This is a commit snapshot of the specification

This document contains the contents of the specification as of commit 94011c73c833eb6a08b5983b0a5d97ba888d170c, and should only be used as a historical reference. This commit may not have even been merged into the specification.

Do not attempt to implement this version of the specification. Do not reference this version as authoritative in any way. Instead, see https://tc39.es/ecma262 for the living specification.

21 Numbers and Mathematical Functions

21.1 Number Objects

21.1.1 The Number Constructor

The Number constructor:

  • is %Number%.
  • is the initial value of the "Number" property of the global object.
  • creates and initializes a new Number object when called as a constructor.
  • performs a type conversion when called as a function rather than as a constructor.
  • may be used as the value of an extends clause of a class definition. Subclass constructors that intend to inherit the specified Number behaviour must include a super call to the Number constructor to create and initialize the subclass instance with a [[NumberData]] internal slot.

21.1.1.1 Number ( value )

This function performs the following steps when called:

  1. If value is present, then
    1. Let prim be ? ToNumeric(value).
    2. If prim is a BigInt, let n be ๐”ฝ(โ„(prim)).
    3. Otherwise, let n be prim.
  2. Else,
    1. Let n be +0๐”ฝ.
  3. If NewTarget is undefined, return n.
  4. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Number.prototype%", ยซ [[NumberData]] ยป).
  5. Set O.[[NumberData]] to n.
  6. Return O.

21.1.2 Properties of the Number Constructor

The Number constructor:

  • has a [[Prototype]] internal slot whose value is %Function.prototype%.
  • has the following properties:

21.1.2.1 Number.EPSILON

The value of Number.EPSILON is the Number value for the magnitude of the difference between 1 and the smallest value greater than 1 that is representable as a Number value, which is approximately 2.2204460492503130808472633361816 ร— 10-16.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.1.2.2 Number.isFinite ( number )

This function performs the following steps when called:

  1. If number is not a Number, return false.
  2. If number is not finite, return false.
  3. Otherwise, return true.

21.1.2.3 Number.isInteger ( number )

This function performs the following steps when called:

  1. If number is an integral Number, return true.
  2. Return false.

21.1.2.4 Number.isNaN ( number )

This function performs the following steps when called:

  1. If number is not a Number, return false.
  2. If number is NaN, return true.
  3. Otherwise, return false.
Note

This function differs from the global isNaN function (19.2.3) in that it does not convert its argument to a Number before determining whether it is NaN.

21.1.2.5 Number.isSafeInteger ( number )

Note

An integer n is a "safe integer" if and only if the Number value for n is not the Number value for any other integer.

This function performs the following steps when called:

  1. If number is an integral Number, then
    1. If abs(โ„(number)) โ‰ค 253 - 1, return true.
  2. Return false.

21.1.2.6 Number.MAX_SAFE_INTEGER

Note

Due to rounding behaviour necessitated by precision limitations of IEEE 754-2019, the Number value for every integer greater than Number.MAX_SAFE_INTEGER is shared with at least one other integer. Such large-magnitude integers are therefore not safe, and are not guaranteed to be exactly representable as Number values or even to be distinguishable from each other. For example, both 9007199254740992 and 9007199254740993 evaluate to the Number value 9007199254740992๐”ฝ.

The value of Number.MAX_SAFE_INTEGER is 9007199254740991๐”ฝ (๐”ฝ(253 - 1)).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.1.2.7 Number.MAX_VALUE

The value of Number.MAX_VALUE is the largest positive finite value of the Number type, which is approximately 1.7976931348623157 ร— 10308.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.1.2.8 Number.MIN_SAFE_INTEGER

Note

Due to rounding behaviour necessitated by precision limitations of IEEE 754-2019, the Number value for every integer less than Number.MIN_SAFE_INTEGER is shared with at least one other integer. Such large-magnitude integers are therefore not safe, and are not guaranteed to be exactly representable as Number values or even to be distinguishable from each other. For example, both -9007199254740992 and -9007199254740993 evaluate to the Number value -9007199254740992๐”ฝ.

The value of Number.MIN_SAFE_INTEGER is -9007199254740991๐”ฝ (๐”ฝ(-(253 - 1))).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.1.2.9 Number.MIN_VALUE

The value of Number.MIN_VALUE is the smallest positive value of the Number type, which is approximately 5 ร— 10-324.

In the IEEE 754-2019 double precision binary representation, the smallest possible value is a denormalized number. If an implementation does not support denormalized values, the value of Number.MIN_VALUE must be the smallest non-zero positive value that can actually be represented by the implementation.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.1.2.10 Number.NaN

The value of Number.NaN is NaN.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.1.2.11 Number.NEGATIVE_INFINITY

The value of Number.NEGATIVE_INFINITY is -โˆž๐”ฝ.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.1.2.12 Number.parseFloat ( string )

The initial value of the "parseFloat" property is %parseFloat%.

21.1.2.13 Number.parseInt ( string, radix )

The initial value of the "parseInt" property is %parseInt%.

21.1.2.14 Number.POSITIVE_INFINITY

The value of Number.POSITIVE_INFINITY is +โˆž๐”ฝ.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.1.2.15 Number.prototype

The initial value of Number.prototype is the Number prototype object.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.1.3 Properties of the Number Prototype Object

The Number prototype object:

  • is %Number.prototype%.
  • is an ordinary object.
  • is itself a Number object; it has a [[NumberData]] internal slot with the value +0๐”ฝ.
  • has a [[Prototype]] internal slot whose value is %Object.prototype%.

Unless explicitly stated otherwise, the methods of the Number prototype object defined below are not generic and the this value passed to them must be either a Number value or an object that has a [[NumberData]] internal slot that has been initialized to a Number value.

The phrase โ€œthis Number valueโ€ within the specification of a method refers to the result returned by calling the abstract operation ThisNumberValue with the this value of the method invocation passed as the argument.

21.1.3.1 Number.prototype.constructor

The initial value of Number.prototype.constructor is %Number%.

21.1.3.2 Number.prototype.toExponential ( fractionDigits )

This method returns a String containing this Number value represented in decimal exponential notation with one digit before the significand's decimal point and fractionDigits digits after the significand's decimal point. If fractionDigits is undefined, it includes as many significand digits as necessary to uniquely specify the Number (just like in ToString except that in this case the Number is always output in exponential notation).

It performs the following steps when called:

  1. Let x be ? ThisNumberValue(this value).
  2. Let f be ? ToIntegerOrInfinity(fractionDigits).
  3. Assert: If fractionDigits is undefined, then f is 0.
  4. If x is not finite, return Number::toString(x, 10).
  5. If f < 0 or f > 100, throw a RangeError exception.
  6. Set x to โ„(x).
  7. Let s be the empty String.
  8. If x < 0, then
    1. Set s to "-".
    2. Set x to -x.
  9. If x = 0, then
    1. Let m be the String value consisting of f + 1 occurrences of the code unit 0x0030 (DIGIT ZERO).
    2. Let e be 0.
  10. Else,
    1. If fractionDigits is not undefined, then
      1. Let e and n be integers such that 10f โ‰ค n < 10f + 1 and for which n ร— 10e - f - x is as close to zero as possible. If there are two such sets of e and n, pick the e and n for which n ร— 10e - f is larger.
    2. Else,
      1. Let e, n, and ff be integers such that ff โ‰ฅ 0, 10ff โ‰ค n < 10ff + 1, ๐”ฝ(n ร— 10e - ff) is ๐”ฝ(x), and ff is as small as possible. Note that the decimal representation of n has ff + 1 digits, n is not divisible by 10, and the least significant digit of n is not necessarily uniquely determined by these criteria.
      2. Set f to ff.
    3. Let m be the String value consisting of the digits of the decimal representation of n (in order, with no leading zeroes).
  11. If f โ‰  0, then
    1. Let a be the first code unit of m.
    2. Let b be the other f code units of m.
    3. Set m to the string-concatenation of a, ".", and b.
  12. If e = 0, then
    1. Let c be "+".
    2. Let d be "0".
  13. Else,
    1. If e > 0, then
      1. Let c be "+".
    2. Else,
      1. Assert: e < 0.
      2. Let c be "-".
      3. Set e to -e.
    3. Let d be the String value consisting of the digits of the decimal representation of e (in order, with no leading zeroes).
  14. Set m to the string-concatenation of m, "e", c, and d.
  15. Return the string-concatenation of s and m.
Note

For implementations that provide more accurate conversions than required by the rules above, it is recommended that the following alternative version of step 10.b.i be used as a guideline:

  1. Let e, n, and ff be integers such that ff โ‰ฅ 0, 10ff โ‰ค n < 10ff + 1, ๐”ฝ(n ร— 10e - ff) is ๐”ฝ(x), and ff is as small as possible. If there are multiple possibilities for n, choose the value of n for which ๐”ฝ(n ร— 10e - ff) is closest in value to ๐”ฝ(x). If there are two such possible values of n, choose the one that is even.

21.1.3.3 Number.prototype.toFixed ( fractionDigits )

Note 1

This method returns a String containing this Number value represented in decimal fixed-point notation with fractionDigits digits after the decimal point. If fractionDigits is undefined, 0 is assumed.

It performs the following steps when called:

  1. Let x be ? ThisNumberValue(this value).
  2. Let f be ? ToIntegerOrInfinity(fractionDigits).
  3. Assert: If fractionDigits is undefined, then f is 0.
  4. If f is not finite, throw a RangeError exception.
  5. If f < 0 or f > 100, throw a RangeError exception.
  6. If x is not finite, return Number::toString(x, 10).
  7. Set x to โ„(x).
  8. Let s be the empty String.
  9. If x < 0, then
    1. Set s to "-".
    2. Set x to -x.
  10. If x โ‰ฅ 1021, then
    1. Let m be ! ToString(๐”ฝ(x)).
  11. Else,
    1. Let n be an integer for which n / 10f - x is as close to zero as possible. If there are two such n, pick the larger n.
    2. If n = 0, let m be "0"; otherwise let m be the String value consisting of the digits of the decimal representation of n (in order, with no leading zeroes).
    3. If f โ‰  0, then
      1. Let k be the length of m.
      2. If k โ‰ค f, then
        1. Let z be the String value consisting of f + 1 - k occurrences of the code unit 0x0030 (DIGIT ZERO).
        2. Set m to the string-concatenation of z and m.
        3. Set k to f + 1.
      3. Let a be the first k - f code units of m.
      4. Let b be the other f code units of m.
      5. Set m to the string-concatenation of a, ".", and b.
  12. Return the string-concatenation of s and m.
Note 2

The output of toFixed may be more precise than toString for some values because toString only prints enough significant digits to distinguish the number from adjacent Number values. For example,

(1000000000000000128).toString() returns "1000000000000000100", while
(1000000000000000128).toFixed(0) returns "1000000000000000128".

21.1.3.4 Number.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:

This method produces a String value that represents this Number value formatted according to the conventions of the host environment's current locale. This method is implementation-defined, and it is permissible, but not encouraged, for it to return the same thing as toString.

The meanings of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.

21.1.3.5 Number.prototype.toPrecision ( precision )

This method returns a String containing this Number value represented either in decimal exponential notation with one digit before the significand's decimal point and precision - 1 digits after the significand's decimal point or in decimal fixed notation with precision significant digits. If precision is undefined, it calls ToString instead.

It performs the following steps when called:

  1. Let x be ? ThisNumberValue(this value).
  2. If precision is undefined, return ! ToString(x).
  3. Let p be ? ToIntegerOrInfinity(precision).
  4. If x is not finite, return Number::toString(x, 10).
  5. If p < 1 or p > 100, throw a RangeError exception.
  6. Set x to โ„(x).
  7. Let s be the empty String.
  8. If x < 0, then
    1. Set s to the code unit 0x002D (HYPHEN-MINUS).
    2. Set x to -x.
  9. If x = 0, then
    1. Let m be the String value consisting of p occurrences of the code unit 0x0030 (DIGIT ZERO).
    2. Let e be 0.
  10. Else,
    1. Let e and n be integers such that 10p - 1 โ‰ค n < 10p and for which n ร— 10e - p + 1 - x is as close to zero as possible. If there are two such sets of e and n, pick the e and n for which n ร— 10e - p + 1 is larger.
    2. Let m be the String value consisting of the digits of the decimal representation of n (in order, with no leading zeroes).
    3. If e < -6 or e โ‰ฅ p, then
      1. Assert: e โ‰  0.
      2. If p โ‰  1, then
        1. Let a be the first code unit of m.
        2. Let b be the other p - 1 code units of m.
        3. Set m to the string-concatenation of a, ".", and b.
      3. If e > 0, then
        1. Let c be the code unit 0x002B (PLUS SIGN).
      4. Else,
        1. Assert: e < 0.
        2. Let c be the code unit 0x002D (HYPHEN-MINUS).
        3. Set e to -e.
      5. Let d be the String value consisting of the digits of the decimal representation of e (in order, with no leading zeroes).
      6. Return the string-concatenation of s, m, the code unit 0x0065 (LATIN SMALL LETTER E), c, and d.
  11. If e = p - 1, return the string-concatenation of s and m.
  12. If e โ‰ฅ 0, then
    1. Set m to the string-concatenation of the first e + 1 code units of m, the code unit 0x002E (FULL STOP), and the remaining p - (e + 1) code units of m.
  13. Else,
    1. Set m to the string-concatenation of the code unit 0x0030 (DIGIT ZERO), the code unit 0x002E (FULL STOP), -(e + 1) occurrences of the code unit 0x0030 (DIGIT ZERO), and the String m.
  14. Return the string-concatenation of s and m.

21.1.3.6 Number.prototype.toString ( [ radix ] )

Note

The optional radix should be an integral Number value in the inclusive interval from 2๐”ฝ to 36๐”ฝ. If radix is undefined then 10๐”ฝ is used as the value of radix.

This method performs the following steps when called:

  1. Let x be ? ThisNumberValue(this value).
  2. If radix is undefined, let radixMV be 10.
  3. Else, let radixMV be ? ToIntegerOrInfinity(radix).
  4. If radixMV is not in the inclusive interval from 2 to 36, throw a RangeError exception.
  5. Return Number::toString(x, radixMV).

This method is not generic; it throws a TypeError exception if its this value is not a Number or a Number object. Therefore, it cannot be transferred to other kinds of objects for use as a method.

The "length" property of this method is 1๐”ฝ.

21.1.3.7 Number.prototype.valueOf ( )

  1. Return ? ThisNumberValue(this value).

21.1.3.7.1 ThisNumberValue ( value )

The abstract operation ThisNumberValue takes argument value (an ECMAScript language value) and returns either a normal completion containing a Number or a throw completion. It performs the following steps when called:

  1. If value is a Number, return value.
  2. If value is an Object and value has a [[NumberData]] internal slot, then
    1. Let n be value.[[NumberData]].
    2. Assert: n is a Number.
    3. Return n.
  3. Throw a TypeError exception.

21.1.4 Properties of Number Instances

Number instances are ordinary objects that inherit properties from the Number prototype object. Number instances also have a [[NumberData]] internal slot. The [[NumberData]] internal slot is the Number value represented by this Number object.

21.2 BigInt Objects

21.2.1 The BigInt Constructor

The BigInt constructor:

  • is %BigInt%.
  • is the initial value of the "BigInt" property of the global object.
  • performs a type conversion when called as a function rather than as a constructor.
  • is not intended to be used with the new operator or to be subclassed. It may be used as the value of an extends clause of a class definition but a super call to the BigInt constructor will cause an exception.

21.2.1.1 BigInt ( value )

This function performs the following steps when called:

  1. If NewTarget is not undefined, throw a TypeError exception.
  2. Let prim be ? ToPrimitive(value, number).
  3. If prim is a Number, return ? NumberToBigInt(prim).
  4. Otherwise, return ? ToBigInt(prim).

21.2.1.1.1 NumberToBigInt ( number )

The abstract operation NumberToBigInt takes argument number (a Number) and returns either a normal completion containing a BigInt or a throw completion. It performs the following steps when called:

  1. If number is not an integral Number, throw a RangeError exception.
  2. Return โ„ค(โ„(number)).

21.2.2 Properties of the BigInt Constructor

The BigInt constructor:

  • has a [[Prototype]] internal slot whose value is %Function.prototype%.
  • has the following properties:

21.2.2.1 BigInt.asIntN ( bits, bigint )

This function performs the following steps when called:

  1. Set bits to ? ToIndex(bits).
  2. Set bigint to ? ToBigInt(bigint).
  3. Let mod be โ„(bigint) modulo 2bits.
  4. If mod โ‰ฅ 2bits - 1, return โ„ค(mod - 2bits); otherwise return โ„ค(mod).

21.2.2.2 BigInt.asUintN ( bits, bigint )

This function performs the following steps when called:

  1. Set bits to ? ToIndex(bits).
  2. Set bigint to ? ToBigInt(bigint).
  3. Return โ„ค(โ„(bigint) modulo 2bits).

21.2.2.3 BigInt.prototype

The initial value of BigInt.prototype is the BigInt prototype object.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.2.3 Properties of the BigInt Prototype Object

The BigInt prototype object:

The phrase โ€œthis BigInt valueโ€ within the specification of a method refers to the result returned by calling the abstract operation ThisBigIntValue with the this value of the method invocation passed as the argument.

21.2.3.1 BigInt.prototype.constructor

The initial value of BigInt.prototype.constructor is %BigInt%.

21.2.3.2 BigInt.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used:

This method produces a String value that represents this BigInt value formatted according to the conventions of the host environment's current locale. This method is implementation-defined, and it is permissible, but not encouraged, for it to return the same thing as toString.

The meanings of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.

21.2.3.3 BigInt.prototype.toString ( [ radix ] )

Note

The optional radix should be an integral Number value in the inclusive interval from 2๐”ฝ to 36๐”ฝ. If radix is undefined then 10๐”ฝ is used as the value of radix.

This method performs the following steps when called:

  1. Let x be ? ThisBigIntValue(this value).
  2. If radix is undefined, let radixMV be 10.
  3. Else, let radixMV be ? ToIntegerOrInfinity(radix).
  4. If radixMV is not in the inclusive interval from 2 to 36, throw a RangeError exception.
  5. Return BigInt::toString(x, radixMV).

This method is not generic; it throws a TypeError exception if its this value is not a BigInt or a BigInt object. Therefore, it cannot be transferred to other kinds of objects for use as a method.

21.2.3.4 BigInt.prototype.valueOf ( )

  1. Return ? ThisBigIntValue(this value).

21.2.3.4.1 ThisBigIntValue ( value )

The abstract operation ThisBigIntValue takes argument value (an ECMAScript language value) and returns either a normal completion containing a BigInt or a throw completion. It performs the following steps when called:

  1. If value is a BigInt, return value.
  2. If value is an Object and value has a [[BigIntData]] internal slot, then
    1. Assert: value.[[BigIntData]] is a BigInt.
    2. Return value.[[BigIntData]].
  3. Throw a TypeError exception.

21.2.3.5 BigInt.prototype [ %Symbol.toStringTag% ]

The initial value of the %Symbol.toStringTag% property is the String value "BigInt".

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

21.2.4 Properties of BigInt Instances

BigInt instances are ordinary objects that inherit properties from the BigInt prototype object. BigInt instances also have a [[BigIntData]] internal slot. The [[BigIntData]] internal slot is the BigInt value represented by this BigInt object.

21.3 The Math Object

The Math object:

  • is %Math%.
  • is the initial value of the "Math" property of the global object.
  • is an ordinary object.
  • has a [[Prototype]] internal slot whose value is %Object.prototype%.
  • is not a function object.
  • does not have a [[Construct]] internal method; it cannot be used as a constructor with the new operator.
  • does not have a [[Call]] internal method; it cannot be invoked as a function.
Note

In this specification, the phrase โ€œthe Number value for xโ€ has a technical meaning defined in 6.1.6.1.

21.3.1 Value Properties of the Math Object

21.3.1.1 Math.E

The Number value for e, the base of the natural logarithms, which is approximately 2.7182818284590452354.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.3.1.2 Math.LN10

The Number value for the natural logarithm of 10, which is approximately 2.302585092994046.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.3.1.3 Math.LN2

The Number value for the natural logarithm of 2, which is approximately 0.6931471805599453.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.3.1.4 Math.LOG10E

The Number value for the base-10 logarithm of e, the base of the natural logarithms; this value is approximately 0.4342944819032518.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

Note

The value of Math.LOG10E is approximately the reciprocal of the value of Math.LN10.

21.3.1.5 Math.LOG2E

The Number value for the base-2 logarithm of e, the base of the natural logarithms; this value is approximately 1.4426950408889634.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

Note

The value of Math.LOG2E is approximately the reciprocal of the value of Math.LN2.

21.3.1.6 Math.PI

The Number value for ฯ€, the ratio of the circumference of a circle to its diameter, which is approximately 3.1415926535897932.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.3.1.7 Math.SQRT1_2

The Number value for the square root of ยฝ, which is approximately 0.7071067811865476.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

Note

The value of Math.SQRT1_2 is approximately the reciprocal of the value of Math.SQRT2.

21.3.1.8 Math.SQRT2

The Number value for the square root of 2, which is approximately 1.4142135623730951.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.3.1.9 Math [ %Symbol.toStringTag% ]

The initial value of the %Symbol.toStringTag% property is the String value "Math".

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

21.3.2 Function Properties of the Math Object

Note

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, 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).

21.3.2.1 Math.abs ( x )

This function returns the absolute value of x; the result has the same magnitude as x but has positive sign.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, return NaN.
  3. If n is -0๐”ฝ, return +0๐”ฝ.
  4. If n is -โˆž๐”ฝ, return +โˆž๐”ฝ.
  5. If n < -0๐”ฝ, return -n.
  6. Return n.

21.3.2.2 Math.acos ( x )

This function returns the inverse cosine of x. The result is expressed in radians and is in the inclusive interval from +0๐”ฝ to ๐”ฝ(ฯ€).

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, n > 1๐”ฝ, or n < -1๐”ฝ, return NaN.
  3. If n is 1๐”ฝ, return +0๐”ฝ.
  4. Return an implementation-approximated Number value representing the inverse cosine of โ„(n).

21.3.2.3 Math.acosh ( x )

This function returns the inverse hyperbolic cosine of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +โˆž๐”ฝ, return n.
  3. If n is 1๐”ฝ, return +0๐”ฝ.
  4. If n < 1๐”ฝ, return NaN.
  5. Return an implementation-approximated Number value representing the inverse hyperbolic cosine of โ„(n).

21.3.2.4 Math.asin ( x )

This function returns the inverse sine of x. The result is expressed in radians and is in the inclusive interval from ๐”ฝ(-ฯ€ / 2) to ๐”ฝ(ฯ€ / 2).

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, or -0๐”ฝ, return n.
  3. If n > 1๐”ฝ or n < -1๐”ฝ, return NaN.
  4. Return an implementation-approximated Number value representing the inverse sine of โ„(n).

21.3.2.5 Math.asinh ( x )

This function returns the inverse hyperbolic sine of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0๐”ฝ or -0๐”ฝ, return n.
  3. Return an implementation-approximated Number value representing the inverse hyperbolic sine of โ„(n).

21.3.2.6 Math.atan ( x )

This function returns the inverse tangent of x. The result is expressed in radians and is in the inclusive interval from ๐”ฝ(-ฯ€ / 2) to ๐”ฝ(ฯ€ / 2).

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, or -0๐”ฝ, return n.
  3. If n is +โˆž๐”ฝ, return an implementation-approximated Number value representing ฯ€ / 2.
  4. If n is -โˆž๐”ฝ, return an implementation-approximated Number value representing -ฯ€ / 2.
  5. Return an implementation-approximated Number value representing the inverse tangent of โ„(n).

21.3.2.7 Math.atanh ( x )

This function returns the inverse hyperbolic tangent of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, or -0๐”ฝ, return n.
  3. If n > 1๐”ฝ or n < -1๐”ฝ, return NaN.
  4. If n is 1๐”ฝ, return +โˆž๐”ฝ.
  5. If n is -1๐”ฝ, return -โˆž๐”ฝ.
  6. Return an implementation-approximated Number value representing the inverse hyperbolic tangent of โ„(n).

21.3.2.8 Math.atan2 ( y, x )

This function 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 is in the inclusive interval from -ฯ€ to +ฯ€.

It performs the following steps when called:

  1. Let ny be ? ToNumber(y).
  2. Let nx be ? ToNumber(x).
  3. If ny is NaN or nx is NaN, return NaN.
  4. If ny is +โˆž๐”ฝ, then
    1. If nx is +โˆž๐”ฝ, return an implementation-approximated Number value representing ฯ€ / 4.
    2. If nx is -โˆž๐”ฝ, return an implementation-approximated Number value representing 3ฯ€ / 4.
    3. Return an implementation-approximated Number value representing ฯ€ / 2.
  5. If ny is -โˆž๐”ฝ, then
    1. If nx is +โˆž๐”ฝ, return an implementation-approximated Number value representing -ฯ€ / 4.
    2. If nx is -โˆž๐”ฝ, return an implementation-approximated Number value representing -3ฯ€ / 4.
    3. Return an implementation-approximated Number value representing -ฯ€ / 2.
  6. If ny is +0๐”ฝ, then
    1. If nx > +0๐”ฝ or nx is +0๐”ฝ, return +0๐”ฝ.
    2. Return an implementation-approximated Number value representing ฯ€.
  7. If ny is -0๐”ฝ, then
    1. If nx > +0๐”ฝ or nx is +0๐”ฝ, return -0๐”ฝ.
    2. Return an implementation-approximated Number value representing -ฯ€.
  8. Assert: ny is finite and is neither +0๐”ฝ nor -0๐”ฝ.
  9. If ny > +0๐”ฝ, then
    1. If nx is +โˆž๐”ฝ, return +0๐”ฝ.
    2. If nx is -โˆž๐”ฝ, return an implementation-approximated Number value representing ฯ€.
    3. If nx is either +0๐”ฝ or -0๐”ฝ, return an implementation-approximated Number value representing ฯ€ / 2.
  10. If ny < -0๐”ฝ, then
    1. If nx is +โˆž๐”ฝ, return -0๐”ฝ.
    2. If nx is -โˆž๐”ฝ, return an implementation-approximated Number value representing -ฯ€.
    3. If nx is either +0๐”ฝ or -0๐”ฝ, return an implementation-approximated Number value representing -ฯ€ / 2.
  11. Assert: nx is finite and is neither +0๐”ฝ nor -0๐”ฝ.
  12. Let r be the inverse tangent of abs(โ„(ny) / โ„(nx)).
  13. If nx < -0๐”ฝ, then
    1. If ny > +0๐”ฝ, set r to ฯ€ - r.
    2. Else, set r to -ฯ€ + r.
  14. Else,
    1. If ny < -0๐”ฝ, set r to -r.
  15. Return an implementation-approximated Number value representing r.

21.3.2.9 Math.cbrt ( x )

This function returns the cube root of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0๐”ฝ or -0๐”ฝ, return n.
  3. Return an implementation-approximated Number value representing the cube root of โ„(n).

21.3.2.10 Math.ceil ( x )

This function 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.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0๐”ฝ or -0๐”ฝ, return n.
  3. If n < -0๐”ฝ and n > -1๐”ฝ, return -0๐”ฝ.
  4. If n is an integral Number, return n.
  5. Return the smallest (closest to -โˆž) integral Number value that is not less than n.
Note

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

21.3.2.11 Math.clz32 ( x )

This function performs the following steps when called:

  1. Let n be ? ToUint32(x).
  2. Let p be the number of leading zero bits in the unsigned 32-bit binary representation of n.
  3. Return ๐”ฝ(p).
Note

If n is either +0๐”ฝ or -0๐”ฝ, this method returns 32๐”ฝ. If the most significant bit of the 32-bit binary encoding of n is 1, this method returns +0๐”ฝ.

21.3.2.12 Math.cos ( x )

This function returns the cosine of x. The argument is expressed in radians.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is not finite, return NaN.
  3. If n is either +0๐”ฝ or -0๐”ฝ, return 1๐”ฝ.
  4. Return an implementation-approximated Number value representing the cosine of โ„(n).

21.3.2.13 Math.cosh ( x )

This function returns the hyperbolic cosine of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, return NaN.
  3. If n is either +โˆž๐”ฝ or -โˆž๐”ฝ, return +โˆž๐”ฝ.
  4. If n is either +0๐”ฝ or -0๐”ฝ, return 1๐”ฝ.
  5. Return an implementation-approximated Number value representing the hyperbolic cosine of โ„(n).
Note

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

21.3.2.14 Math.exp ( x )

This function returns the exponential function of x (e raised to the power of x, where e is the base of the natural logarithms).

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +โˆž๐”ฝ, return n.
  3. If n is either +0๐”ฝ or -0๐”ฝ, return 1๐”ฝ.
  4. If n is -โˆž๐”ฝ, return +0๐”ฝ.
  5. Return an implementation-approximated Number value representing the exponential function of โ„(n).

21.3.2.15 Math.expm1 ( x )

This function 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 to 0.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, -0๐”ฝ, or +โˆž๐”ฝ, return n.
  3. If n is -โˆž๐”ฝ, return -1๐”ฝ.
  4. Let exp be the exponential function of โ„(n).
  5. Return an implementation-approximated Number value representing exp - 1.

21.3.2.16 Math.floor ( x )

This function 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.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0๐”ฝ or -0๐”ฝ, return n.
  3. If n < 1๐”ฝ and n > +0๐”ฝ, return +0๐”ฝ.
  4. If n is an integral Number, return n.
  5. Return the greatest (closest to +โˆž) integral Number value that is not greater than n.
Note

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

21.3.2.17 Math.fround ( x )

This function performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, return NaN.
  3. If n is one of +0๐”ฝ, -0๐”ฝ, +โˆž๐”ฝ, or -โˆž๐”ฝ, return n.
  4. Let n32 be the result of converting n to IEEE 754-2019 binary32 format using roundTiesToEven mode.
  5. Let n64 be the result of converting n32 to IEEE 754-2019 binary64 format.
  6. Return the ECMAScript Number value corresponding to n64.

21.3.2.18 Math.f16round ( x )

This function performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, return NaN.
  3. If n is one of +0๐”ฝ, -0๐”ฝ, +โˆž๐”ฝ, or -โˆž๐”ฝ, return n.
  4. Let n16 be the result of converting n to IEEE 754-2019 binary16 format using roundTiesToEven mode.
  5. Let n64 be the result of converting n16 to IEEE 754-2019 binary64 format.
  6. Return the ECMAScript Number value corresponding to n64.
Note

This operation is not the same as casting to binary32 and then to binary16 because of the possibility of double-rounding: consider the number k = 1.00048828125000022204๐”ฝ, for example, for which Math.f16round(k) is 1.0009765625๐”ฝ, but Math.f16round(Math.fround(k)) is 1๐”ฝ.

Not all platforms provide native support for casting from binary64 to binary16. There are various libraries which can provide this, including the MIT-licensed half library. Alternatively, it is possible to first cast from binary64 to binary32 under roundTiesToEven and then check whether the result could lead to incorrect double-rounding. Such cases can be handled explicitly by adjusting the mantissa of the binary32 value so that it is the value which would be produced by performing the initial cast under roundTiesToOdd. Casting the adjusted value to binary16 under roundTiesToEven then produces the correct value.

21.3.2.19 Math.hypot ( ...args )

Given zero or more arguments, this function returns the square root of the sum of squares of its arguments.

It performs the following steps when called:

  1. Let coerced be a new empty List.
  2. For each element arg of args, do
    1. Let n be ? ToNumber(arg).
    2. Append n to coerced.
  3. For each element number of coerced, do
    1. If number is either +โˆž๐”ฝ or -โˆž๐”ฝ, return +โˆž๐”ฝ.
  4. Let onlyZero be true.
  5. For each element number of coerced, do
    1. If number is NaN, return NaN.
    2. If number is neither +0๐”ฝ nor -0๐”ฝ, set onlyZero to false.
  6. If onlyZero is true, return +0๐”ฝ.
  7. Return an implementation-approximated Number value representing the square root of the sum of squares of the mathematical values of the elements of coerced.

The "length" property of this function is 2๐”ฝ.

Note

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.

21.3.2.20 Math.imul ( x, y )

This function performs the following steps when called:

  1. Let a be โ„(? ToUint32(x)).
  2. Let b be โ„(? ToUint32(y)).
  3. Let product be (a ร— b) modulo 232.
  4. If product โ‰ฅ 231, return ๐”ฝ(product - 232); otherwise return ๐”ฝ(product).

21.3.2.21 Math.log ( x )

This function returns the natural logarithm of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +โˆž๐”ฝ, return n.
  3. If n is 1๐”ฝ, return +0๐”ฝ.
  4. If n is either +0๐”ฝ or -0๐”ฝ, return -โˆž๐”ฝ.
  5. If n < -0๐”ฝ, return NaN.
  6. Return an implementation-approximated Number value representing ln(โ„(n)).

21.3.2.22 Math.log1p ( x )

This function 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.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, -0๐”ฝ, or +โˆž๐”ฝ, return n.
  3. If n is -1๐”ฝ, return -โˆž๐”ฝ.
  4. If n < -1๐”ฝ, return NaN.
  5. Return an implementation-approximated Number value representing ln(1 + โ„(n)).

21.3.2.23 Math.log10 ( x )

This function returns the base 10 logarithm of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +โˆž๐”ฝ, return n.
  3. If n is 1๐”ฝ, return +0๐”ฝ.
  4. If n is either +0๐”ฝ or -0๐”ฝ, return -โˆž๐”ฝ.
  5. If n < -0๐”ฝ, return NaN.
  6. Return an implementation-approximated Number value representing log10(โ„(n)).

21.3.2.24 Math.log2 ( x )

This function returns the base 2 logarithm of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +โˆž๐”ฝ, return n.
  3. If n is 1๐”ฝ, return +0๐”ฝ.
  4. If n is either +0๐”ฝ or -0๐”ฝ, return -โˆž๐”ฝ.
  5. If n < -0๐”ฝ, return NaN.
  6. Return an implementation-approximated Number value representing log2(โ„(n)).

21.3.2.25 Math.max ( ...args )

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

It performs the following steps when called:

  1. Let coerced be a new empty List.
  2. For each element arg of args, do
    1. Let n be ? ToNumber(arg).
    2. Append n to coerced.
  3. Let highest be -โˆž๐”ฝ.
  4. For each element number of coerced, do
    1. If number is NaN, return NaN.
    2. If number is +0๐”ฝ and highest is -0๐”ฝ, set highest to +0๐”ฝ.
    3. If number > highest, set highest to number.
  5. Return highest.
Note

The comparison of values to determine the largest value is done using the IsLessThan algorithm except that +0๐”ฝ is considered to be larger than -0๐”ฝ.

The "length" property of this function is 2๐”ฝ.

21.3.2.26 Math.min ( ...args )

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

It performs the following steps when called:

  1. Let coerced be a new empty List.
  2. For each element arg of args, do
    1. Let n be ? ToNumber(arg).
    2. Append n to coerced.
  3. Let lowest be +โˆž๐”ฝ.
  4. For each element number of coerced, do
    1. If number is NaN, return NaN.
    2. If number is -0๐”ฝ and lowest is +0๐”ฝ, set lowest to -0๐”ฝ.
    3. If number < lowest, set lowest to number.
  5. Return lowest.
Note

The comparison of values to determine the largest value is done using the IsLessThan algorithm except that +0๐”ฝ is considered to be larger than -0๐”ฝ.

The "length" property of this function is 2๐”ฝ.

21.3.2.27 Math.pow ( base, exponent )

This function performs the following steps when called:

  1. Set base to ? ToNumber(base).
  2. Set exponent to ? ToNumber(exponent).
  3. Return Number::exponentiate(base, exponent).

21.3.2.28 Math.random ( )

This function returns a Number value with positive sign, greater than or equal to +0๐”ฝ but strictly less than 1๐”ฝ, chosen randomly or pseudo randomly with approximately uniform distribution over that range, using an implementation-defined algorithm or strategy.

Each Math.random function created for distinct realms must produce a distinct sequence of values from successive calls.

21.3.2.29 Math.round ( x )

This function returns the Number value that is closest to x and is integral. If two integral Numbers are equally close to x, then the result is the Number value that is closer to +โˆž. If x is already integral, the result is x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is an integral Number, return n.
  3. If n < 0.5๐”ฝ and n > +0๐”ฝ, return +0๐”ฝ.
  4. If n < -0๐”ฝ and n โ‰ฅ -0.5๐”ฝ, return -0๐”ฝ.
  5. Return the integral Number closest to n, preferring the Number closer to +โˆž in the case of a tie.
Note 1

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

Note 2

The value of Math.round(x) is not always the same as the value of Math.floor(x + 0.5). When x is -0๐”ฝ or x is less than -0๐”ฝ but greater than or equal to -0.5๐”ฝ, Math.round(x) returns -0๐”ฝ, but Math.floor(x + 0.5) returns +0๐”ฝ. Math.round(x) may also differ from the value of Math.floor(x + 0.5)because of internal rounding when computing x + 0.5.

21.3.2.30 Math.sign ( x )

This function returns the sign of x, indicating whether x is positive, negative, or zero.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, or -0๐”ฝ, return n.
  3. If n < -0๐”ฝ, return -1๐”ฝ.
  4. Return 1๐”ฝ.

21.3.2.31 Math.sin ( x )

This function returns the sine of x. The argument is expressed in radians.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, or -0๐”ฝ, return n.
  3. If n is either +โˆž๐”ฝ or -โˆž๐”ฝ, return NaN.
  4. Return an implementation-approximated Number value representing the sine of โ„(n).

21.3.2.32 Math.sinh ( x )

This function returns the hyperbolic sine of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0๐”ฝ or -0๐”ฝ, return n.
  3. Return an implementation-approximated Number value representing the hyperbolic sine of โ„(n).
Note

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

21.3.2.33 Math.sqrt ( x )

This function returns the square root of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, -0๐”ฝ, or +โˆž๐”ฝ, return n.
  3. If n < -0๐”ฝ, return NaN.
  4. Return ๐”ฝ(the square root of โ„(n)).

21.3.2.34 Math.sumPrecise ( items )

Given an iterable of Numbers, this function sums each value in the iterable and returns their sum. If any value is not a Number it throws a TypeError exception.

It performs the following steps when called:

  1. Perform ? RequireObjectCoercible(items).
  2. Let iteratorRecord be ? GetIterator(items, sync).
  3. Let state be minus-zero.
  4. Let sum be 0.
  5. Let count be 0.
  6. Let next be not-started.
  7. Repeat, while next is not done,
    1. Set next to ? IteratorStepValue(iteratorRecord).
    2. If next is not done, then
      1. If count โ‰ฅ 253 - 1, then
        1. NOTE: This step is not expected to be reached in practice and is included only so that implementations may rely on inputs being "reasonably sized" without violating this specification.
        2. Let error be ThrowCompletion(a newly created RangeError object).
        3. Return ? IteratorClose(iteratorRecord, error).
      2. If next is not a Number, then
        1. Let error be ThrowCompletion(a newly created TypeError object).
        2. Return ? IteratorClose(iteratorRecord, error).
      3. Let n be next.
      4. If state is not not-a-number, then
        1. If n is NaN, then
          1. Set state to not-a-number.
        2. Else if n is +โˆž๐”ฝ, then
          1. If state is minus-infinity, set state to not-a-number.
          2. Else, set state to plus-infinity.
        3. Else if n is -โˆž๐”ฝ, then
          1. If state is plus-infinity, set state to not-a-number.
          2. Else, set state to minus-infinity.
        4. Else if n is not -0๐”ฝ and state is either minus-zero or finite, then
          1. Set state to finite.
          2. Set sum to sum + โ„(n).
      5. Set count to count + 1.
  8. If state is not-a-number, return NaN.
  9. If state is plus-infinity, return +โˆž๐”ฝ.
  10. If state is minus-infinity, return -โˆž๐”ฝ.
  11. If state is minus-zero, return -0๐”ฝ.
  12. Return ๐”ฝ(sum).
Note

The value of sum can be computed without arbitrary-precision arithmetic by a variety of algorithms. One such is the "Grow-Expansion" algorithm given in Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates by Jonathan Richard Shewchuk. A more recent algorithm is given in "Fast exact summation using small and large superaccumulators", code for which is available at https://gitlab.com/radfordneal/xsum.

21.3.2.35 Math.tan ( x )

This function returns the tangent of x. The argument is expressed in radians.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, or -0๐”ฝ, return n.
  3. If n is either +โˆž๐”ฝ or -โˆž๐”ฝ, return NaN.
  4. Return an implementation-approximated Number value representing the tangent of โ„(n).

21.3.2.36 Math.tanh ( x )

This function returns the hyperbolic tangent of x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0๐”ฝ, or -0๐”ฝ, return n.
  3. If n is +โˆž๐”ฝ, return 1๐”ฝ.
  4. If n is -โˆž๐”ฝ, return -1๐”ฝ.
  5. Return an implementation-approximated Number value representing the hyperbolic tangent of โ„(n).
Note

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)).

21.3.2.37 Math.trunc ( x )

This function returns the integral part of the number x, removing any fractional digits. If x is already integral, the result is x.

It performs the following steps when called:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0๐”ฝ or -0๐”ฝ, return n.
  3. If n < 1๐”ฝ and n > +0๐”ฝ, return +0๐”ฝ.
  4. If n < -0๐”ฝ and n > -1๐”ฝ, return -0๐”ฝ.
  5. Return the integral Number nearest n in the direction of +0๐”ฝ.