Skip to content

Math natives

IS4 edited this page Oct 9, 2022 · 6 revisions

math_random

native math_random(min=0, max=cellmax);

Returns a random signed integer between min and max (inclusive). The distribution is uniform.

math_random_unsigned

native math_random_unsigned(min=0, max=-1);

Returns a random unsigned integer between min and max (inclusive). The distribution is uniform.

math_random_float

native Float:math_random_float(Float:min=0.0, Float:max=1.0);

Returns a random floating point number between min and max (inclusive). The distribution is uniform.

math_random_seed

native math_random_seed(seed);

Configures the internal pseudo-random number generator with a new seed. Raises an error if the current generator is generator_random_device.

math_random_generator

native math_random_generator(random_generator:type);

Switches the (pseudo-)random number generator in use to the one identified by type. The state of the old generator will be preserved and used if it is switched back to. The default generator is generator_mt19937.

Rounding functions

native math_round(Float:val);
native math_floor(Float:val);
native math_ceiling(Float:val);
native math_truncate(Float:val);

Rounds a floating point number to the nearest integer. Raises a domain error if the number doesn't fit in a cell.

Signed arithmetic functions

native math_iadd({_,signed}:a, {_,signed}:b);
native math_isub({_,signed}:a, {_,signed}:b);
native math_imul({_,signed}:a, {_,signed}:b);
native math_idiv({_,signed}:a, {_,signed}:b);
native math_imod({_,signed}:a, {_,signed}:b);
native math_iinc({_,signed}:a);
native math_idec({_,signed}:a);

Performs a signed arithmetic operation on two signed values.

Signed arithmetic functions (checked)

native math_iadd_ovf({_,signed}:a, {_,signed}:b);
native math_isub_ovf({_,signed}:a, {_,signed}:b);
native math_imul_ovf({_,signed}:a, {_,signed}:b);
native math_iinc_ovf({_,signed}:a);
native math_idec_ovf({_,signed}:a);

Performs a signed arithmetic operation on two signed values. If the result does not fit in a single cell, raises a domain error.

Unsigned arithmetic functions

native math_uadd({_,unsigned}:a, {_,unsigned}:b);
native math_usub({_,unsigned}:a, {_,unsigned}:b);
native math_umul({_,unsigned}:a, {_,unsigned}:b);
native math_udiv({_,unsigned}:a, {_,unsigned}:b);
native math_umod({_,unsigned}:a, {_,unsigned}:b);
native math_uinc({_,unsigned}:a);
native math_udec({_,unsigned}:a);

Performs an unsigned arithmetic operation on two unsigned values.

Unsigned arithmetic functions (checked)

native math_uadd_ovf({_,unsigned}:a, {_,unsigned}:b);
native math_usub_ovf({_,unsigned}:a, {_,unsigned}:b);
native math_umul_ovf({_,unsigned}:a, {_,unsigned}:b);
native math_uinc_ovf({_,unsigned}:a);
native math_udec_ovf({_,unsigned}:a);

Performs an unsigned arithmetic operation on two unsigned values. If the result does not fit in a single cell, raises a domain error.

Comparison functions

native bool:math_ilt({_,signed}:a, {_,signed}:b);
native bool:math_ilte({_,signed}:a, {_,signed}:b);
native bool:math_igt({_,signed}:a, {_,signed}:b);
native bool:math_igte({_,signed}:a, {_,signed}:b);
native bool:math_ult({_,unsigned}:a, {_,unsigned}:b);
native bool:math_ulte({_,unsigned}:a, {_,unsigned}:b);
native bool:math_ugt({_,unsigned}:a, {_,unsigned}:b);
native bool:math_ugte({_,unsigned}:a, {_,unsigned}:b);

Compares two signed or two unsigned values.

Clone this wiki locally