Modules · Core · Maths

Maths

Integer and real numbers, and their arithmetic. Maths gives you two native number types — Maths.Integer for whole numbers and Maths.Real for real (floating-point) numbers — each acting as a pseudo-module that also holds its operations. Every function is reactive: a sum or comparison recomputes whenever the values it reads change. Comparisons return a Logic.Maybe, so they compose with Logic.

Contents

Types

Functions

Types

Maths.Integer

A whole number, backed by each target's native integer type. It also groups the integer operations.

Definition

TYPE Maths.Integer
  NATIVE dart  "int"
  NATIVE swift "Int"
  NATIVE js    "Security.Integer"
  NATIVE go    "int64"
  NATIVE rust  "i64"
A native type: each target maps it to its own integer primitive.

Example

STATE Maths.Integer count = 0
A reactive integer cell starting at zero.

Maths.Real

A real (floating-point) number, backed by each target's native double type. It also groups the real-number operations.

Definition

TYPE Maths.Real
  NATIVE dart  "double"
  NATIVE swift "Double"
  NATIVE js    "Security.Number"
  NATIVE go    "float64"
  NATIVE rust  "f64"
A native type: each target maps it to its own floating-point primitive.

Example

STATE Maths.Real ratio = 0.5
A reactive real cell starting at one half.

Functions

Maths.Integer.Abs

The absolute value of an integer.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to take the magnitude of.

Returns

Returns Maths.Integer — the non-negative magnitude of value.

Maths.Integer.Add

Adds two integers.

Parameters

NameTypeDescription
aMaths.IntegerFirst addend.
bMaths.IntegerSecond addend.

Returns

Returns Maths.Integer — the sum of a and b.

Example

LET Maths.Integer total = Maths.Integer.Add price tax
Adds two integer values into a reactive total.

Maths.Integer.Clamp

Constrains a value to the min–max range.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to constrain.
minMaths.IntegerLower bound.
maxMaths.IntegerUpper bound.

Returns

Returns Maths.Integervalue pulled into the inclusive range minmax.

Maths.Integer.Decrement

One less than the value.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to decrease.

Returns

Returns Maths.Integervalue minus one.

Maths.Integer.Divide

Divides a by b, truncating toward zero.

Parameters

NameTypeDescription
aMaths.IntegerThe dividend.
bMaths.IntegerThe divisor.

Returns

Returns Maths.Integer — the quotient, truncated toward zero.

Maths.Integer.Equal

Yes when two integers are equal.

Parameters

NameTypeDescription
aMaths.IntegerFirst value.
bMaths.IntegerSecond value.

Returns

Returns Logic.Maybe — yes when a and b are equal.

Example

LET Logic.Maybe atLimit = Maths.Integer.Equal count 10
Yes once count reaches ten.

Maths.Integer.GreaterOrEqual

Yes when value is at or above the threshold.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to test.
thresholdMaths.IntegerThe bound to compare against.

Returns

Returns Logic.Maybe — yes when valuethreshold.

Maths.Integer.GreaterThan

Yes when value is above the threshold.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to test.
thresholdMaths.IntegerThe bound to compare against.

Returns

Returns Logic.Maybe — yes when value > threshold.

Maths.Integer.Increment

One more than the value.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to increase.

Returns

Returns Maths.Integervalue plus one.

Example

LET Maths.Integer next = Maths.Integer.Increment count
The value one above the current count.

Maths.Integer.Interpolate

The integer a fraction of the way from start to target.

Parameters

NameTypeDescription
startMaths.IntegerValue at progress 0.
targetMaths.IntegerValue at progress 1.
progressMaths.RealHow far between, 0 to 1.

Returns

Returns Maths.Integer — the rounded value progress of the way from start to target.

Maths.Integer.LessOrEqual

Yes when value is at or below the threshold.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to test.
thresholdMaths.IntegerThe bound to compare against.

Returns

Returns Logic.Maybe — yes when valuethreshold.

Maths.Integer.LessThan

Yes when value is below the threshold.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to test.
thresholdMaths.IntegerThe bound to compare against.

Returns

Returns Logic.Maybe — yes when value < threshold.

Maths.Integer.Max

The larger of two integers.

Parameters

NameTypeDescription
aMaths.IntegerFirst value.
bMaths.IntegerSecond value.

Returns

Returns Maths.Integer — whichever of a and b is larger.

Maths.Integer.Min

The smaller of two integers.

Parameters

NameTypeDescription
aMaths.IntegerFirst value.
bMaths.IntegerSecond value.

Returns

Returns Maths.Integer — whichever of a and b is smaller.

Maths.Integer.Modulo

The remainder of a divided by b.

Parameters

NameTypeDescription
aMaths.IntegerThe dividend.
bMaths.IntegerThe divisor.

Returns

Returns Maths.Integer — the remainder after dividing a by b.

Maths.Integer.Multiply

Multiplies two integers.

Parameters

NameTypeDescription
aMaths.IntegerFirst factor.
bMaths.IntegerSecond factor.

Returns

Returns Maths.Integer — the product of a and b.

Maths.Integer.NotEqual

Yes when two integers differ.

Parameters

NameTypeDescription
aMaths.IntegerFirst value.
bMaths.IntegerSecond value.

Returns

Returns Logic.Maybe — yes when a and b differ.

Maths.Integer.Option

Runs its block when its value matches the enclosing Select.

Parameters

NameTypeDescription
optionValueMaths.IntegerThe value this option matches.

Block

The content to run when optionValue equals the value selected by the enclosing Maths.Integer.Select.

Returns

Returns nothing — it runs its block only on a match.

Maths.Integer.Select

Opens a group that runs the matching Option for an integer value.

Parameters

NameTypeDescription
valueMaths.IntegerThe value the options are matched against.

Block

An indented block of Maths.Integer.Option entries; the one whose value equals value runs.

Returns

Returns nothing — it publishes value to the enclosed options over its block.

Example

Maths.Integer.Select choice
Maths.Integer.Option 1
  Ui.Content.Text "One"
Maths.Integer.Option 2
  Ui.Content.Text "Two"
Shows the block for whichever option matches choice.

Maths.Integer.Subtract

Subtracts b from a.

Parameters

NameTypeDescription
aMaths.IntegerThe value subtracted from.
bMaths.IntegerThe amount to subtract.

Returns

Returns Maths.Integera minus b.

Maths.Integer.ToDouble

The integer converted to a real number.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to convert.

Returns

Returns Maths.Realvalue as a real number.

Maths.Integer.ToString

The integer rendered as text.

Parameters

NameTypeDescription
valueMaths.IntegerThe value to render.

Returns

Returns Text — the decimal digits of value.

Maths.Real.Abs

The absolute value of a real number.

Parameters

NameTypeDescription
valueMaths.RealThe value to take the magnitude of.

Returns

Returns Maths.Real — the non-negative magnitude of value.

Maths.Real.Add

Adds two real numbers.

Parameters

NameTypeDescription
aMaths.RealFirst addend.
bMaths.RealSecond addend.

Returns

Returns Maths.Real — the sum of a and b.

Maths.Real.Ceil

The value rounded up to a whole number.

Parameters

NameTypeDescription
valueMaths.RealThe value to round up.

Returns

Returns Maths.Real — the smallest whole number not below value.

Maths.Real.Clamp

Constrains a real value to the min–max range.

Parameters

NameTypeDescription
valueMaths.RealThe value to constrain.
minMaths.RealLower bound.
maxMaths.RealUpper bound.

Returns

Returns Maths.Realvalue pulled into the inclusive range minmax.

Maths.Real.Cos

The cosine of an angle in radians.

Parameters

NameTypeDescription
radiansMaths.RealThe angle in radians.

Returns

Returns Maths.Real — the cosine of radians.

Maths.Real.Divide

Divides a by b.

Parameters

NameTypeDescription
aMaths.RealThe dividend.
bMaths.RealThe divisor.

Returns

Returns Maths.Real — the quotient of a over b.

Maths.Real.Ease

Shapes linear progress into an eased curve.

Parameters

NameTypeDescription
progressMaths.RealLinear progress, 0 to 1.
easeInMaths.RealStrength of the ease at the start.
easeOutMaths.RealStrength of the ease at the end.

Returns

Returns Maths.Real — the eased progress, useful for smoothing an animation.

Maths.Real.Floor

The value rounded down to a whole number.

Parameters

NameTypeDescription
valueMaths.RealThe value to round down.

Returns

Returns Maths.Real — the largest whole number not above value.

Maths.Real.GreaterOrEqual

Yes when value is at or above the threshold.

Parameters

NameTypeDescription
valueMaths.RealThe value to test.
thresholdMaths.RealThe bound to compare against.

Returns

Returns Logic.Maybe — yes when valuethreshold.

Maths.Real.GreaterThan

Yes when value is above the threshold.

Parameters

NameTypeDescription
valueMaths.RealThe value to test.
thresholdMaths.RealThe bound to compare against.

Returns

Returns Logic.Maybe — yes when value > threshold.

Maths.Real.Interpolate

The value a fraction of the way from start to target.

Parameters

NameTypeDescription
startMaths.RealValue at progress 0.
targetMaths.RealValue at progress 1.
progressMaths.RealHow far between, 0 to 1.

Returns

Returns Maths.Real — the value progress of the way from start to target.

Example

LET Maths.Real x = Maths.Real.Interpolate 0.0 100.0 progress
Moves x from 0 to 100 as progress runs 0 to 1.

Maths.Real.LessOrEqual

Yes when value is at or below the threshold.

Parameters

NameTypeDescription
valueMaths.RealThe value to test.
thresholdMaths.RealThe bound to compare against.

Returns

Returns Logic.Maybe — yes when valuethreshold.

Maths.Real.LessThan

Yes when value is below the threshold.

Parameters

NameTypeDescription
valueMaths.RealThe value to test.
thresholdMaths.RealThe bound to compare against.

Returns

Returns Logic.Maybe — yes when value < threshold.

Maths.Real.Max

The larger of two real numbers.

Parameters

NameTypeDescription
aMaths.RealFirst value.
bMaths.RealSecond value.

Returns

Returns Maths.Real — whichever of a and b is larger.

Maths.Real.Min

The smaller of two real numbers.

Parameters

NameTypeDescription
aMaths.RealFirst value.
bMaths.RealSecond value.

Returns

Returns Maths.Real — whichever of a and b is smaller.

Maths.Real.Multiply

Multiplies two real numbers.

Parameters

NameTypeDescription
aMaths.RealFirst factor.
bMaths.RealSecond factor.

Returns

Returns Maths.Real — the product of a and b.

Maths.Real.Pow

Raises a to the power of b.

Parameters

NameTypeDescription
aMaths.RealThe base.
bMaths.RealThe exponent.

Returns

Returns Maths.Reala raised to the power b.

Maths.Real.Round

The value rounded to the nearest whole number.

Parameters

NameTypeDescription
valueMaths.RealThe value to round.

Returns

Returns Maths.Realvalue rounded to the nearest whole number.

Maths.Real.Sin

The sine of an angle in radians.

Parameters

NameTypeDescription
radiansMaths.RealThe angle in radians.

Returns

Returns Maths.Real — the sine of radians.

Maths.Real.Sqrt

The square root of a real number.

Parameters

NameTypeDescription
valueMaths.RealThe value to take the root of.

Returns

Returns Maths.Real — the square root of value.

Maths.Real.Subtract

Subtracts b from a.

Parameters

NameTypeDescription
aMaths.RealThe value subtracted from.
bMaths.RealThe amount to subtract.

Returns

Returns Maths.Reala minus b.

Maths.Real.ToInteger

The real number converted to an integer, dropping any fraction.

Parameters

NameTypeDescription
valueMaths.RealThe value to convert.

Returns

Returns Maths.Integervalue with its fractional part dropped.

Maths.Real.ToString

The real number rendered as text.

Parameters

NameTypeDescription
valueMaths.RealThe value to render.

Returns

Returns Text — a textual form of value.