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
- Maths.Integer.Abs
- Maths.Integer.Add
- Maths.Integer.Clamp
- Maths.Integer.Decrement
- Maths.Integer.Divide
- Maths.Integer.Equal
- Maths.Integer.GreaterOrEqual
- Maths.Integer.GreaterThan
- Maths.Integer.Increment
- Maths.Integer.Interpolate
- Maths.Integer.LessOrEqual
- Maths.Integer.LessThan
- Maths.Integer.Max
- Maths.Integer.Min
- Maths.Integer.Modulo
- Maths.Integer.Multiply
- Maths.Integer.NotEqual
- Maths.Integer.Option
- Maths.Integer.Select
- Maths.Integer.Subtract
- Maths.Integer.ToDouble
- Maths.Integer.ToString
- Maths.Real.Abs
- Maths.Real.Add
- Maths.Real.Ceil
- Maths.Real.Clamp
- Maths.Real.Cos
- Maths.Real.Divide
- Maths.Real.Ease
- Maths.Real.Floor
- Maths.Real.GreaterOrEqual
- Maths.Real.GreaterThan
- Maths.Real.Interpolate
- Maths.Real.LessOrEqual
- Maths.Real.LessThan
- Maths.Real.Max
- Maths.Real.Min
- Maths.Real.Multiply
- Maths.Real.Pow
- Maths.Real.Round
- Maths.Real.Sin
- Maths.Real.Sqrt
- Maths.Real.Subtract
- Maths.Real.ToInteger
- Maths.Real.ToString
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"Example
STATE Maths.Integer count = 0Maths.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"Example
STATE Maths.Real ratio = 0.5Functions
Maths.Integer.Abs
The absolute value of an integer.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to take the magnitude of. |
Returns
Returns Maths.Integer — the non-negative magnitude of value.
Maths.Integer.Add
Adds two integers.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Integer | First addend. |
b | Maths.Integer | Second addend. |
Returns
Returns Maths.Integer — the sum of a and b.
Example
LET Maths.Integer total = Maths.Integer.Add price taxMaths.Integer.Clamp
Constrains a value to the min–max range.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to constrain. |
min | Maths.Integer | Lower bound. |
max | Maths.Integer | Upper bound. |
Returns
Returns Maths.Integer — value pulled into the inclusive range min…max.
Maths.Integer.Decrement
One less than the value.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to decrease. |
Returns
Returns Maths.Integer — value minus one.
Maths.Integer.Divide
Divides a by b, truncating toward zero.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Integer | The dividend. |
b | Maths.Integer | The divisor. |
Returns
Returns Maths.Integer — the quotient, truncated toward zero.
Maths.Integer.Equal
Yes when two integers are equal.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Integer | First value. |
b | Maths.Integer | Second value. |
Returns
Returns Logic.Maybe — yes when a and b are equal.
Example
LET Logic.Maybe atLimit = Maths.Integer.Equal count 10count reaches ten.Maths.Integer.GreaterOrEqual
Yes when value is at or above the threshold.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to test. |
threshold | Maths.Integer | The bound to compare against. |
Returns
Returns Logic.Maybe — yes when value ≥ threshold.
Maths.Integer.GreaterThan
Yes when value is above the threshold.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to test. |
threshold | Maths.Integer | The bound to compare against. |
Returns
Returns Logic.Maybe — yes when value > threshold.
Maths.Integer.Increment
One more than the value.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to increase. |
Returns
Returns Maths.Integer — value plus one.
Example
LET Maths.Integer next = Maths.Integer.Increment countMaths.Integer.Interpolate
The integer a fraction of the way from start to target.
Parameters
| Name | Type | Description |
|---|---|---|
start | Maths.Integer | Value at progress 0. |
target | Maths.Integer | Value at progress 1. |
progress | Maths.Real | How 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
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to test. |
threshold | Maths.Integer | The bound to compare against. |
Returns
Returns Logic.Maybe — yes when value ≤ threshold.
Maths.Integer.LessThan
Yes when value is below the threshold.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to test. |
threshold | Maths.Integer | The bound to compare against. |
Returns
Returns Logic.Maybe — yes when value < threshold.
Maths.Integer.Max
The larger of two integers.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Integer | First value. |
b | Maths.Integer | Second value. |
Returns
Returns Maths.Integer — whichever of a and b is larger.
Maths.Integer.Min
The smaller of two integers.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Integer | First value. |
b | Maths.Integer | Second value. |
Returns
Returns Maths.Integer — whichever of a and b is smaller.
Maths.Integer.Modulo
The remainder of a divided by b.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Integer | The dividend. |
b | Maths.Integer | The divisor. |
Returns
Returns Maths.Integer — the remainder after dividing a by b.
Maths.Integer.Multiply
Multiplies two integers.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Integer | First factor. |
b | Maths.Integer | Second factor. |
Returns
Returns Maths.Integer — the product of a and b.
Maths.Integer.NotEqual
Yes when two integers differ.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Integer | First value. |
b | Maths.Integer | Second 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
| Name | Type | Description |
|---|---|---|
optionValue | Maths.Integer | The 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
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The 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"choice.Maths.Integer.Subtract
Subtracts b from a.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Integer | The value subtracted from. |
b | Maths.Integer | The amount to subtract. |
Returns
Returns Maths.Integer — a minus b.
Maths.Integer.ToDouble
The integer converted to a real number.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to convert. |
Returns
Returns Maths.Real — value as a real number.
Maths.Integer.ToString
The integer rendered as text.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Integer | The value to render. |
Returns
Returns Text — the decimal digits of value.
Maths.Real.Abs
The absolute value of a real number.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to take the magnitude of. |
Returns
Returns Maths.Real — the non-negative magnitude of value.
Maths.Real.Add
Adds two real numbers.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Real | First addend. |
b | Maths.Real | Second addend. |
Returns
Returns Maths.Real — the sum of a and b.
Maths.Real.Ceil
The value rounded up to a whole number.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The 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
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to constrain. |
min | Maths.Real | Lower bound. |
max | Maths.Real | Upper bound. |
Returns
Returns Maths.Real — value pulled into the inclusive range min…max.
Maths.Real.Cos
The cosine of an angle in radians.
Parameters
| Name | Type | Description |
|---|---|---|
radians | Maths.Real | The angle in radians. |
Returns
Returns Maths.Real — the cosine of radians.
Maths.Real.Divide
Divides a by b.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Real | The dividend. |
b | Maths.Real | The divisor. |
Returns
Returns Maths.Real — the quotient of a over b.
Maths.Real.Ease
Shapes linear progress into an eased curve.
Parameters
| Name | Type | Description |
|---|---|---|
progress | Maths.Real | Linear progress, 0 to 1. |
easeIn | Maths.Real | Strength of the ease at the start. |
easeOut | Maths.Real | Strength 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
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The 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
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to test. |
threshold | Maths.Real | The bound to compare against. |
Returns
Returns Logic.Maybe — yes when value ≥ threshold.
Maths.Real.GreaterThan
Yes when value is above the threshold.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to test. |
threshold | Maths.Real | The 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
| Name | Type | Description |
|---|---|---|
start | Maths.Real | Value at progress 0. |
target | Maths.Real | Value at progress 1. |
progress | Maths.Real | How 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 progressx from 0 to 100 as progress runs 0 to 1.Maths.Real.LessOrEqual
Yes when value is at or below the threshold.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to test. |
threshold | Maths.Real | The bound to compare against. |
Returns
Returns Logic.Maybe — yes when value ≤ threshold.
Maths.Real.LessThan
Yes when value is below the threshold.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to test. |
threshold | Maths.Real | The bound to compare against. |
Returns
Returns Logic.Maybe — yes when value < threshold.
Maths.Real.Max
The larger of two real numbers.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Real | First value. |
b | Maths.Real | Second value. |
Returns
Returns Maths.Real — whichever of a and b is larger.
Maths.Real.Min
The smaller of two real numbers.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Real | First value. |
b | Maths.Real | Second value. |
Returns
Returns Maths.Real — whichever of a and b is smaller.
Maths.Real.Multiply
Multiplies two real numbers.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Real | First factor. |
b | Maths.Real | Second factor. |
Returns
Returns Maths.Real — the product of a and b.
Maths.Real.Pow
Raises a to the power of b.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Real | The base. |
b | Maths.Real | The exponent. |
Returns
Returns Maths.Real — a raised to the power b.
Maths.Real.Round
The value rounded to the nearest whole number.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to round. |
Returns
Returns Maths.Real — value rounded to the nearest whole number.
Maths.Real.Sin
The sine of an angle in radians.
Parameters
| Name | Type | Description |
|---|---|---|
radians | Maths.Real | The angle in radians. |
Returns
Returns Maths.Real — the sine of radians.
Maths.Real.Sqrt
The square root of a real number.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to take the root of. |
Returns
Returns Maths.Real — the square root of value.
Maths.Real.Subtract
Subtracts b from a.
Parameters
| Name | Type | Description |
|---|---|---|
a | Maths.Real | The value subtracted from. |
b | Maths.Real | The amount to subtract. |
Returns
Returns Maths.Real — a minus b.
Maths.Real.ToInteger
The real number converted to an integer, dropping any fraction.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to convert. |
Returns
Returns Maths.Integer — value with its fractional part dropped.
Maths.Real.ToString
The real number rendered as text.
Parameters
| Name | Type | Description |
|---|---|---|
value | Maths.Real | The value to render. |
Returns
Returns Text — a textual form of value.