Tin
Standard library · Numbers and math

On this page

Standard library

Numbers and math

int is 32-bit and checked: overflow is a panic, not a wrap. The Bits module has wrapping arithmetic.

Example

print(max(3, 7))
print(abs(-4))
print(sqrt(2.0).fixed(3))
print(pow(2.0, 10.0))
print(round(2.5) + floor(2.9))
print(1.compare(2))
7
4
1.414
1024.0
5.0
-1

All 31 symbols

min

fn min<T: Ord>(a: T, b: T): T

The smaller of two values (the Ord order). For floats NaN counts as largest, so min(NaN, 1.0) is 1.0.

max

fn max<T: Ord>(a: T, b: T): T

The larger of two values (the Ord order). For floats NaN counts as largest, so max(NaN, 1.0) is NaN.

int.compare

fn int.compare(a: int, b: int): int

No summary yet; the signature is the whole description.

i64.compare

fn i64.compare(a: i64, b: i64): int

No summary yet; the signature is the whole description.

float.compare

fn float.compare(a: float, b: float): int

A total order: NaN equals NaN and comes after every number; -0.0 equals 0.0.

string.compare

fn string.compare(a: string, b: string): int

No summary yet; the signature is the whole description.

Duration.compare

fn Duration.compare(a: Duration, b: Duration): int

No summary yet; the signature is the whole description.

Frequency.compare

fn Frequency.compare(a: Frequency, b: Frequency): int

No summary yet; the signature is the whole description.

Angle.compare

fn Angle.compare(a: Angle, b: Angle): int

No summary yet; the signature is the whole description.

Angle.rad

fn Angle.rad(a: Angle): float

The angle as a plain number of radians.

Angle.deg

fn Angle.deg(a: Angle): float

The angle as a plain number of degrees.

Angle.sin

fn Angle.sin(a: Angle): float

No summary yet; the signature is the whole description.

Angle.cos

fn Angle.cos(a: Angle): float

No summary yet; the signature is the whole description.

Angle.wrap

fn Angle.wrap(a: Angle): Angle

The angle wrapped into (-180deg, 180deg].

Angle.clamp

fn Angle.clamp(a: Angle, lo: Angle, hi: Angle): Angle

The angle limited to lo..hi.

abs

fn abs<T>(x: T): T

The absolute value of an int or a float.

sqrt

fn sqrt(x: float): float

The square root.

floor

fn floor(x: float): float

The largest whole number not above x.

ceil

fn ceil(x: float): float

The smallest whole number not below x.

round

fn round(x: float): float

The nearest whole number; halves round up.

pow

fn pow(base: float, exponent: float): float

`base` raised to `exponent`.

sin

fn sin(x: float): float

Sine of an angle in radians.

cos

fn cos(x: float): float

Cosine of an angle in radians.

tan

fn tan(x: float): float

Tangent of an angle in radians.

exp

fn exp(x: float): float

e raised to x.

ln

fn ln(x: float): float

The natural logarithm.

float.fixed

fn float.fixed(x: float, digits: int): string

x as text with exactly `digits` decimals: (3.14159).fixed(2) is "3.14".

float.bits

fn float.bits(x: float): i64

The IEEE 754 bits of x as an i64 (for writing a float out byte by byte); floatFromBits turns them back.

floatFromBits

fn floatFromBits(b: i64): float

The float whose IEEE 754 bits are b: floatFromBits(x.bits()) is x.

random

fn random(): float

A random float, at least 0 and below 1.

randomInt

fn randomInt(from: int, to: int): int

A random integer from `from` up to, but not including, `to`.

See also