Skip to content

Math

Standard constants and functions related to mathematics and numerical computation are assigned the namespace of Math:.

Constants

The type is all num.

NameDescriptionRough Value
Math:InfinityPositive infinityN/A
Math:ENapier number e2.718281828459045
Math:LN2Natural logarithm of 20.6931471805599453
Math:LN10Natural logarithm of 102.302585092994046
Math:LOG2ELogarithm of e with base 21.4426950408889634
Math:LOG10ELogarithm of e with base 100.4342944819032518
Math:PIPi π3.141592653589793
Math:SQRT1_2120.7071067811865476
Math:SQRT221.4142135623730951

Basic Functions

@Math:abs(x: num): num

Calculate absolute value. |x|

@Math:sign(x: num): num

Returns 1 if x is positive, -1 if it is negative, and the same value if it is 0 or -0.
Returns NaN if x is neither.

@Math:round(x: num): num

Returns the nearest integer, rounded to the nearest whole number.

@Math:ceil(x: num): num

Returns the smallest integer greater than or equal to the argument.

@Math:floor(x: num): num

Returns the largest integer less than or equal to the argument.

@Math:trunc(x: num): num

Truncates the decimal portion of the argument and returns the integer portion. [x]

@Math:min(a: num, b: num): num

Returns the smaller value.

@Math:max(a: num, b: num): num

Returns the larger value.

@Math:sqrt(x: num): num

Computes the positive square root. x

@Math:cbrt(x: num): num

Calculate the cubic root. x3

@Math:hypot(vs: arr): num

Returns the positive square root of the sum of the elements of vs after squaring each of them. v12+v22++vn2

Trigonometric Functions

Hereafter, all angles are in radians.

@Math:sin(rad: num): num

Returns sine.

@Math:cos(rad: num): num

Returns cosine.

@Math:tan(rad: num): num

Returns tangent.

@Math:asin(x: num): num

Returns arcsine.

@Math:acos(x: num): num

Returns arccosine.

@Math:atan(x: num): num

Returns arctangent.

@Math:atan2(y: num, x: num): num

Returns the tangent of yx, but if x is negative, returns a value off by π.

Hyperbolic Functions

@Math:sinh(x: num): num

Returns hyperbolic sine.

@Math:cosh(x: num): num

Returns hyperbolic cosine.

@Math:tanh(x: num): num

Returns hyperbolic tangent.

@Math:asinh(x: num): num

Returns hyperbolic arcsine.

@Math:acosh(x: num): num

Returns hyperbolic arccosine.

@Math:atanh(x: num): num

Returns hyperbolic arctangent.

Exponential / Logarithmic Functions

@Math:pow(x: num, y: num): num

Returns the y power of x. Almost identical to Core:pow except that it internally uses the Math.pow function instead of Javascript's ** operator.

@Math:exp(x: num): num

Returns the x power of e.

@Math:expm1(x: num): num

Returns the x power of e minus 1.

@Math:log(x: num): num

Returns the natural logarithm. Use Math:log10 for the ordinary logarithm.

@Math:log1p(x: num): num

Returns the natural logarithm of x + 1.

@Math:log10(x: num): num

Returns the logarithm with 10 as the base (ordinary logarithm).

@Math:log2(x: num): num

Returns the logarithm with 2 as the base.

Random Generators

@Math:rnd(min?: num, max?: num): num

Generates random numbers.
If min and max are passed, integers with min <= x and x <= max are returned, otherwise decimals with 0 <= x and x < 1 are returned.

@Math:gen_rng(seed: num | str, options?: obj): @(min?: num, max?: num)

Generates a random number generator from the seed.
The generated random number generator returns an integer with min <= x, x <= max if min and max are passed,
If not passed, it returns a floating point number with 0 <= x, x < 1.
You can specify the internal behavior through the object passed to options.
The change in behavior by specifying options.algorithm is shown below:

options.algorithmInternal randomize algorhythmRange-specified integer generation algorithm
rc4RC4Rejection Sampling
rc4_legacyRC4Range limitation by floating-point arithmetic (pre-0.19.0 algorithm)
Not specified, or chacha20ChaCha20Rejection Sampling
aiscript
let rng = Math:gen_rng('AICHAN')

// Seed value is fixed, so under the same conditions,
// the same generation pattern will be generated each time.
<: rng(0, 10)
<: rng(0, 10)
<: rng(0, 10)

WARNING

Range-specified integer generation algorithms with floating-point arithmetic, such as rc4_legacy, may generate values larger than the specified max value due to rounding errors during arithmetic.

Misc.

@Math:clz32(x: num): num

Returns the number of leading zeros when x is represented in 32-bit binary.

@Math:fround(x: num): num

Returns the value when x is converted to a 32-bit floating-point number.

@Math:imul(x: num, y: num): num

Returns the result of a C-like 32-bit multiplication of x and y.