Constants
(constant) Infinity :number
The name
Infinity
refers to the special number value Infinity
.
See ECMAScript Specification, Section 4.3.23
Type:
- number
(constant) math_E :number
The Number value for e, Euler's number,
which is approximately 2.718281828459045.
Type:
- number
(constant) math_LN2 :number
The Number value for the natural logarithm of 2,
which is approximately 0.6931471805599453.
Type:
- number
(constant) math_LN10 :number
The Number value for the natural logarithm of 10,
which is approximately 2.302585092994046.
Type:
- number
(constant) math_LOG2E :number
The Number value for the base-2 logarithm of eℝ, the base of the natural logarithms;
this value is approximately 1.4426950408889634.
NOTE:
The value of math_LOG2E is approximately the reciprocal of the value of math_LN2.
Type:
- number
(constant) math_LOG10E :number
The Number value for the base-10 logarithm of e,
the base of the natural logarithms; this value is approximately 0.4342944819032518.
NOTE:
The value of math_LOG10E is approximately the reciprocal of the value of math_LN10.
Type:
- number
(constant) math_PI :number
The Number value for π, the ratio of the circumference of a circle to its diameter,
which is approximately 3.1415926535897932.
Type:
- number
(constant) math_SQRT1_2 :number
The Number value for the square root of 0.5, which is approximately 0.7071067811865476.
NOTE:
The value of math_SQRT1_2 is approximately the reciprocal of the value of math_SQRT2.
Type:
- number
(constant) math_SQRT2 :number
The Number value for the square root of 2, which is approximately 1.4142135623730951.
Type:
- number
(constant) NaN :number
The name
NaN
refers to the special number value NaN
("not a number"). Note that
NaN
is a number, as specified by is_number
.
See ECMAScript Specification, Section 4.3.24
Type:
- number
(constant) undefined :undefined
The name
undefined
refers to the special value undefined
.
See also textbook explanation in section 4.1.1.
Type:
Functions
arity(f) → {number}
Returns the number of parameters the given function
f
expects,
excluding the rest parameter.
Parameters:
Name | Type | Description |
---|---|---|
f |
function | given function |
Returns:
number of parameters f expects
- Type
- number
char_at(s, i) → {string}
Takes a string
s
as first argument and a nonnegative integer
i
as second argument. If i
is less than the length
of s
, this function returns a one-character string that contains
the character of s
at position i
, counting from 0.
If i
is larger than or equal to the length of
s
, this function returns undefined
.
Parameters:
Name | Type | Description |
---|---|---|
s |
string | given string |
i |
number | index |
Returns:
one-character or undefined
- Type
- string
display(v, s) → {value}
Optional second argument. If present,
displays the given string
s
, followed by a space character, followed by the
value v
in the console.
If second argument not present,
just displays the value v
in the console.
The notation used for the display of values
is consistent with
JSON,
but also displays undefined
, NaN
, Infinity
, and function objects.
Parameters:
Name | Type | Description |
---|---|---|
v |
value | to be displayed |
s |
string | to be displayed, preceding v , optional argument |
Returns:
v, the first argument value
- Type
- value
error(v, s)
Optional second argument.
If present,
displays the given string
s
, followed by a space character, followed by the
value v
in the console with error flag.
If second argument not present,
just displays the value v
in the console with error flag.
The evaluation
of any call of error
aborts the running program immediately.
The notation used for the display of values
is consistent with
JSON,
but also displays undefined
, NaN
, Infinity
, and function objects.
Parameters:
Name | Type | Description |
---|---|---|
v |
value | to be displayed |
s |
string | to be displayed, preceding v |
get_time() → {number}
Returns number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
See also textbook example.
Returns:
current time in milliseconds
- Type
- number
is_boolean(v) → {boolean}
checks whether a given value is a boolean
Parameters:
Name | Type | Description |
---|---|---|
v |
value | to be checked |
Returns:
indicating whether the value is a boolean
- Type
- boolean
is_function(v) → {boolean}
checks whether a given value is a function
Parameters:
Name | Type | Description |
---|---|---|
v |
value | to be checked |
Returns:
indicating whether the value is a function
- Type
- boolean
is_number(v) → {boolean}
checks whether a given value is a number.
See also textbook example.
Parameters:
Name | Type | Description |
---|---|---|
v |
value | to be checked |
Returns:
indicating whether the value is a number
- Type
- boolean
is_string(v) → {boolean}
checks whether a given value is a string.
See also textbook example.
Parameters:
Name | Type | Description |
---|---|---|
v |
value | to be checked |
Returns:
indicating whether the value is a string
- Type
- boolean
is_undefined(v) → {boolean}
checks whether a given value is the special value
undefined
Parameters:
Name | Type | Description |
---|---|---|
v |
value | to be checked |
Returns:
indicating whether the value is
undefined
- Type
- boolean
math_abs(x
) → {number}
computes the absolute value of x; the result has the same magnitude as
x
but has positive sign.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
absolute value of
x
- Type
- number
math_acos(x
) → {number}
computes the arc cosine of
x
.
The result is expressed in radians and ranges from +0 to +π.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
arc cosine of
x
- Type
- number
math_acosh(x
) → {number}
computes the inverse hyperbolic cosine of
x
.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
inverse hyperbolic cosine of
x
.
- Type
- number
math_asin(x
) → {number}
computes the arc sine of
x
. The result is expressed in radians and ranges from -π / 2 to +π / 2.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
arc sine of
x
.
- Type
- number
math_asinh(x
) → {number}
computes the inverse hyperbolic
sine of
x
. The result is expressed in radians and ranges from -π / 2 to +π / 2.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
inverse hyperbolic sine of
x
- Type
- number
math_atan(x
) → {number}
computes the arc tangent of
x
. The result is expressed in radians and ranges from -π / 2 to +π / 2.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
arc tangent of
x
- Type
- number
math_atan2(y
, x
) → {number}
computes 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 +π.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given first number |
|
number | given second number |
Returns:
arc tangent of
y
/ x
.
- Type
- number
math_atanh(x
) → {number}
computes the inverse hyperbolic tangent of
x
.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
inverse hyperbolic tangent of
x
.
- Type
- number
math_cbrt(x
) → {number}
computes the cube root of
x
.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
cube root of
x
.
- Type
- number
math_ceil(x
) → {number}
computes 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
.
The value of math_ceil(x) is the same as the value of -math_floor(-x).
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
"ceiling" of the number
- Type
- number
math_clz32(n) → {number}
When math_clz32 is called with one argument
If n is 0, p will be 32. If the most significant bit of the 32-bit binary encoding of n is 1, p will be 0.
x
, the following steps are taken:
Let n be ToUint32(x).
Let p be the number of leading zero bits in the 32-bit binary representation of n.
Return p.
NOTE:
If n is 0, p will be 32. If the most significant bit of the 32-bit binary encoding of n is 1, p will be 0.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | given number |
Returns:
p - leading zero bits
- Type
- number
math_cos(x
) → {number}
Computes the cosine of
x
.
The argument is expressed in radians.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
- cosine of
x
- Type
- number
math_cosh(x
) → {number}
computes the hyperbolic cosine of
x
.
NOTE:
The value of cosh(x) is the same as (exp(x) + exp(-x)) / 2.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
hyperbolic cosine of
x
- Type
- number
math_exp(x
) → {number}
computes the exponential function of
x
(e raised to the power of x
, where e is the base of the natural logarithms).
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
e to the power of
x
- Type
- number
math_expm1(x
) → {number}
computes 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.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
-1 plus e to the power of
x
- Type
- number
math_floor(x
) → {number}
computes the greatest (closest to +∞) Number value that is not greater than
If
x
and is an integer.
If
x
is already an integer, the result is x
.
NOTE:
The value of math_floor(x) is the same as the value of -math_ceil(-x).
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
floor of
x
- Type
- number
math_fround(x
) → {number}
When math_fround is called with argument
x
, the following steps are taken:
- If
x
is NaN, return NaN. - If
x
is one of +0, -0, +∞, -∞, returnx
. - Let x32 be the result of converting
x
to a value in IEEE 754-2008 binary32 format using roundTiesToEven mode. - Let x64 be the result of converting x32 to a value in IEEE 754-2008 binary64 format.
- Return the ECMAScript Number value corresponding to x64.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
fround of
x
- Type
- number
math_hypot() → {number}
computes the square root
of the sum of squares of its arguments.
If no arguments are passed, the result is +0.
If no arguments are passed, the result is +0.
Parameters:
Name | Type | Description |
---|---|---|
value1,value2,... |
number | given numbers |
Returns:
square root of sum of squares of arguments
- Type
- number
math_imul(x
, x
) → {number}
When math_imul is called with arguments
x
and y
,
the following steps are taken:
- Let a be ToUint32(x).
- Let b be ToUint32(y).
- Let product be (a × b) modulo 232.
- If product ≥ 231, return product - 232; otherwise return product.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given first number |
|
number | given second number |
Returns:
-
x
imul y
- Type
- number
math_log(x
) → {number}
Computes the natural logarithm of
x
.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
- natural logarithm of
x
- Type
- number
math_log1p(x
) → {number}
computes 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.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
math_log(1 + x)
- Type
- number
math_log2(x
) → {number}
computes the base 2 logarithm of
x
.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
base 2 logarithm of
x
- Type
- number
math_log10(x
) → {number}
computes the base 10 logarithm of
x
.
Parameters:
Name | Type | Description |
---|---|---|
|
number | given number |
Returns:
base 10 logarithm of
x
- Type
- number
math_max() → {number}
Given zero or more numbers, returns the largest of them.
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.
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.
Parameters:
Name | Type | Description |
---|---|---|
value1,value2,... |
number | given numbers |
Returns:
largest of them
- Type
- number
math_min() → {number}
Given zero or more arguments, returns the smallest of them.
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.
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.
Parameters:
Name | Type | Description |
---|---|---|
value1,value2,... |
number | given numbers |
Returns:
smallest of them
- Type
- number
math_pow(base, exponent) → {number}
Computes the result of raising base to
the power of exponent.
Parameters:
Name | Type | Description |
---|---|---|
base |
number | the given base |
exponent |
number | the given exponent |
Returns:
base
to the power of exponent
- Type
- number
math_random() → {number}
Returns a number value with positive sign, greater than or equal to 0 but less than 1,
chosen randomly or pseudo randomly with approximately uniform distribution over that
range, using an implementation-dependent algorithm or strategy. This function takes no arguments.
Each math_random function created for distinct realms must produce a distinct sequence
of values from successive calls.
Returns:
random number greater than or equal to 0 but less than 1
- Type
- number
math_round(x
) → {number}
Returns the number value that is closest to
If two integers are equally close 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
.
NOTE 1:
math_round(3.5) returns 4, but math_round(-3.5) returns -3.
Parameters:
Name | Type | Description |
---|---|---|
|
number | the given number |
Returns:
closest integer to
x
- Type
- number
math_sign(x
) → {number}
Computes the sign of
x
, indicating whether x
is positive, negative, or zero.
Parameters:
Name | Type | Description |
---|---|---|
|
number | the given number |
Returns:
the sign (-1, 0 or +1)
- Type
- number
math_sin(x
) → {number}
Computes the sine of
x
.
The argument is expressed in radians.
Parameters:
Name | Type | Description |
---|---|---|
|
number | the given number |
Returns:
the sine of
x
- Type
- number
math_sinh(x
) → {number}
Computes the hyperbolic sine of
x
.
NOTE:
The value of sinh(x) is the same as (exp(x) - exp(-x)) / 2.
Parameters:
Name | Type | Description |
---|---|---|
|
number | the given number |
Returns:
the hyperbolic sine of
x
- Type
- number
math_sqrt(x
) → {number}
Computes the square root of
x
.
Parameters:
Name | Type | Description |
---|---|---|
|
number | the given number |
Returns:
the square root of
x
- Type
- number
math_tan(x
) → {number}
Computes the tangent of
x
. The argument is expressed in radians.
Parameters:
Name | Type | Description |
---|---|---|
|
number | the given number |
Returns:
the tangent of
x
- Type
- number
math_tanh(x
) → {number}
Computes the hyperbolic tangent of
x
.
NOTE:
The value of math_tanh(x)
is the same as
(exp(x) - exp(-x))/(exp(x) + exp(-x))
.
Parameters:
Name | Type | Description |
---|---|---|
|
number | the given number |
Returns:
the hyperbolic tangent of
x
- Type
- number
math_trunc(x
) → {number}
Computes the integral part of the number
x
,
removing any fractional digits.
Parameters:
Name | Type | Description |
---|---|---|
|
number | the given number |
Returns:
the integral part of
x
- Type
- number
parse_int(s, i) → {number}
Interprets a given string
Examples:
See ECMAScript Specification, Section 18.2.5 for details.
s
as an integer,
using the positive integer i
as radix,
and returns the respective value.
Examples:
parse_int("909", 10)
returns the number
909
, and parse_int("-1111", 2)
returns the number
-15
.See ECMAScript Specification, Section 18.2.5 for details.
Parameters:
Name | Type | Description |
---|---|---|
s |
string | string to be converted |
i |
number | radix |
Returns:
result of conversion
- Type
- number
prompt(s) → {string}
Pops up a window that displays the string
s
, provides
an input line for the user to enter a text, a Cancel
button and an OK
button.
The call of prompt
suspends execution of the program until one of the two buttons is pressed. If
the OK
button is pressed, prompt
returns the entered text as a string.
If the Cancel
button is pressed, prompt
returns a non-string value.
Parameters:
Name | Type | Description |
---|---|---|
s |
string | to be displayed in popup |
Returns:
entered text
- Type
- string
stringify(v) → {string}
returns a string that represents the value
v
, using a
notation that is is consistent with
JSON,
but also displays undefined
, NaN
, Infinity
, and function objects.
See also textbook example.
Parameters:
Name | Type | Description |
---|---|---|
v |
value | the argument value |
Returns:
string representation of v
- Type
- string