From 8710d2b2a8906d0d41e90cfcb9f47573d8d573fb Mon Sep 17 00:00:00 2001 From: Ryan Duffy Date: Fri, 11 Sep 2020 21:30:17 -0700 Subject: [PATCH] Editorial: define Math functions using algorithm steps (#2122) Fixes #2119. Signed-off-by: Ryan Duffy --- spec.html | 894 ++++++++++++++++++------------------------------------ 1 file changed, 298 insertions(+), 596 deletions(-) diff --git a/spec.html b/spec.html index 63507e7e41..d41452e1dc 100644 --- a/spec.html +++ b/spec.html @@ -27579,8 +27579,6 @@

Math [ @@toStringTag ]

Function Properties of the Math Object

-

Each of the following `Math` object functions applies the ToNumber abstract operation to each of its arguments (in left-to-right order if there is more than one). If ToNumber returns an abrupt completion, that Completion Record is immediately returned. Otherwise, the function performs a computation on the resulting Number value(s). The value returned by each function is a Number.

-

In the function descriptions below, the symbols *NaN*, *-0*, *+0*, *-∞* and *+∞* refer to the Number values described in .

The behaviour of the functions `acos`, `acosh`, `asin`, `asinh`, `atan`, `atanh`, `atan2`, `cbrt`, `cos`, `cosh`, `exp`, `expm1`, `hypot`, `log`,`log1p`, `log2`, `log10`, `pow`, `random`, `sin`, `sinh`, `sqrt`, `tan`, and `tanh` is not precisely specified here except to require specific results for certain argument values that represent boundary cases of interest. For other argument values, these functions are intended to compute approximations to the results of familiar mathematical functions, but some latitude is allowed in the choice of approximation algorithms. The general intent is that an implementer should be able to use the same mathematical library for ECMAScript on a given hardware platform that is available to C programmers on that platform.

Although the choice of algorithms is left to the implementation, it is recommended (but not specified by this standard) that implementations use the approximation algorithms for IEEE 754-2019 arithmetic contained in `fdlibm`, the freely distributable mathematical library from Sun Microsystems (http://www.netlib.org/fdlibm).

@@ -27589,278 +27587,158 @@

Function Properties of the Math Object

Math.abs ( _x_ )

Returns the absolute value of _x_; the result has the same magnitude as _x_ but has positive sign.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *-0*, the result is *+0*. -
  • -
  • - If _x_ is *-∞*, the result is *+∞*. -
  • -
+

When the `Math.abs` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, return *NaN*. + 1. If _n_ is *-0*, return *+0*. + 1. If _n_ is *-∞*, return *+∞*. + 1. If _n_ < 0, return -_n_. + 1. Return _n_. +

Math.acos ( _x_ )

-

Returns an implementation-approximated value representing the result of the arc cosine of _x_. The result is expressed in radians and ranges from *+0* to +π.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is greater than 1, the result is *NaN*. -
  • -
  • - If _x_ is less than -1, the result is *NaN*. -
  • -
  • - If _x_ is exactly 1, the result is *+0*. -
  • -
+

Returns the inverse cosine of _x_. The result is expressed in radians and ranges from *+0* to +π, inclusive.

+

When the `Math.acos` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ > 1, or _n_ < -1, return *NaN*. + 1. If _n_ is 1, return *+0*. + 1. Return an implementation-approximated value representing the result of the inverse cosine of _n_. +

Math.acosh ( _x_ )

-

Returns an implementation-approximated value representing the result of the inverse hyperbolic cosine of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If x is less than 1, the result is *NaN*. -
  • -
  • - If x is 1, the result is *+0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
+

Returns the inverse hyperbolic cosine of _x_.

+

When the `Math.acosh` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN* or _n_ is *+∞*, return _n_. + 1. If _n_ is 1, return *+0*. + 1. If _n_ < 1, return *NaN*. + 1. Return an implementation-approximated value representing the result of the inverse hyperbolic cosine of _n_. +

Math.asin ( _x_ )

-

Returns an implementation-approximated value representing the result of the arc sine of _x_. The result is expressed in radians and ranges from -π / 2 to +π / 2.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is greater than 1, the result is *NaN*. -
  • -
  • - If _x_ is less than -1, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
+

Returns the inverse sine of _x_. The result is expressed in radians and ranges from -π / 2 to +π / 2, inclusive.

+

When the `Math.asin` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, or _n_ is *-0*, return _n_. + 1. If _n_ > 1 or _n_ < -1, return *NaN*. + 1. Return an implementation-approximated value representing the result of the inverse sine of _n_. +

Math.asinh ( _x_ )

-

Returns an implementation-approximated value representing the result of the inverse hyperbolic sine of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If x is *-∞*, the result is *-∞*. -
  • -
+

Returns the inverse hyperbolic sine of _x_.

+

When the `Math.asinh` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, _n_ is *-0*, _n_ is *+∞*, or _n_ is *-∞*, return _n_. + 1. Return an implementation-approximated value representing the result of the inverse hyperbolic sine of _n_. +

Math.atan ( _x_ )

-

Returns an implementation-approximated value representing the result of the arc tangent of _x_. The result is expressed in radians and ranges from -π / 2 to +π / 2.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is an implementation-approximated value representing +π / 2. -
  • -
  • - If _x_ is *-∞*, the result is an implementation-approximated value representing to -π / 2. -
  • -
+

Returns the inverse tangent of _x_. The result is expressed in radians and ranges from -π / 2 to +π / 2, inclusive.

+

When the `Math.atan` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, or _n_ is *-0*, return _n_. + 1. If _n_ is *+∞*, return an implementation-approximated value representing +π / 2. + 1. If _n_ is *-∞*, return an implementation-approximated value representing -π / 2. + 1. Return an implementation-approximated value representing the result of the inverse tangent of _n_. +

Math.atanh ( _x_ )

-

Returns an implementation-approximated value representing the result of the inverse hyperbolic tangent of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is less than -1, the result is *NaN*. -
  • -
  • - If _x_ is greater than 1, the result is *NaN*. -
  • -
  • - If _x_ is -1, the result is *-∞*. -
  • -
  • - If _x_ is +1, the result is *+∞*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
+

Returns the inverse hyperbolic tangent of _x_.

+

When the `Math.atanh` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, or _n_ is *-0*, return _n_. + 1. If _n_ > 1 or _n_ < -1, return *NaN*. + 1. If _n_ is +1, return *+∞*. + 1. If _n_ is -1, return *-∞*. + 1. Return an implementation-approximated value representing the result of the inverse hyperbolic tangent of _n_. +

Math.atan2 ( _y_, _x_ )

-

Returns an implementation-approximated value representing the result of the arc tangent of the quotient _y_ / _x_ of the arguments _y_ and _x_, where the signs of _y_ and _x_ are used to determine the quadrant of the result. Note that it is intentional and traditional for the two-argument arc tangent function that the argument named _y_ be first and the argument named _x_ be second. The result is expressed in radians and ranges from -π to +π.

-
    -
  • - If either _x_ or _y_ is *NaN*, the result is *NaN*. -
  • -
  • - If _y_ > 0 and _x_ is *+0*, the result is an implementation-approximated value representing +π / 2. -
  • -
  • - If _y_ > 0 and _x_ is *-0*, the result is an implementation-approximated value representing +π / 2. -
  • -
  • - If _y_ is *+0* and _x_ > 0, the result is *+0*. -
  • -
  • - If _y_ is *+0* and _x_ is *+0*, the result is *+0*. -
  • -
  • - If _y_ is *+0* and _x_ is *-0*, the result is an implementation-approximated value representing +π. -
  • -
  • - If _y_ is *+0* and _x_ < 0, the result is an implementation-approximated value representing +π. -
  • -
  • - If _y_ is *-0* and _x_ > 0, the result is *-0*. -
  • -
  • - If _y_ is *-0* and _x_ is *+0*, the result is *-0*. -
  • -
  • - If _y_ is *-0* and _x_ is *-0*, the result is an implementation-approximated value representing -π. -
  • -
  • - If _y_ is *-0* and _x_ < 0, the result is an implementation-approximated value representing -π. -
  • -
  • - If _y_ < 0 and _x_ is *+0*, the result is an implementation-approximated value representing -π / 2. -
  • -
  • - If _y_ < 0 and _x_ is *-0*, the result is an implementation-approximated value representing -π / 2. -
  • -
  • - If _y_ > 0 and _y_ is finite and _x_ is *+∞*, the result is *+0*. -
  • -
  • - If _y_ > 0 and _y_ is finite and _x_ is *-∞*, the result is an implementation-approximated value representing +π. -
  • -
  • - If _y_ < 0 and _y_ is finite and _x_ is *+∞*, the result is *-0*. -
  • -
  • - If _y_ < 0 and _y_ is finite and _x_ is *-∞*, the result is an implementation-approximated value representing -π. -
  • -
  • - If _y_ is *+∞* and _x_ is finite, the result is an implementation-approximated value representing +π / 2. -
  • -
  • - If _y_ is *-∞* and _x_ is finite, the result is an implementation-approximated value representing -π / 2. -
  • -
  • - If _y_ is *+∞* and _x_ is *+∞*, the result is an implementation-approximated value representing +π / 4. -
  • -
  • - If _y_ is *+∞* and _x_ is *-∞*, the result is an implementation-approximated value representing +3π / 4. -
  • -
  • - If _y_ is *-∞* and _x_ is *+∞*, the result is an implementation-approximated value representing -π / 4. -
  • -
  • - If _y_ is *-∞* and _x_ is *-∞*, the result is an implementation-approximated value representing -3π / 4. -
  • -
+

Returns the inverse tangent of the quotient _y_ / _x_ of the arguments _y_ and _x_, where the signs of _y_ and _x_ are used to determine the quadrant of the result. Note that it is intentional and traditional for the two-argument inverse tangent function that the argument named _y_ be first and the argument named _x_ be second. The result is expressed in radians and ranges from -π to +π, inclusive.

+

When the `Math.atan2` method is called with arguments _x_ and _y_, the following steps are taken:

+ + 1. Let _ny_ be ? ToNumber(_y_). + 1. Let _nx_ be ? ToNumber(_x_). + 1. If _ny_ is *NaN* or _nx_ is *NaN*, return *NaN*. + 1. If _ny_ is *+∞*, then + 1. If _nx_ is *+∞*, return an implementation-approximated value representing +π / 4. + 1. If _nx_ is *-∞*, return an implementation-approximated value representing +3π / 4. + 1. Return an implementation-approximated value representing +π / 2. + 1. If _ny_ is *-∞*, then + 1. If _nx_ is *+∞*, return an implementation-approximated value representing -π / 4. + 1. If _nx_ is *-∞*, return an implementation-approximated value representing -3π / 4. + 1. Return an implementation-approximated value representing -π / 2. + 1. If _ny_ is *+0*, then + 1. If _nx_ > 0 or _nx_ is *+0*, return *+0*. + 1. Return an implementation-approximated value representing +π. + 1. If _ny_ is *-0*, then + 1. If _nx_ > 0 or _nx_ is *+0*, return *-0*. + 1. Return an implementation-approximated value representing -π. + 1. Assert: _ny_ is finite and is neither *+0* nor *-0*. + 1. If _ny_ > 0, then + 1. If _nx_ is *+∞*, return *+0*. + 1. If _nx_ is *-∞*, return an implementation-approximated value representing +π. + 1. If _nx_ is *+0* or _nx_ is *-0*, return an implementation-approximated value representing +π / 2. + 1. If _ny_ < 0, then + 1. If _nx_ is *+∞*, return *-0*. + 1. If _nx_ is *-∞*, return an implementation-approximated value representing -π. + 1. If _nx_ is *+0* or _nx_ is *-0*, return an implementation-approximated value representing -π / 2. + 1. Assert: _nx_ is finite and is neither *+0* nor *-0*. + 1. Return an implementation-approximated value representing the result of the inverse tangent of the quotient _ny_ / _nx_. +

Math.cbrt ( _x_ )

-

Returns an implementation-approximated value representing the result of the cube root of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If _x_ is *-∞*, the result is *-∞*. -
  • -
+

Returns the cube root of _x_.

+

When the `Math.cbrt` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, _n_ is *-0*, _n_ is *+∞*, or _n_ is *-∞*, return _n_. + 1. Return an implementation-approximated value representing the result of the cube root of _n_. +

Math.ceil ( _x_ )

-

Returns the smallest (closest to *-∞*) Number value that is not less than _x_ and is an integer. If _x_ is already an integer, the result is _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If _x_ is *-∞*, the result is *-∞*. -
  • -
  • - If _x_ is less than 0 but greater than -1, the result is *-0*. -
  • -
-

The value of `Math.ceil(x)` is the same as the value of `-Math.floor(-x)`.

+

Returns the smallest (closest to *-∞*) integral Number value that is not less than _x_. If _x_ is already an integral Number, the result is _x_.

+

When the `Math.ceil` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, _n_ is *-0*, _n_ is *+∞*, or _n_ is *-∞*, return _n_. + 1. If _n_ < 0 and _n_ > -1, return *-0*. + 1. If _n_ is an integral Number, return _n_. + 1. Return the smallest (closest to *-∞*) integral Number value that is not less than _n_. + + +

The value of `Math.ceil(x)` is the same as the value of `-Math.floor(-x)`.

+

Math.clz32 ( _x_ )

-

When `Math.clz32` is called with one argument _x_, the following steps are taken:

+

When the `Math.clz32` method is called with argument _x_, the following steps are taken:

1. Let _n_ be ? ToUint32(_x_). 1. Let _p_ be the number of leading zero bits in the 32-bit binary representation of _n_. @@ -27873,46 +27751,26 @@

Math.clz32 ( _x_ )

Math.cos ( _x_ )

-

Returns an implementation-approximated value representing the result of the cosine of _x_. The argument is expressed in radians.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is 1. -
  • -
  • - If _x_ is *-0*, the result is 1. -
  • -
  • - If _x_ is *+∞*, the result is *NaN*. -
  • -
  • - If _x_ is *-∞*, the result is *NaN*. -
  • -
+

Returns the cosine of _x_. The argument is expressed in radians.

+

When the `Math.cos` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, or _n_ is *-0*, return _n_. + 1. If _n_ is *+∞* or _n_ is *-∞*, return *NaN*. + 1. Return an implementation-approximated value representing the result of the cosine of _n_. +

Math.cosh ( _x_ )

-

Returns an implementation-approximated value representing the result of the hyperbolic cosine of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is 1. -
  • -
  • - If _x_ is *-0*, the result is 1. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If _x_ is *-∞*, the result is *+∞*. -
  • -
+

Returns the hyperbolic cosine of _x_.

+

When the `Math.cosh` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+∞*, or _n_ is *-∞*, return _n_. + 1. If _n_ is *+0* or _n_ is *-0*, return 1. + 1. Return an implementation-approximated value representing the result of the hyperbolic cosine of _n_. +

The value of `Math.cosh(x)` is the same as the value of `(Math.exp(x) + Math.exp(-x)) / 2`.

@@ -27920,71 +27778,40 @@

Math.cosh ( _x_ )

Math.exp ( _x_ )

-

Returns an implementation-approximated value representing the result of the exponential function of _x_ (_e_ raised to the power of _x_, where _e_ is the base of the natural logarithms).

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is 1. -
  • -
  • - If _x_ is *-0*, the result is 1. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If _x_ is *-∞*, the result is *+0*. -
  • -
+

Returns the exponential function of _x_ (_e_ raised to the power of _x_, where _e_ is the base of the natural logarithms).

+

When the `Math.exp` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN* or _n_ is *+∞*, return _n_. + 1. If _n_ is *+0* or _n_ is *-0*, return 1. + 1. If _n_ is *-∞*, return *+0*. + 1. Return an implementation-approximated value representing the result of the exponential function of _n_. +

Math.expm1 ( _x_ )

-

Returns an implementation-approximated value representing the result of subtracting 1 from the exponential function of _x_ (_e_ raised to the power of _x_, where _e_ is the base of the natural logarithms). The result is computed in a way that is accurate even when the value of x is close 0.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If _x_ is *-∞*, the result is -1. -
  • -
+

Returns the result of subtracting 1 from the exponential function of _x_ (_e_ raised to the power of _x_, where _e_ is the base of the natural logarithms). The result is computed in a way that is accurate even when the value of x is close 0.

+

When the `Math.expm1` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, _n_ is *-0*, or _n_ is *+∞*, return _n_. + 1. If _n_ is *-∞*, return -1. + 1. Return an implementation-approximated value representing the result of subtracting 1 from the exponential function of _n_. +

Math.floor ( _x_ )

-

Returns the greatest (closest to *+∞*) Number value that is not greater than _x_ and is an integer. If _x_ is already an integer, the result is _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If _x_ is *-∞*, the result is *-∞*. -
  • -
  • - If _x_ is greater than 0 but less than 1, the result is *+0*. -
  • -
+

Returns the greatest (closest to *+∞*) integral Number value that is not greater than _x_. If _x_ is already an integral Number, the result is _x_.

+

When the `Math.floor` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, _n_ is *-0*, _n_ is *+∞*, or _n_ is *-∞*, return _n_. + 1. If _n_ < 1 and _n_ > 0, return *+0*. + 1. If _n_ is an integral Number, return _n_. + 1. Return the greatest (closest to *+∞*) integral Number value that is not greater than _n_. +

The value of `Math.floor(x)` is the same as the value of `-Math.ceil(-x)`.

@@ -27992,7 +27819,7 @@

Math.floor ( _x_ )

Math.fround ( _x_ )

-

When `Math.fround` is called with argument _x_, the following steps are taken:

+

When the `Math.fround` method is called with argument _x_, the following steps are taken:

1. If _x_ is *NaN*, return *NaN*. 1. If _x_ is one of *+0*, *-0*, *+∞*, *-∞*, return _x_. @@ -28004,24 +27831,18 @@

Math.fround ( _x_ )

Math.hypot ( _value1_, _value2_, ..._values_ )

-

`Math.hypot` returns an implementation-approximated value representing the result of the square root of the sum of squares of its arguments.

-
    -
  • - If no arguments are passed, the result is *+0*. -
  • -
  • - If any argument is *+∞*, the result is *+∞*. -
  • -
  • - If any argument is *-∞*, the result is *+∞*. -
  • -
  • - If no argument is *+∞* or *-∞*, and any argument is *NaN*, the result is *NaN*. -
  • -
  • - If all arguments are either *+0* or *-0*, the result is *+0*. -
  • -
+

Returns the square root of the sum of squares of its arguments.

+

When the `Math.hypot` method is called with at least two arguments _value1_ and _value2_ and any number of additional arguments which form the rest parameter ..._values_, the following steps are taken:

+ + 1. Let _numbers_ be a List containing _value1_, _value2_, and the elements of _values_ in List order. + 1. Let _onlyZero_ be *true*. + 1. For each element _number_ of _numbers_, do + 1. Let _n_ be ? ToNumber(_number_). + 1. If _n_ is *NaN*, _n_ is *+∞*, or _n_ is *-∞*, return _n_. + 1. If _n_ is neither *+0* nor *-0*, set _onlyZero_ to *false*. + 1. If _onlyZero_ is *true*, return *+0*. + 1. Return an implementation-approximated value representing the square root of the sum of squares of the elements of _numbers_. +

Implementations should take care to avoid the loss of precision from overflows and underflows that are prone to occur in naive implementations when this function is called with two or more arguments.

@@ -28040,135 +27861,100 @@

Math.imul ( _x_, _y_ )

Math.log ( _x_ )

-

Returns an implementation-approximated value representing the result of the natural logarithm of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is less than 0, the result is *NaN*. -
  • -
  • - If _x_ is *+0* or *-0*, the result is *-∞*. -
  • -
  • - If _x_ is 1, the result is *+0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
+

Returns the natural logarithm of _x_.

+

When the `Math.log` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN* or _n_ is *+∞*, return _n_. + 1. If _n_ is 1, return *+0*. + 1. If _n_ is *+0* or _n_ is *-0*, return *-∞*. + 1. If _n_ < 0, return *NaN*. + 1. Return an implementation-approximated value representing the result of the natural logarithm of _n_. +

Math.log1p ( _x_ )

-

Returns an implementation-approximated value representing the result of the natural logarithm of 1 + _x_. The result is computed in a way that is accurate even when the value of x is close to zero.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is less than -1, the result is *NaN*. -
  • -
  • - If x is -1, the result is *-∞*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
+

Returns the natural logarithm of 1 + _x_. The result is computed in a way that is accurate even when the value of x is close to zero.

+

When the `Math.log1p` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, _n_ is *-0*, or _n_ is *+∞*, return _n_. + 1. If _n_ is -1, return *-∞*. + 1. If _n_ < -1, return *NaN*. + 1. Return an implementation-approximated value representing the result of the natural logarithm of 1 + _n_. +

Math.log10 ( _x_ )

-

Returns an implementation-approximated value representing the result of the base 10 logarithm of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is less than 0, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *-∞*. -
  • -
  • - If _x_ is *-0*, the result is *-∞*. -
  • -
  • - If _x_ is 1, the result is *+0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
+

Returns the base 10 logarithm of _x_.

+

When the `Math.log10` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN* or _n_ is *+∞*, return _n_. + 1. If _n_ is 1, return *+0*. + 1. If _n_ is *+0* or _n_ is *-0*, return *-∞*. + 1. If _n_ < 0, return *NaN*. + 1. Return an implementation-approximated value representing the result of the base 10 logarithm of _n_. +

Math.log2 ( _x_ )

-

Returns an implementation-approximated value representing the result of the base 2 logarithm of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is less than 0, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *-∞*. -
  • -
  • - If _x_ is *-0*, the result is *-∞*. -
  • -
  • - If _x_ is 1, the result is *+0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
+

Returns the base 2 logarithm of _x_.

+

When the `Math.log2` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN* or _n_ is *+∞*, return _n_. + 1. If _n_ is 1, return *+0*. + 1. If _n_ is *+0* or _n_ is *-0*, return *-∞*. + 1. If _n_ < 0, return *NaN*. + 1. Return an implementation-approximated value representing the result of the base 2 logarithm of _n_. +

Math.max ( _value1_, _value2_, ..._values_ )

Given zero or more arguments, calls ToNumber on each of the arguments and returns the largest of the resulting values.

-
    -
  • - If no arguments are given, the result is *-∞*. -
  • -
  • - If any value is *NaN*, the result is *NaN*. -
  • -
  • - The comparison of values to determine the largest value is done using the Abstract Relational Comparison algorithm except that *+0* is considered to be larger than *-0*. -
  • -
+

When the `Math.max` method is called with at least two arguments _value1_ and _value2_ and any number of additional arguments which form the rest parameter ..._values_, the following steps are taken:

+ + 1. Let _numbers_ be a List containing _value1_, _value2_, and the elements of _values_ in List order. + 1. Let _highest_ be *-∞*. + 1. For each element _number_ of _numbers_, do + 1. Let _n_ be ? ToNumber(_number_). + 1. If _n_ is *NaN*, return *NaN*. + 1. If _n_ is *+0* and _highest_ is *-0*, set _highest_ to *+0*. + 1. If _n_ > _highest_, set _highest_ to _n_. + 1. Return _highest_. + + +

The comparison of values to determine the largest value is done using the Abstract Relational Comparison algorithm except that *+0* is considered to be larger than *-0*.

+

Math.min ( _value1_, _value2_, ..._values_ )

Given zero or more arguments, calls ToNumber on each of the arguments and returns the smallest of the resulting values.

-
    -
  • - If no arguments are given, the result is *+∞*. -
  • -
  • - If any value is *NaN*, the result is *NaN*. -
  • -
  • - The comparison of values to determine the smallest value is done using the Abstract Relational Comparison algorithm except that *+0* is considered to be larger than *-0*. -
  • -
+

When the `Math.min` method is called with at least two arguments _value1_ and _value2_ and any number of additional arguments which form the rest parameter ..._values_, the following steps are taken:

+ + 1. Let _numbers_ be a List containing _value1_, _value2_, and the elements of _values_ in List order. + 1. Let _lowest_ be *+∞*. + 1. For each element _number_ of _numbers_, do + 1. Let _n_ be ? ToNumber(_number_). + 1. If _n_ is *NaN*, return *NaN*. + 1. If _n_ is *-0* and _lowest_ is *+0*, set _lowest_ to *-0*. + 1. If _n_ < _lowest_, set _lowest_ to _n_. + 1. Return _lowest_. + + +

The comparison of values to determine the largest value is done using the Abstract Relational Comparison algorithm except that *+0* is considered to be larger than *-0*.

+

Math.pow ( _base_, _exponent_ )

+

When the `Math.pow` method is called with arguments _base_ and _exponent_, the following steps are taken:

1. Set _base_ to ? ToNumber(_base_). 1. Set _exponent_ to ? ToNumber(_exponent_). @@ -28185,29 +27971,14 @@

Math.random ( )

Math.round ( _x_ )

Returns the Number value that is closest to _x_ and is an integer. If two integers are equally close to _x_, then the result is the Number value that is closer to *+∞*. If _x_ is already an integer, the result is _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If _x_ is *-∞*, the result is *-∞*. -
  • -
  • - If _x_ is greater than 0 but less than 0.5, the result is *+0*. -
  • -
  • - If _x_ is less than 0 but greater than or equal to -0.5, the result is *-0*. -
  • -
+

When the `Math.round` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is an integral Number, return _n_. + 1. If _x_ < 0.5 and _x_ > 0, return *+0*. + 1. If _x_ < 0 and _x_ ≥ -0.5, return *-0*. + 1. Return the integral Number closest to _n_, preferring the Number closer to *+∞* in the case of a tie. +

`Math.round(3.5)` returns 4, but `Math.round(-3.5)` returns -3.

@@ -28219,64 +27990,36 @@

Math.round ( _x_ )

Math.sign ( _x_ )

Returns the sign of _x_, indicating whether _x_ is positive, negative, or zero.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is negative and not *-0*, the result is -1. -
  • -
  • - If _x_ is positive and not *+0*, the result is +1. -
  • -
+

When the `Math.sign` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, or _n_ is *-0*, return _n_. + 1. If _n_ < 0, return -1. + 1. Return +1. +

Math.sin ( _x_ )

-

Returns an implementation-approximated value representing the result of the sine of _x_. The argument is expressed in radians.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞* or *-∞*, the result is *NaN*. -
  • -
+

Returns the sine of _x_. The argument is expressed in radians.

+

When the `Math.sin` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, or _n_ is *-0*, return _n_. + 1. If _n_ is *+∞* or _n_ is *-∞*, return *NaN*. + 1. Return an implementation-approximated value representing the result of the sine of _n_. +

Math.sinh ( _x_ )

-

Returns an implementation-approximated value representing the result of the hyperbolic sine of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If _x_ is *-∞*, the result is *-∞*. -
  • -
+

Returns the hyperbolic sine of _x_.

+

When the `Math.sinh` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, _n_ is *-0*, _n_ is *+∞*, or _n_ is *-∞*, return _n_. + 1. Return an implementation-approximated value representing the result of the hyperbolic sine of _n_. +

The value of `Math.sinh(x)` is the same as the value of `(Math.exp(x) - Math.exp(-x)) / 2`.

@@ -28284,65 +28027,39 @@

Math.sinh ( _x_ )

Math.sqrt ( _x_ )

-

Returns an implementation-approximated value representing the result of the square root of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is less than 0, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
+

Returns the square root of _x_.

+

When the `Math.sqrt` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, _n_ is *-0*, or _n_ is *+∞*, return _n_. + 1. If _n_ < 0, return *NaN*. + 1. Return an implementation-approximated value representing the result of the square root of _n_. +

Math.tan ( _x_ )

-

Returns an implementation-approximated value representing the result of the tangent of _x_. The argument is expressed in radians.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞* or *-∞*, the result is *NaN*. -
  • -
+

Returns the tangent of _x_. The argument is expressed in radians.

+

When the `Math.tan` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, or _n_ is *-0*, return _n_. + 1. If _n_ is *+∞*, or _n_ is *-∞*, return *NaN*. + 1. Return an implementation-approximated value representing the result of the tangent of _n_. +

Math.tanh ( _x_ )

-

Returns an implementation-approximated value representing the result of the hyperbolic tangent of _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+∞*, the result is +1. -
  • -
  • - If _x_ is *-∞*, the result is -1. -
  • -
+

Returns the hyperbolic tangent of _x_.

+

When the `Math.tanh` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, or _n_ is *-0*, return _n_. + 1. If _n_ is *+∞*, return +1. + 1. If _n_ is *-∞*, return -1. + 1. Return an implementation-approximated value representing the result of the hyperbolic tangent of _n_. +

The value of `Math.tanh(x)` is the same as the value of `(Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x))`.

@@ -28351,29 +28068,14 @@

Math.tanh ( _x_ )

Math.trunc ( _x_ )

Returns the integral part of the number _x_, removing any fractional digits. If _x_ is already an integer, the result is _x_.

-
    -
  • - If _x_ is *NaN*, the result is *NaN*. -
  • -
  • - If _x_ is *-0*, the result is *-0*. -
  • -
  • - If _x_ is *+0*, the result is *+0*. -
  • -
  • - If _x_ is *+∞*, the result is *+∞*. -
  • -
  • - If _x_ is *-∞*, the result is *-∞*. -
  • -
  • - If _x_ is greater than 0 but less than 1, the result is *+0*. -
  • -
  • - If _x_ is less than 0 but greater than -1, the result is *-0*. -
  • -
+

When the `Math.trunc` method is called with argument _x_, the following steps are taken:

+ + 1. Let _n_ be ? ToNumber(_x_). + 1. If _n_ is *NaN*, _n_ is *+0*, _n_ is *-0*, _n_ is *+∞*, or _n_ is *-∞*, return _n_. + 1. If _n_ < 1 and _n_ > 0, return *+0*. + 1. If _n_ < 0 and _n_ > -1, return *-0*. + 1. Return the integral Number nearest _n_ in the direction of *+0*. +