Commit 2e4280f2 authored by mbrandy's avatar mbrandy Committed by Commit bot

[es7] Fix "implement exponentiation operator proposal" for AIX.

Prefer Pow() as it works around certain cases that are different in AIX's
std::pow().

TEST=mjsunit/harmony/exponentiation-operator
R=caitpotter88@gmail.com, littledan@chromium.org, adamk@chromium.org, rossberg@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1916043002

Cr-Commit-Position: refs/heads/master@{#35775}
parent 01ca769c
......@@ -1729,34 +1729,12 @@ double power_double_int(double x, int y) {
double power_double_double(double x, double y) {
#if (defined(__MINGW64_VERSION_MAJOR) && \
(!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1)) || \
defined(V8_OS_AIX)
// MinGW64 and AIX have a custom implementation for pow. This handles certain
// special cases that are different.
if ((x == 0.0 || std::isinf(x)) && y != 0.0 && std::isfinite(y)) {
double f;
double result = ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0;
/* retain sign if odd integer exponent */
return ((std::modf(y, &f) == 0.0) && (static_cast<int64_t>(y) & 1))
? copysign(result, x)
: result;
}
if (x == 2.0) {
int y_int = static_cast<int>(y);
if (y == y_int) {
return std::ldexp(1.0, y_int);
}
}
#endif
// The checks for special cases can be dropped in ia32 because it has already
// been done in generated code before bailing out here.
if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) {
return std::numeric_limits<double>::quiet_NaN();
}
return std::pow(x, y);
return Pow(x, y);
}
......
......@@ -438,7 +438,7 @@ bool ParserTraits::ShortcutNumericLiteralBinaryExpression(
return true;
}
case Token::EXP: {
double value = std::pow(x_val, y_val);
double value = Pow(x_val, y_val);
int int_value = static_cast<int>(value);
*x = factory->NewNumberLiteral(
int_value == value && value != -0.0 ? int_value : value, pos,
......
......@@ -211,6 +211,30 @@ inline double Floor(double x) {
return std::floor(x);
}
inline double Pow(double x, double y) {
#if (defined(__MINGW64_VERSION_MAJOR) && \
(!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1)) || \
defined(V8_OS_AIX)
// MinGW64 and AIX have a custom implementation for pow. This handles certain
// special cases that are different.
if ((x == 0.0 || std::isinf(x)) && y != 0.0 && std::isfinite(y)) {
double f;
double result = ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0;
/* retain sign if odd integer exponent */
return ((std::modf(y, &f) == 0.0) && (static_cast<int64_t>(y) & 1))
? copysign(result, x)
: result;
}
if (x == 2.0) {
int y_int = static_cast<int>(y);
if (y == y_int) {
return std::ldexp(1.0, y_int);
}
}
#endif
return std::pow(x, y);
}
// TODO(svenpanne) Clean up the whole power-of-2 mess.
inline int32_t WhichPowerOf2Abs(int32_t x) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment