v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
ieee754.cc
Go to the documentation of this file.
1// Copyright 2011 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <cmath>
8
9#include "src/base/ieee754.h"
10#include "src/flags/flags.h"
11
13
14double pow(double x, double y) {
15 if (v8_flags.use_std_math_pow) {
16 if (std::isnan(y)) {
17 // 1. If exponent is NaN, return NaN.
18 return std::numeric_limits<double>::quiet_NaN();
19 }
20 if (std::isinf(y) && (x == 1 || x == -1)) {
21 // 9. If exponent is +∞𝔽, then
22 // b. If abs(ℝ(base)) = 1, return NaN.
23 // and
24 // 10. If exponent is -∞𝔽, then
25 // b. If abs(ℝ(base)) = 1, return NaN.
26 return std::numeric_limits<double>::quiet_NaN();
27 }
28 if (std::isnan(x)) {
29 // std::pow distinguishes between quiet and signaling NaN; JS doesn't.
30 x = std::numeric_limits<double>::quiet_NaN();
31 }
32
33 // The following special cases just exist to match the optimizing compilers'
34 // behavior, which avoid calls to `pow` in those cases.
35 if (y == 2) {
36 // x ** 2 ==> x * x
37 return x * x;
38 } else if (y == 0.5) {
39 // x ** 0.5 ==> sqrt(x), except if x is -Infinity
40 if (std::isinf(x)) {
41 return std::numeric_limits<double>::infinity();
42 } else {
43 // Note the +0 so that we get +0 for -0**0.5 rather than -0.
44 return std::sqrt(x + 0);
45 }
46 }
47
48 return std::pow(x, y);
49 }
51}
52
53} // namespace v8::internal::math
int x
double pow(double x, double y)
Definition ieee754.cc:2646
double pow(double x, double y)
Definition ieee754.cc:14
V8_EXPORT_PRIVATE FlagValues v8_flags