ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 48

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     46      47      48      49     ..

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 48

 

 

NOTE

The value of 

Number.MAX_SAFE_INTEGER

Number.MAX_SAFE_INTEGER

 is 

9007199254740991

𝔽

53

 - 1)).

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The value of 

Number.MAX_VALUE

Number.MAX_VALUE

 is the largest positive finite value of the Number type, which is approximately

1.7976931348623157 

×

 10

308

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

NOTE

The value of 

Number.MIN_SAFE_INTEGER

Number.MIN_SAFE_INTEGER

 is 

-9007199254740991

𝔽

 (

(-(2

53

 - 1))).

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The value of 

Number.MIN_VALUE

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

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

 }.

The value of 

Number.NaN

Number.NaN

 is 

NaN

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The value of 

Number.NEGATIVE_INFINITY

Number.NEGATIVE_INFINITY

 is 

-

𝔽

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The value of 

Number.MAX_SAFE_INTEGER

Number.MAX_SAFE_INTEGER

 is the largest 

integral Number

 n such that 

Number value

.

The value of 

Number.MIN_SAFE_INTEGER

Number.MIN_SAFE_INTEGER

 is the smallest 

integral Number

 n such that 

(n)

Number value

.

21.1.2.7  Number.MAX_VALUE

21.1.2.8  Number.MIN_SAFE_INTEGER

21.1.2.9  Number.MIN_VALUE

21.1.2.10  Number.NaN

21.1.2.11  Number.NEGATIVE_INFINITY

21.1.2.12  Number.parseFloat ( 

string

 )

509

The value of the 

Number.parseFloat

Number.parseFloat

 

data property

 is the same built-in 

function object

 that is the initial value of

the 

"parseFloat"

 property of the 

global object

 defined in 

19.2.4

.

The value of the 

Number.parseInt

Number.parseInt

 

data property

 is the same built-in 

function object

 that is the initial value of the

"parseInt"

 property of the 

global object

 defined in 

19.2.5

.

The value of 

Number.POSITIVE_INFINITY

Number.POSITIVE_INFINITY

 is 

+

𝔽

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Number.prototype

Number.prototype

 is the 

Number prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

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 abstract operation 

thisNumberValue

 takes argument 

value

. It performs the following steps when called:

1.  If 

Type

(

value

) is Number, return 

value

.

2.  If 

Type

(

value

) is Object and 

value

 has a [[NumberData]] internal slot, then

a.  Let 

n

 be 

value

.[[NumberData]].

b. 

Assert

Type

(

n

) is Number.

c.  Return 

n

.

3.  Throw a 

TypeError

 exception.

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.

The initial value of 

Number.prototype.constructor

Number.prototype.constructor

 is 

%Number%

.

21.1.2.13  Number.parseInt ( 

string

radix

 )

21.1.2.14  Number.POSITIVE_INFINITY

21.1.2.15  Number.prototype

21.1.3  Properties of the Number Prototype Object

21.1.3.1  Number.prototype.constructor

510

Return 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

,

include 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). Specifically, perform the following steps:

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

).

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

a.  Set 

s

 to 

"-"

.

b.  Set 

x

 to -

x

.

9.  If 

x

 = 0, then

a.  Let 

m

 be the String value consisting of 

f

 + 1 occurrences of the code unit 0x0030 (DIGIT ZERO).

b.  Let 

e

 be 0.

10.  Else,

a.  If 

fractionDigits

 is not 

undefined

, then

i.  Let 

e

 and 

n

 be integers such that 10

f

 

 

n

 < 10

f

 + 1

 and for which 

n

 

×

 10

e

 - 

n

 - 

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

 

×

 10

e

 - 

f

 is larger.

b.  Else,

i.  Let 

e

n

, and 

f

 be integers such that 

f

 

 0, 10

f

 

 

n

 < 10

f

 + 1

n

 

×

 10

e

 - 

f

 is 

x

, and 

f

 is as small as

possible. Note that the decimal representation of 

n

 has 

f

 + 1 digits, 

n

 is not divisible by 10, and the

least significant digit of 

n

 is not necessarily uniquely determined by these criteria.

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

a.  Let 

a

 be the first code unit of 

m

.

b.  Let 

b

 be the other 

f

 code units of 

m

.

c.  Set 

m

 to the 

string-concatenation

 of 

a

"."

, and 

b

.

12.  If 

e

 = 0, then

a.  Let 

c

 be 

"+"

.

b.  Let 

d

 be 

"0"

.

13.  Else,

a.  If 

e

 > 0, let 

c

 be 

"+"

.

b.  Else,

i. 

Assert

e

 < 0.

ii.  Let 

c

 be 

"-"

.

iii.  Set 

e

 to -

e

.

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

.

21.1.3.2  Number.prototype.toExponential ( 

fractionDigits

 )

511

NOTE

NOTE 1

The following steps are performed:

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

).

7.  Set 

x

 to 

(

x

).

8.  Let 

s

 be the empty String.

9.  If 

x

 < 0, then

a.  Set 

s

 to 

"-"

.

b.  Set 

x

 to -

x

.

10.  If 

x

 

 10

21

, then

a.  Let 

m

 be ! 

ToString

(

(

x

)).

11.  Else,

a.  Let 

n

 be an 

integer

 for which 

n

 / 10

f

 - 

x

 is as close to zero as possible. If there are two such 

n

, pick the

larger 

n

.

b.  If 

n

 = 0, let 

m

 be the String 

"0"

. Otherwise, let 

m

 be the String value consisting of the digits of the decimal

representation of 

n

 (in order, with no leading zeroes).

c.  If 

f

 

 0, then

i.  Let 

k

 be the length of 

m

.

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

iii.  Let 

a

 be the first 

k

 - 

f

 code units of 

m

.

iv.  Let 

b

 be the other 

f

 code units of 

m

.

v.  Set 

m

 to the 

string-concatenation

 of 

a

"."

, and 

b

.

12.  Return the 

string-concatenation

 of 

s

 and 

m

.

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:

i.  Let 

e

n

, and 

f

 be integers such that 

f

 

 0, 10

f

 

 

n

 < 10

f

 + 1

n

 

×

 10

e

 - 

f

 is 

x

, and 

f

 is as small as

possible. If there are multiple possibilities for 

n

, choose the value of 

n

 for which 

n

 

×

 10

e

 - 

f

is closest in value to 

x

. If there are two such possible values of 

n

, choose the one that is

even.

toFixed

toFixed

 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.

21.1.3.3  Number.prototype.toFixed ( 

fractionDigits

 )

512

NOTE 2

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the

Number.prototype.toLocaleString

Number.prototype.toLocaleString

 method as specified in the ECMA-402 specification. If an ECMAScript

implementation does not include the ECMA-402 API the following specification of the 

toLocaleString

toLocaleString

 method

is used.

Produces a String value that represents this 

Number value

 formatted according to the conventions of the 

host

environment

's current locale. This function is 

implementation-defined

, and it is permissible, but not encouraged, for it

to return the same thing as 

toString

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.

Return 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

, call 

ToString

 instead. Specifically, perform the following

steps:

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

).

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

a.  Set 

s

 to the code unit 0x002D (HYPHEN-MINUS).

b.  Set 

x

 to -

x

.

9.  If 

x

 = 0, then

a.  Let 

m

 be the String value consisting of 

p

 occurrences of the code unit 0x0030 (DIGIT ZERO).

b.  Let 

e

 be 0.

10.  Else,

a.  Let 

e

 and 

n

 be integers such that 10

p

 - 1

 

 

n

 < 10

p

 and for which 

n

 

×

 10

e

 - 

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

 

×

 10

e

 - 

p

 + 1

 is larger.

b.  Let 

m

 be the String value consisting of the digits of the decimal representation of 

n

 (in order, with no

leading zeroes).

c.  If 

e

 < -6 or 

e

 

 

p

, then

i. 

Assert

e

 

 0.

The output of 

toFixed

toFixed

 may be more precise than 

toString

toString

 for some values because toString

only prints enough significant digits to distinguish the number from adjacent Number values.
For example,

(1000000000000000128).toString()

(1000000000000000128).toString()

 returns 

"1000000000000000100"

, while 

(1000000000000000128).toFixed(0)

(1000000000000000128).toFixed(0)

 returns 

"1000000000000000128"

.

21.1.3.4  Number.prototype.toLocaleString ( [ 

reserved1

 [ , 

reserved2

 ] ] )

21.1.3.5  Number.prototype.toPrecision ( 

precision

 )

513

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

.

iii.  If 

e

 > 0, then

1.  Let 

c

 be the code unit 0x002B (PLUS SIGN).

iv.  Else,

1. 

Assert

e

 < 0.

2.  Let 

c

 be the code unit 0x002D (HYPHEN-MINUS).

3.  Set 

e

 to -

e

.

v.  Let 

d

 be the String value consisting of the digits of the decimal representation of 

e

 (in order, with

no leading zeroes).

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

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

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

.

NOTE

The following steps are performed:

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

 < 2 or 

radixMV

 > 36, throw a 

RangeError

 exception.

5.  If 

radixMV

 = 10, return ! 

ToString

(

x

).

6.  Return the String representation of this 

Number value

 using the radix specified by 

radixMV

. Letters 

aa

-

zz

 are

used for digits with values 10 through 35. The precise algorithm is 

implementation-defined

, however the

algorithm should be a generalization of that specified in 

6.1.6.1.20

.

The 

toString

toString

 function 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 the 

toString

toString

 method is 

1

𝔽

.

1.  Return ? 

thisNumberValue

(

this

 value).

The optional 

radix

 should be an 

integral Number

 value in the inclusive range 

2

𝔽

 to 

36

𝔽

. If 

radix

 is

undefined

 then 

10

𝔽

 is used as the value of 

radix

.

21.1.3.6  Number.prototype.toString ( [ 

radix

 ] )

21.1.3.7  Number.prototype.valueOf ( )

514

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.

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

new

 operator or to be subclassed. It may be used as the value of an

extends

extends

 clause of a class definition but a 

super

super

 call to the BigInt 

constructor

 will cause an exception.

When 

BigInt

BigInt

 is called with argument 

value

, the following steps are taken:

1.  If NewTarget is not 

undefined

, throw a 

TypeError

 exception.

2.  Let 

prim

 be ? 

ToPrimitive

(

value

number

).

3.  If 

Type

(

prim

) is Number, return ? 

NumberToBigInt

(

prim

).

4.  Otherwise, return ? 

ToBigInt

(

value

).

The abstract operation NumberToBigInt takes argument 

number

 (a Number). It performs the following steps when

called:

1.  If 

IsIntegralNumber

(

number

) is 

false

, throw a 

RangeError

 exception.

2.  Return the BigInt value that represents 

(

number

).

The value of the [[Prototype]] internal slot of the BigInt 

constructor

 is 

%Function.prototype%

.

The BigInt 

constructor

 has the following properties:

When the 

BigInt.asIntN

BigInt.asIntN

 function is called with two arguments 

bits

 and 

bigint

, the following steps are taken:

1.  Set 

bits

 to ? 

ToIndex

(

bits

).

2.  Set 

bigint

 to ? 

ToBigInt

(

bigint

).

3.  Let 

mod

 be 

(

bigint

modulo

 2

bits

.

21.1.4  Properties of Number Instances

21.2  BigInt Objects

21.2.1  The BigInt Constructor

21.2.1.1  BigInt ( 

value

 )

21.2.1.1.1  NumberToBigInt ( 

number

 )

21.2.2  Properties of the BigInt Constructor

21.2.2.1  BigInt.asIntN ( 

bits

bigint

 )

515

4.  If 

mod

 

 2

bits

 - 1

(

mod

 - 2

bits

mod

).

When the 

BigInt.asUintN

BigInt.asUintN

 function is called with two arguments 

bits

 and 

bigint

, the following steps are taken:

1.  Set 

bits

 to ? 

ToIndex

(

bits

).

2.  Set 

bigint

 to ? 

ToBigInt

(

bigint

).

3.  Return the BigInt value that represents 

(

bigint

modulo

 2

bits

.

The initial value of 

BigInt.prototype

BigInt.prototype

 is the 

BigInt prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The 

BigInt prototype object

:

is 

%BigInt.prototype%

.

is an 

ordinary object

.

is not a BigInt object; it does not have a [[BigIntData]] internal slot.
has a [[Prototype]] internal slot whose value is 

%Object.prototype%

.

The abstract operation 

thisBigIntValue

 takes argument 

value

. It performs the following steps when called:

1.  If 

Type

(

value

) is BigInt, return 

value

.

2.  If 

Type

(

value

) is Object and 

value

 has a [[BigIntData]] internal slot, then

a. 

Assert

Type

(

value

.[[BigIntData]]) is BigInt.

b.  Return 

value

.[[BigIntData]].

3.  Throw a 

TypeError

 exception.

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.

The initial value of 

BigInt.prototype.constructor

BigInt.prototype.constructor

 is 

%BigInt%

.

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the

BigInt.prototype.toLocaleString

BigInt.prototype.toLocaleString

 method as specified in the ECMA-402 specification. If an ECMAScript

implementation does not include the ECMA-402 API the following specification of the 

toLocaleString

toLocaleString

 method

is used.

Produces a String value that represents this BigInt value formatted according to the conventions of the 

host

environment

's current locale. This function is 

implementation-defined

, and it is permissible, but not encouraged, for it

to return the same thing as 

toString

toString

.

21.2.2.2  BigInt.asUintN ( 

bits

bigint

 )

21.2.2.3  BigInt.prototype

21.2.3  Properties of the BigInt Prototype Object

21.2.3.1  BigInt.prototype.constructor

21.2.3.2  BigInt.prototype.toLocaleString ( [ 

reserved1

 [ , 

reserved2

 ] ] )

516

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.

NOTE

The following steps are performed:

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

 < 2 or 

radixMV

 > 36, throw a 

RangeError

 exception.

5.  If 

radixMV

 = 10, return ! 

ToString

(

x

).

6.  Return the String representation of this 

Number value

 using the radix specified by 

radixMV

. Letters 

aa

-

zz

 are

used for digits with values 10 through 35. The precise algorithm is 

implementation-defined

, however the

algorithm should be a generalization of that specified in 

6.1.6.2.23

.

The 

toString

toString

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

1.  Return ? 

thisBigIntValue

(

this

 value).

The initial value of the 

@@toStringTag

 property is the String value 

"BigInt"

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

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

new

 operator.

does not have a [[Call]] internal method; it cannot be invoked as a function.

NOTE

The optional 

radix

 should be an 

integral Number

 value in the inclusive range 

2

𝔽

 to 

36

𝔽

. If 

radix

 is

undefined

 then 

10

𝔽

 is used as the value of 

radix

.

In this specification, the phrase “the 

Number value

 for 

x

” has a technical meaning defined in

6.1.6.1

.

21.2.3.3  BigInt.prototype.toString ( [ 

radix

 ] )

21.2.3.4  BigInt.prototype.valueOf ( )

21.2.3.5  BigInt.prototype [ @@toStringTag ]

21.3  The Math Object

517

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

 }.

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

 }.

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

 }.

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 

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 

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

 }.

The 

Number value

 for the square root of 

½

, which is approximately 0.7071067811865476.

The value of 

Math.LOG10E

Math.LOG10E

 is approximately the reciprocal of the value of 

Math.LN10

Math.LN10

.

The value of 

Math.LOG2E

Math.LOG2E

 is approximately the reciprocal of the value of 

Math.LN2

Math.LN2

.

21.3.1  Value Properties of the Math Object

21.3.1.1  Math.E

21.3.1.2  Math.LN10

21.3.1.3  Math.LN2

21.3.1.4  Math.LOG10E

21.3.1.5  Math.LOG2E

21.3.1.6  Math.PI

21.3.1.7  Math.SQRT1_2

518

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

NOTE

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

 }.

The initial value of the 

@@toStringTag

 property is the String value 

"Math"

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

NOTE

Returns the absolute value of 

x

; the result has the same magnitude as 

x

 but has positive sign.

When the 

Math.abs

Math.abs

 method is called with argument 

x

, the following steps are taken:

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

.

The value of 

Math.SQRT1_2

Math.SQRT1_2

 is approximately the reciprocal of the value of 

Math.SQRT2

Math.SQRT2

.

The behaviour of the functions 

acos

acos

acosh

acosh

asin

asin

asinh

asinh

atan

atan

atanh

atanh

atan2

atan2

cbrt

cbrt

,

cos

cos

cosh

cosh

exp

exp

expm1

expm1

hypot

hypot

log

log

log1p

log1p

log2

log2

log10

log10

pow

pow

random

random

sin

sin

sinh

sinh

,

sqrt

sqrt

tan

tan

, and 

tanh

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

fdlibm

, the freely distributable mathematical library from Sun

Microsystems (

http://www.netlib.org/fdlibm

).

21.3.1.8  Math.SQRT2

21.3.1.9  Math [ @@toStringTag ]

21.3.2  Function Properties of the Math Object

21.3.2.1  Math.abs ( 

x

 )

21.3.2.2  Math.acos ( 

x

 )

519

Returns the inverse cosine of 

x

. The result is expressed in radians and ranges from 

+0

𝔽

π

), inclusive.

When the 

Math.acos

Math.acos

 method is called with argument 

x

, the following steps are taken:

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

 value representing the result of the inverse cosine of 

n

).

Returns the inverse hyperbolic cosine of 

x

.

When the 

Math.acosh

Math.acosh

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

 or 

n

 is 

+

𝔽

, return 

n

.

3.  If 

n

 is 

1

𝔽

, return 

+0

𝔽

.

4.  If 

n

 < 

1

𝔽

, return 

NaN

.

5.  Return an 

implementation-approximated

n

).

Returns the inverse sine of 

x

(-

π

(

π

 / 2), inclusive.

When the 

Math.asin

Math.asin

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

, or 

n

 is 

-0

𝔽

, return 

n

.

3.  If 

n

 > 

1

𝔽

 or 

n

 < 

-1

𝔽

, return 

NaN

.

4.  Return an 

implementation-approximated

(

n

).

Returns the inverse hyperbolic sine of 

x

.

When the 

Math.asinh

Math.asinh

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

n

 is 

-0

𝔽

n

 is 

+

𝔽

, or 

n

 is 

-

𝔽

, return 

n

.

3.  Return an 

implementation-approximated

 value representing the result of the inverse hyperbolic sine of 

(

n

).

Returns the inverse tangent of 

x

. The result is expressed in radians and ranges from 

(-

π

 / 2) to 

π

 / 2), inclusive.

When the 

Math.atan

Math.atan

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

, or 

n

 is 

-0

𝔽

, return 

n

.

21.3.2.3  Math.acosh ( 

x

 )

21.3.2.4  Math.asin ( 

x

 )

21.3.2.5  Math.asinh ( 

x

 )

21.3.2.6  Math.atan ( 

x

 )

520

3.  If 

n

 is 

+

𝔽

, return an 

implementation-approximated

 value representing 

π

 / 2.

4.  If 

n

 is 

-

𝔽

, return an 

implementation-approximated

 value representing -

π

 / 2.

5.  Return an 

implementation-approximated

 value representing the result of the inverse tangent of 

(

n

).

Returns the inverse hyperbolic tangent of 

x

.

When the 

Math.atanh

Math.atanh

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

, or 

n

 is 

-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

 value representing the result of the inverse hyperbolic tangent of

(

n

).

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

Math.atan2

 method is called with arguments 

y

 and 

x

, the following steps are taken:

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

a.  If 

nx

 is 

+

𝔽

, return an 

implementation-approximated

 value representing 

π

 / 4.

b.  If 

nx

 is 

-

𝔽

, return an 

implementation-approximated

 value representing 3

π

 / 4.

c.  Return an 

implementation-approximated

 value representing 

π

 / 2.

5.  If 

ny

 is 

-

𝔽

, then

a.  If 

nx

 is 

+

𝔽

, return an 

implementation-approximated

 value representing -

π

 / 4.

b.  If 

nx

 is 

-

𝔽

, return an 

implementation-approximated

 value representing -3

π

 / 4.

c.  Return an 

implementation-approximated

 value representing -

π

 / 2.

6.  If 

ny

 is 

+0

𝔽

, then

a.  If 

nx

 > 

+0

𝔽

 or 

nx

 is 

+0

𝔽

, return 

+0

𝔽

.

b.  Return an 

implementation-approximated

 value representing 

π

.

7.  If 

ny

 is 

-0

𝔽

, then

a.  If 

nx

 > 

+0

𝔽

 or 

nx

 is 

+0

𝔽

, return 

-0

𝔽

.

b.  Return an 

implementation-approximated

 value representing -

π

.

8. 

Assert

ny

 is finite and is neither 

+0

𝔽

 nor 

-0

𝔽

.

9.  If 

ny

 > 

+0

𝔽

, then

a.  If 

nx

 is 

+

𝔽

, return 

+0

𝔽

.

21.3.2.7  Math.atanh ( 

x

 )

21.3.2.8  Math.atan2 ( 

y

x

 )

521

b.  If 

nx

 is 

-

𝔽

, return an 

implementation-approximated

 value representing 

π

.

c.  If 

nx

 is 

+0

𝔽

 or 

nx

 is 

-0

𝔽

, return an 

implementation-approximated

 value representing 

π

 / 2.

10.  If 

ny

 < 

+0

𝔽

, then

a.  If 

nx

 is 

+

𝔽

, return 

-0

𝔽

.

b.  If 

nx

 is 

-

𝔽

, return an 

implementation-approximated

 value representing -

π

.

c.  If 

nx

 is 

+0

𝔽

 or 

nx

 is 

-0

𝔽

, return an 

implementation-approximated

 value representing -

π

 / 2.

11. 

Assert

nx

 is finite and is neither 

+0

𝔽

 nor 

-0

𝔽

.

12.  Return an 

implementation-approximated

 value representing the result of the inverse tangent of the quotient

(

ny

nx

).

Returns the cube root of 

x

.

When the 

Math.cbrt

Math.cbrt

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

n

 is 

-0

𝔽

n

 is 

+

𝔽

, or 

n

 is 

-

𝔽

, return 

n

.

3.  Return an 

implementation-approximated

 value representing the result of the cube root of 

(

n

).

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

Math.ceil

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

n

 is 

-0

𝔽

n

 is 

+

𝔽

, or 

n

 is 

-

𝔽

, 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

When the 

Math.clz32

Math.clz32

 method is called with argument 

x

, the following steps are taken:

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

The value of 

Math.ceil(x)

Math.ceil(x)

 is the same as the value of 

-Math.floor(-x)

-Math.floor(-x)

.

If 

n

 is 

+0

𝔽

 or 

n

 is 

-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.9  Math.cbrt ( 

x

 )

21.3.2.10  Math.ceil ( 

x

 )

21.3.2.11  Math.clz32 ( 

x

 )

522

Returns the cosine of 

x

. The argument is expressed in radians.

When the 

Math.cos

Math.cos

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

, or 

n

 is 

-0

𝔽

, return 

n

.

3.  If 

n

 is 

+

𝔽

 or 

n

 is 

-

𝔽

, return 

NaN

.

4.  Return an 

implementation-approximated

n

).

Returns the hyperbolic cosine of 

x

.

When the 

Math.cosh

Math.cosh

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+

𝔽

, or 

n

 is 

-

𝔽

, return 

n

.

3.  If 

n

 is 

+0

𝔽

 or 

n

 is 

-0

𝔽

, return 

1

𝔽

.

4.  Return an 

implementation-approximated

n

).

NOTE

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

Math.exp

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

 or 

n

 is 

+

𝔽

, return 

n

.

3.  If 

n

 is 

+0

𝔽

 or 

n

 is 

-0

𝔽

, return 

1

𝔽

.

4.  If 

n

 is 

-

𝔽

, return 

+0

𝔽

.

5.  Return an 

implementation-approximated

(

n

).

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.

When the 

Math.expm1

Math.expm1

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

n

 is 

-0

𝔽

, or 

n

 is 

+

𝔽

, return 

n

.

3.  If 

n

 is 

-

𝔽

, return 

-1

𝔽

.

4.  Return an 

implementation-approximated

 value representing the result of subtracting 1 from the exponential

n

).

The value of 

Math.cosh(x)

Math.cosh(x)

 is the same as the value of

(Math.exp(x) + Math.exp(-x)) / 2

(Math.exp(x) + Math.exp(-x)) / 2

.

21.3.2.12  Math.cos ( 

x

 )

21.3.2.13  Math.cosh ( 

x

 )

21.3.2.14  Math.exp ( 

x

 )

21.3.2.15  Math.expm1 ( 

x

 )

523

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

Math.floor

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

n

 is 

-0

𝔽

n

 is 

+

𝔽

, or 

n

 is 

-

𝔽

, 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

When the 

Math.fround

Math.fround

 method is called with argument 

x

, the following steps are taken:

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 a value in 

IEEE 754-2019

 binary32 format using roundTiesToEven mode.

5.  Let 

n64

 be the result of converting 

n32

 to a value in 

IEEE 754-2019

 binary64 format.

6.  Return the ECMAScript 

Number value

 corresponding to 

n64

.

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

When the 

Math.hypot

Math.hypot

 method is called with zero or more arguments which form the rest parameter ...

args

, the

following steps are taken:

1.  Let 

coerced

 be a new empty 

List

.

2.  For each element 

arg

 of 

args

, do

a.  Let 

n

 be ? 

ToNumber

(

arg

).

b.  Append 

n

 to 

coerced

.

3.  Let 

onlyZero

 be 

true

.

4.  For each element 

number

 of 

coerced

, do

a.  If 

number

 is 

NaN

 or 

number

 is 

+

𝔽

, return 

number

.

b.  If 

number

 is 

-

𝔽

, return 

+

𝔽

.

c.  If 

number

 is neither 

+0

𝔽

 nor 

-0

𝔽

, set 

onlyZero

 to 

false

.

5.  If 

onlyZero

 is 

true

, return 

+0

𝔽

.

6.  Return an 

implementation-approximated

 value representing the square root of the sum of squares of the

mathematical values of the elements of 

coerced

.

The 

"length"

 property of the 

hypot

hypot

 method is 

2

𝔽

.

The value of 

Math.floor(x)

Math.floor(x)

 is the same as the value of 

-Math.ceil(-x)

-Math.ceil(-x)

.

21.3.2.16  Math.floor ( 

x

 )

21.3.2.17  Math.fround ( 

x

 )

21.3.2.18  Math.hypot ( ...

args

 )

524

 

 

 

 

 

 

 

Content      ..     46      47      48      49     ..