Math Funcers

+

Adds two numbers.

TypeValue
InputNumthe first summand
b (param #1)Numthe second summand
OutputNumthe sum

Examples

ProgramTypeValueError
1 +1Num2
1 +2 *3Num9
1 +(2 *3)Num7

-

Subtracts a number from another.

TypeValue
InputNumthe minuend
b (param #1)Numthe subtrahend
OutputNumthe difference

Examples

ProgramTypeValueError
5 -3Num2

-

Returns the additive inverse of a number.

TypeValue
InputAnyany value (is ignored)
n (param #1)Numa number
OutputNumthe additive inverse (opposite number) of n

Examples

ProgramTypeValueError
-1Num-1
-(-2.0)Num2
-infNum-inf
-nanNumnan

*

Multiplies two numbers.

TypeValue
InputNumthe first factor
b (param #1)Numthe second factor
OutputNumthe product

Examples

ProgramTypeValueError
2 *3Num6

/

Divides a number by another.

TypeValue
InputNumthe dividend
b (param #1)Numthe divisor
OutputNumthe quotient

Examples

ProgramTypeValueError
3 /2Num1.5
1 /0Numinf

%

Remainder

TypeValue
InputNumthe dividend
b (param #1)Numthe divisor
OutputNumthe remainder of integer division (rounded towards zero)

Examples

ProgramTypeValueError
3 %2Num1
-8.5 %3Num-2.5

<

Less than

TypeValue
InputNuma number
b (param #1)Numanother number
OutputBooltrue iff the input is smaller than b

Examples

ProgramTypeValueError
2 <1Boolfalse
-inf <infBooltrue
0 <0Boolfalse

>

Greater than

TypeValue
InputNuma number
b (param #1)Numanother number
OutputBooltrue iff the input is greater than b

Examples

ProgramTypeValueError
2 >1Booltrue
-inf >infBoolfalse
0 >0Boolfalse

<=

Less than or equal to

TypeValue
InputNuma number
b (param #1)Numanother number
OutputBooltrue iff the input is less than or equal to b

Examples

ProgramTypeValueError
2 <=1Boolfalse
-inf <=infBooltrue
0 <=0Booltrue

>=

Greater than or equal to

TypeValue
InputNuma number
b (param #1)Numanother number
OutputBooltrue iff the input is greater than or equal to b

Examples

ProgramTypeValueError
2 >=1Booltrue
-inf >=infBoolfalse
0 >=0Booltrue

sum

Computes the sum of several numbers.

TypeValue
InputArr<Num...>an array of numbers
OutputNumtheir sum

Examples

ProgramTypeValueError
[1, 2, 3, 4] sumNum10
[] sumNum0

median

Computes the median of several numbers.

TypeValue
InputArr<Num...>an array of numbers
OutputNumtheir median

Examples

ProgramTypeValueError
[2, 3, 7] medianNum3
[2, 3, 5, 7] medianNum4
[1.25] medianNum1.25
[] medianNumnan

mean

Computes the arithmetic mean (average) of several numbers.

TypeValue
InputArr<Num...>an array of numbers
OutputNumtheir mean

Examples

ProgramTypeValueError
[2, 3, 5, 7] meanNum4.25
[1.25] meanNum1.25
[] meanNumnan

inf

Returns infinity.

TypeValue
InputAnyany value (is ignored)
OutputNumthe special number value representing positive infinity

Examples

ProgramTypeValueError
infNuminf
-infNum-inf
inf +infNuminf
inf -infNumnan

nan

Returns NaN.

TypeValue
InputAnyany value (is ignored)
OutputNumthe special number value representing “not a number”

Examples

ProgramTypeValueError
nanNumnan
nan ==2Boolfalse
nan ==nanBoolfalse
-nanNumnan

isFinite

Checks whether a number is finite.

TypeValue
InputNuma number
OutputBooltrue unless the input is positive or negative infinity

Examples

ProgramTypeValueError
1024 isFiniteBooltrue
-1024 isFiniteBooltrue
inf isFiniteBoolfalse
-inf isFiniteBoolfalse
nan isFiniteBooltrue

isNaN

Checks whether a number is NaN.

TypeValue
InputNuma number
OutputBooltrue iff the input is NaN

Examples

ProgramTypeValueError
1024 isNaNBoolfalse
nan isNaNBooltrue

epsilon

Returns the floating point epsilon.

TypeValue
InputAnyany value (is ignored)
OutputNumthe difference between 1 and the smallest floating point number greater than 1

Examples

ProgramTypeValueError
epsilonNum2.220446049250313e-16

largestSafeInteger

Returns the largest safe integer.

TypeValue
InputAnyany value (is ignored)
OutputNumthe largest integer that can be represented as an IEEE-754 double precision number and cannot be the result of rounding another number to fit IEEE-754

Examples

ProgramTypeValueError
largestSafeInteger +0Num9007199254740991
largestSafeInteger +1Num9007199254740992
largestSafeInteger +2Num9007199254740992

largestNum

Returns the largest representable number.

TypeValue
InputAnyany value (is ignored)
OutputNumthe largest number representable as an IEEE-754 double precision number

Examples

ProgramTypeValueError
largestNumNum1.7976931348623157e+308
largestNum +largestNumNuminf

smallestSafeInteger

Returns the smallest safe integer.

TypeValue
InputAnyany value (is ignored)
OutputNumthe smallest integer that can be represented as an IEEE-754 double precision number and cannot be the result of rounding another integer to fit the IEEE-754 double precision representation

Examples

ProgramTypeValueError
smallestSafeInteger -0Num-9007199254740991
smallestSafeInteger -1Num-9007199254740992
smallestSafeInteger -2Num-9007199254740992

smallestPositiveNum

Returns the smallest representable positive number.

TypeValue
InputAnyany value (is ignored)
OutputNumthe smallest representable positive number

Examples

ProgramTypeValueError
smallestPositiveNumNum5e-324

isInteger

Checks whether a number is integer.

TypeValue
InputNuma number
OutputBooltrue iff the input represents a whole number

Examples

ProgramTypeValueError
1.0 isIntegerBooltrue
1.1 isIntegerBoolfalse

isSafeInteger

Checks whether a number is a safe integer.

TypeValue
InputNuma number
OutputBooltrue iff the input is an integer and cannot be the result of rounding another integer to fit the IEEE-754 double precision representation

Examples

ProgramTypeValueError
-9007199254740992 isSafeIntegerBoolfalse
-9007199254740991 isSafeIntegerBooltrue
0 isSafeIntegerBooltrue
0.1 isSafeIntegerBoolfalse
9007199254740991 isSafeIntegerBooltrue
9007199254740992 isSafeIntegerBoolfalse

toBase

Converts an integer to a specified base.

TypeValue
InputNuman integer
base (param #1)Numan integer between 2 and 36 (inclusive)
OutputStra string representation of the input in the specified base

Examples

ProgramTypeValueError
233 toBase(16)Str"e9"
11 toBase(16)Str"b"

toExponential

Converts a number to exponential notation.

TypeValue
InputNuma number
OutputStra string representation of the input in exponential notation with 6 digits after the decimal point

Examples

ProgramTypeValueError
77.1234 toExponentialStr"7.712340e+01"
77 toExponentialStr"7.700000e+01"

toExponential

Converts a number to exponential notation.

TypeValue
InputNuma number
precision (param #1)Numthe number of digits after the decimal point
OutputStra string representation of the input in exponential notation with the specified number of digits after the decimal point

Examples

ProgramTypeValueError
77.1234 toExponential(4)Str"7.7123e+01"
77.1234 toExponential(2)Str"7.71e+01"

toFixed

Converts a number to fixed-point notation.

TypeValue
InputNuma number
precision (param #1)Numthe number of digits after the decimal point
OutputStra rounded string representation of the input with the specified number of digits after the decimal point

Examples

ProgramTypeValueError
123.456 toFixed(2)Str"123.46"
0.004 toFixed(2)Str"0.00"
1.23e+5 toFixed(2)Str"123000.00"

e

Returns Euler's number.

TypeValue
InputAnyany value (is ignored)
OutputNuman approximation of Euler's number

Examples

ProgramTypeValueError
eNum2.718281828459045

ln2

Returns the natural logarithm of 2.

TypeValue
InputAnyany value (is ignored)
OutputNumthe approximate natural logarithm of 2

Examples

ProgramTypeValueError
ln2Num0.6931471805599453

ln10

Returns the natural logarithm of 10.

TypeValue
InputAnyany value (is ignored)
OutputNumthe approximate natural logarithm of 10

Examples

ProgramTypeValueError
ln10Num2.302585092994046

log2e

Returns the base-2 logarithm of e

TypeValue
InputAnyany value (is ignored)
OutputNumthe approximate base-2 logarithm of Euler's number

Examples

ProgramTypeValueError
log2eNum1.4426950408889634

log10e

Returns the base-10 logarithm of e

TypeValue
InputAnyany value (is ignored)
OutputNumthe approximate base-10 logarithm of Euler's number

Examples

ProgramTypeValueError
log10eNum0.4342944819032518

pi

Returns pi.

TypeValue
InputAnyany value (is ignored)
OutputNuman approximation of pi

Examples

ProgramTypeValueError
piNum3.141592653589793
for Num def radiusToCircumference Num as *2 *pi ok 10 radiusToCircumferenceNum62.83185307179586

sqrt1_2

Returns the square root of 1/2.

TypeValue
InputAnyany value (is ignored)
OutputNumthe approximate square root of 1/2

Examples

ProgramTypeValueError
sqrt1_2Num0.7071067811865476

sqrt2

Returns the square root of 2.

TypeValue
InputAnyany value (is ignored)
OutputNumthe approximate square root of 2

Examples

ProgramTypeValueError
sqrt2Num1.4142135623730951

abs

Computes the absolute value.

TypeValue
InputNuma number
OutputNumthe absolute value of the input

Examples

ProgramTypeValueError
3 -5 absNum2
5 -3 absNum2
1.23456 -7.89012 absNum6.6555599999999995

acos

Computes the inverse cosine.

TypeValue
InputNuma number in the interval [-1, 1]
OutputNumthe inverse cosine (in radians) of the input, or nan if the input is invalid

Examples

ProgramTypeValueError
-2 acosNumnan
-1 acosNum3.141592653589793
0 acosNum1.5707963267948966
1 acosNum0
1.1 acosNumnan

acosh

Computes the inverse hyperbolic cosine.

TypeValue
InputNuma number greater than or equal to 1
OutputNumthe inverse hyperoblic cosine of the input, or nan if the input is invalid

Examples

ProgramTypeValueError
0.9 acoshNumnan
1 acoshNum0
10 acoshNum2.993222846126381

asin

Computes the inverse sine.

TypeValue
InputNuma number in the interval [-1, 1]
OutputNumthe inverse sine (in radians) of the input, of nan if the input is invalid

Examples

ProgramTypeValueError
-2 asinNumnan
-1 asinNum-1.5707963267948966
0 asinNum0
1 asinNum1.5707963267948966
1.1 asinNumnan

asinh

Computes the inverse hyperbolic sine.

TypeValue
InputNuma number
OutputNumthe inverse hyperbolic sine of the input

Examples

ProgramTypeValueError
-1 asinhNum-0.881373587019543
0 asinhNum0
1 asinhNum0.881373587019543
2 asinhNum1.4436354751788103

atan

Computes the inverse tangent.

TypeValue
InputNuma number
OutputNumthe inverse tangent (in radians) of the input

Examples

ProgramTypeValueError
-10 atanNum-1.4711276743037345
-1 atanNum-0.7853981633974483
0 atanNum0
1 atanNum0.7853981633974483

atan2

Computes the angle in the plane.

TypeValue
InputNuma number y (y-coordinate)
x (param #1)Numa number (x-coordinate)
OutputNumthe angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to (x, y)

Examples

ProgramTypeValueError
5 atan2(5)Num0.7853981633974483
10 atan2(10)Num0.7853981633974483
10 atan2(0)Num1.5707963267948966

atanh

Computes the inverse hyperbolic tangent.

TypeValue
InputNuma number in the interval [-1, 1]
OutputNumthe inverse hyperbolic tangent of the input, or nan if the input is invalid

Examples

ProgramTypeValueError
-2 atanhNumnan
-1 atanhNum-inf
0 atanhNum0
0.5 atanhNum0.5493061443340548
1 atanhNuminf

cbrt

Computes the cube root.

TypeValue
InputNuma number
OutputNumthe cube root of the input

Examples

ProgramTypeValueError
-1 cbrtNum-1
1 cbrtNum1
inf cbrtNuminf
64 cbrtNum4

ceil

Rounds a number up.

TypeValue
InputNuma number
OutputNumthe smallest integer greater than or equal to the input

Examples

ProgramTypeValueError
.95 ceilNum1
4 ceilNum4
7.004 ceilNum8
-7.004 ceilNum-7

clz32

Count leading zeros.

TypeValue
InputNuma number (is truncated to integer)
OutputNumthe number of leading zero bits in the 32-bit binary representation of the input

Examples

ProgramTypeValueError
-inf clz32Num32
-4 clz32Num0
-1 clz32Num0
0 clz32Num32
0.5 clz32Num32
1 clz32Num31
1.1 clz32Num31
4 clz32Num29
4.7 clz32Num29
1000 clz32Num22
inf clz32Num32

cos

Computes the cosine.

TypeValue
InputNuman angle in radians
OutputNumthe cosine of the input

Examples

ProgramTypeValueError
-inf cosNumnan
-0 cosNum1
0 cosNum1
1 cosNum0.5403023058681398
pi cosNum-1
pi *2 cosNum1
inf cosNumnan

cosh

Computes the hyperbolic cosine.

TypeValue
InputNuma number
OutputNumthe hyperbolic cosine of the input

Examples

ProgramTypeValueError
0 coshNum1
1 coshNum1.5430806348152437
-1 coshNum1.5430806348152437
2 coshNum3.7621956910836314

exp

Computes the exponential function.

TypeValue
InputNumthe exponent
OutputNume (Euler's number) raised to the exponent

Examples

ProgramTypeValueError
-inf expNum0
-1 expNum0.36787944117144233
0 expNum1
1 expNum2.718281828459045
inf expNuminf

expm1

Computes the exponential function, subtracted by one.

TypeValue
InputNumthe exponent
OutputNum

e (Euler's number) raised to the exponent, minus 1

Examples

ProgramTypeValueError
-inf expm1Num-1
-1 expm1Num-0.6321205588285577
-0 expm1Num-0
0 expm1Num0
1 expm1Num1.718281828459045
inf expm1Numinf

floor

Rounds down.

TypeValue
InputNuma number
OutputNumthe largest integer less than or equal to the input

Examples

ProgramTypeValueError
5.95 floorNum5
5.05 floorNum5
5 floorNum5
-5.05 floorNum-6

fround

Rounds to 32-bit precision.

TypeValue
InputNuma number
OutputNumthe nearest 32-bit single precision float representation

Examples

ProgramTypeValueError
5.5 froundNum5.5
5.05 froundNum5.050000190734863
5 froundNum5
-5.05 froundNum-5.050000190734863

hypot

Computes the square root of the sum of squares

TypeValue
InputArr<Num...>an array of numbers
OutputNumthe square root of the sum of the squares of the input numbers

Examples

ProgramTypeValueError
[3, 4] hypotNum5
[5, 12] hypotNum13
[3, 4, 5] hypotNum7.0710678118654755
[-5] hypotNum5

imul

32-bit multiplication

TypeValue
InputNumthe first factor
y (param #1)Numthe second factor
OutputNumthe product of the 32-bit versions (cf. fround) of the factors

Examples

ProgramTypeValueError
3 imul(4)Num12
-5 imul(12)Num-60
"ffffffff" parseInt(16) imul(5)Num-5
"fffffffe" parseInt(16) imul(5)Num-10

log

Computes the natural logarithm.

TypeValue
InputNuma number
OutputNumthe natural (base e) logarithm of the input

Examples

ProgramTypeValueError
-1 logNumnan
-0 logNum-inf
0 logNum-inf
1 logNum0
10 logNum2.302585092994046
inf logNuminf
8 log /(2 log)Num3
625 log /(5 log)Num4

log10

Computes the base 10 logarithm.

TypeValue
InputNuma number
OutputNumthe base 10 logarithm of the input

Examples

ProgramTypeValueError
-2 log10Numnan
-0 log10Num-inf
0 log10Num-inf
1 log10Num0
2 log10Num0.3010299956639812
100000 log10Num5
inf log10Numinf

log1p

Computes the natural logarithm of x + 1.

TypeValue
InputNuma number (x)
OutputNum

the natural (base e) logarithm of (x + 1)

Examples

ProgramTypeValueError
1 log1pNum0.6931471805599453
0 log1pNum0
-1 log1pNum-inf
-2 log1pNumnan

log2

Computes the base 2 logarithm.

TypeValue
InputNuma number
OutputNumthe base 2 logarithm of the input

Examples

ProgramTypeValueError
3 log2Num1.5849625007211563
2 log2Num1
1 log2Num0
0 log2Num-inf

max

Finds the largest number

TypeValue
InputArr<Num...>an array of numbers
OutputNumthe largest number in the input, or -inf if the input is empty

Examples

ProgramTypeValueError
[1, 3, 2] maxNum3
[-1, -3, -2] maxNum-1
[] maxNum-inf

min

Finds the smallest number

TypeValue
InputArr<Num...>an array of numbers
OutputNumthe smallest number in the input, or inf if the input is empty

Examples

ProgramTypeValueError
[1, 3, 2] minNum1
[-1, -3, -2] minNum-3
[] minNuminf

**

Computes powers (exponentiation).

TypeValue
InputNumthe base
y (param #1)Numthe exponent
OutputNumthe base taken to the y-th power

Examples

ProgramTypeValueError
7 **3Num343
4 **.5Num2
7 **(-2)Num0.02040816326530612
-7 **0.5Numnan

random

Returns a random number between 0 and 1.

TypeValue
InputAnyany value (is ignored)
OutputNuma floating-point, pseudo-random number n with 0 <= n < 1 and approximately uniform distribution over that range

Examples

ProgramTypeValueError
[null] repeat(1000) each(random) each(>=0) allBooltrue
[null] repeat(1000) each(random) each(<1) allBooltrue

random

Returns a random integer number in a specified interval.

TypeValue
InputAnyany value (is ignored)
from (param #1)Numlower bound (inclusive); rounded towards 0 if not integer
to (param #2)Numupper bound (exclusive); rounded towards 0 if not integer
OutputNuma integer, pseudorandom number n with from <= n < to and approximately uniform distribution over that range

Examples

ProgramTypeValueError
[null] repeat(1000) each(random(2, 7)) each(>=2) allBooltrue
[null] repeat(1000) each(random(2, 7)) each(<7) allBooltrue
[null] repeat(1000) each(random(2, 7)) each(=n floor ==n) allBooltrue
[null] repeat(1000) each(random(2.4, 7.6)) each(>=2) allBooltrue
[null] repeat(1000) each(random(2.4, 7.6)) each(<7) allBooltrue
[null] repeat(1000) each(random(2.4, 7.6)) each(=n floor ==n) allBooltrue
[null] repeat(1000) each(random(-7, -2)) each(>=(-7)) allBooltrue
[null] repeat(1000) each(random(-7, -2)) each(<(-2)) allBooltrue
[null] repeat(1000) each(random(-7, -2)) each(=n floor ==n) allBooltrue
[null] repeat(1000) each(random(-7.6, -2.4)) each(>=(-7)) allBooltrue
[null] repeat(1000) each(random(-7.6, -2.4)) each(<(-2)) allBooltrue
[null] repeat(1000) each(random(-7.6, -2.4)) each(=n floor ==n) allBooltrue
random(7, 2)BoolValue error
Code: UnexpectedValue
Message: Component got an unexpected input value.
random(2, 2)BoolValue error
Code: UnexpectedValue
Message: Component got an unexpected input value.

round

Rounds a number to the nearest integer.

TypeValue
InputNuma number
OutputNumthe nearest integer, or away from zero if there's two nearest integers

Examples

ProgramTypeValueError
0.9 roundNum1
5.95 roundNum6
5.5 roundNum6
5.05 roundNum5
-5.05 roundNum-5
-5.5 roundNum-6
-5.95 roundNum-6

sign

Determines the sign of a number.

TypeValue
InputNuma number
OutputNum1 if the input is positive, -1 if negative, 0 if it's 0, and -0 if it's -0

Examples

ProgramTypeValueError
3 signNum1
0 signNum0
-0 signNum-0
-3Num-3

sin

Computes the sine.

TypeValue
InputNuman angle in radians
OutputNumthe sine of the input

Examples

ProgramTypeValueError
-inf sinNumnan
-0 sinNum-0
0 sinNum0
1 sinNum0.8414709848078965
pi /2 sinNum1
inf sinNumnan

sinh

Computes the hyperbolic sine.

TypeValue
InputNuma number
OutputNumthe hyperbolic sine of the input

Examples

ProgramTypeValueError
0 sinhNum0
1 sinhNum1.1752011936438014
-1 sinhNum-1.1752011936438014
2 sinhNum3.626860407847019

sqrt

Computes square roots.

TypeValue
InputNuma number
OutputNumthe square root of the input, or nan if it's negative

Examples

ProgramTypeValueError
-1 sqrtNumnan
-0 sqrtNum-0
0 sqrtNum0
1 sqrtNum1
2 sqrtNum1.4142135623730951
9 sqrtNum3
inf sqrtNuminf

tan

Computes the tangent.

TypeValue
InputNuman angle in radians
OutputNumthe tangent of the input

Examples

ProgramTypeValueError
0 *pi /180 tanNum0
45 *pi /180 tanNum1
90 *pi /180 tanNum16331239353195392

tanh

Computes the hyperbolic tangent.

TypeValue
InputNuma number
OutputNumthe hyperbolic tangent of the input

Examples

ProgramTypeValueError
-1 tanhNum-0.7615941559557649
0 tanhNum0
inf tanhNum1
1 tanhNum0.7615941559557649

trunc

Rounds towards zero.

TypeValue
InputNuma number
OutputNumthe input without fractional digits

Examples

ProgramTypeValueError
13.37 truncNum13
42.84 truncNum42
0.123 truncNum0
-0.123 truncNum-0