Modules · Core

Maths

Numbers and the arithmetic over them. The scalar primitives Maths.Real (a float) and Maths.Integer (a whole number) are framework values, like Text and Boolean; the composite types Vector2, Vector3, Vector4 and Quaternion group several reals together. Arithmetic is per type, not overloaded: Maths.Real.Add and Maths.Integer.Add are separate functions, and integer division truncates to a whole number while real division keeps the float. Each operation returns a reactive result that starts loading and settles on its own once its operands are ready, because a driver computes it asynchronously.

Contents

Functions

Functions

Maths.Integer.Add

Adds two integers, giving a whole-number result.

Parameters

NameTypeDescription
aMaths.IntegerThe first integer.
bMaths.IntegerThe second integer.

Returns

A reactive Maths.Integer, loading until its operands settle.

Example

const total = Maths.Integer.Add(2, 3);
A whole-number sum

Maths.Integer.Divide

Divides one integer by another, truncating the result to a whole number.

Parameters

NameTypeDescription
aMaths.IntegerThe dividend.
bMaths.IntegerThe divisor.

Returns

A reactive Maths.Integer; division truncates towards zero.

Example

const half = Maths.Integer.Divide(7, 2);
7 / 2 truncates to 3

Maths.Integer.FromReal

Narrows a real number to a whole number by truncating toward zero.

Parameters

NameTypeDescription
valueMaths.RealThe real number to narrow.

Returns

A reactive Maths.Integer; the fractional part is dropped by truncating towards zero.

Example

const whole = Maths.Integer.FromReal(3.7);
3.7 truncates to 3

Maths.Integer.Multiply

Multiplies two integers.

Parameters

NameTypeDescription
aMaths.IntegerThe first integer.
bMaths.IntegerThe second integer.

Returns

A reactive Maths.Integer, loading until its operands settle.

Example

const area = Maths.Integer.Multiply(4, 5);
A whole-number product

Maths.Integer.Subtract

Subtracts one integer from another.

Parameters

NameTypeDescription
aMaths.IntegerThe integer to subtract from.
bMaths.IntegerThe integer to subtract.

Returns

A reactive Maths.Integer, loading until its operands settle.

Example

const left = Maths.Integer.Subtract(10, 3);
10 minus 3

Maths.Integer.ToString

Turns an integer into text, so it can be shown with Content.Text.

Parameters

NameTypeDescription
valueMaths.IntegerThe integer to stringify.

Returns

A reactive Text.

Example

const count = Maths.Integer.Add(1, 1);
Content.Text(Maths.Integer.ToString(count));
Showing an integer as text

Maths.Real.Add

Adds two real numbers.

Parameters

NameTypeDescription
aMaths.RealThe first number.
bMaths.RealThe second number.

Returns

A reactive Maths.Real, loading until its operands settle.

Example

const sum = Maths.Real.Add(1.5, 2.25);
A real sum

Maths.Real.AtLeast

Compares two real numbers, giving a reactive boolean that is true while a is greater than or equal to b.

Parameters

NameTypeDescription
aMaths.RealThe number on the left of the comparison.
bMaths.RealThe number it must be at least.

Returns

A reactive Boolean, true while a is greater than or equal to b. This is a native boolean, the kind Reactive.If coerces and Logic.Select branches on, not a Logic.Maybe union.

Example

const ready = Maths.Real.AtLeast(progress, 1);
True once progress reaches 1

Maths.Real.Divide

Divides one real number by another, keeping the fractional part.

Parameters

NameTypeDescription
aMaths.RealThe dividend.
bMaths.RealThe divisor.

Returns

A reactive Maths.Real; the result keeps the float.

Example

const ratio = Maths.Real.Divide(7, 2);
7 / 2 keeps 3.5

Maths.Real.Floor

Rounds a real number down to the largest whole number not greater than it.

Parameters

NameTypeDescription
valueMaths.RealThe number to round down.

Returns

A reactive Maths.Real holding the largest whole number not greater than the value.

Example

const down = Maths.Real.Floor(3.7);
3.7 floors to 3

Maths.Real.Fract

Takes the fractional part of a real number, the value minus its floor, always in 0..1.

Parameters

NameTypeDescription
valueMaths.RealThe number to take the fractional part of.

Returns

A reactive Maths.Real, the value minus Floor(value), always in 0..1.

Example

const part = Maths.Real.Fract(3.7);
The fractional part, 0.7

Maths.Real.FromInteger

Widens an integer to a real, keeping the same numeric value.

Parameters

NameTypeDescription
valueMaths.IntegerThe integer to widen.

Returns

A reactive Maths.Real with the same numeric value, widened from an Maths.Integer.

Example

const real = Maths.Real.FromInteger(4);
The integer 4 as a real

Maths.Real.Multiply

Multiplies two real numbers.

Parameters

NameTypeDescription
aMaths.RealThe first number.
bMaths.RealThe second number.

Returns

A reactive Maths.Real, loading until its operands settle.

Example

const area = Maths.Real.Multiply(2.5, 4);
A real product

Maths.Real.Round

Rounds a real number to the nearest whole number, computed as Floor(value + 0.5).

Parameters

NameTypeDescription
valueMaths.RealThe number to round.

Returns

A reactive Maths.Real, the nearest whole number, computed as Floor(value + 0.5).

Example

const nearest = Maths.Real.Round(3.5);
3.5 rounds to 4

Maths.Real.Subtract

Subtracts one real number from another.

Parameters

NameTypeDescription
aMaths.RealThe number to subtract from.
bMaths.RealThe number to subtract.

Returns

A reactive Maths.Real, loading until its operands settle.

Example

const left = Maths.Real.Subtract(5.0, 1.5);
5 minus 1.5

Maths.Real.ToString

Turns a real number into text, so it can be shown with Content.Text.

Parameters

NameTypeDescription
valueMaths.RealThe number to stringify.

Returns

A reactive Text.

Example

const sum = Maths.Real.Add(1.5, 2.25);
Content.Text(Maths.Real.ToString(sum));
Showing a real value as text