std.number

abs : Number -> Number

Returns the absolute value of a number.

Examples

std.number.abs (-5) =>
  5
std.number.abs 42 =>
  42

floor : Number -> Number

Rounds a number down to the next integer.

Examples

std.number.floor 42.5 =>
  42
std.number.floor (-42.5) =>
  -43

fract : Number -> Number

Returns the fractional part of a number.

Examples

std.number.fract 13.37 =>
  0.37
std.number.fract 42 =>
  0

Integer

Enforces that a number is an integer.

Examples

(1.5 | Integer) =>
  error
(42 | Integer) =>
  42

is_integer : Number -> Bool

Checks if the given number is an integer.

Examples

std.number.is_integer 42 =>
  true
std.number.is_integer 1.5 =>
  false

max : Number -> Number -> Number

Returns the higher of two numbers.

Examples

std.number.max (-1337) 42 =>
  42

min : Number -> Number -> Number

Returns the lower of two numbers.

Examples

std.number.min (-1337) 42 =>
  -1337

Nat

Enforces that a number is a natural number (including 0).

Examples

(42 | std.number.Nat) =>
  42
(0 | std.number.Nat) =>
  0
(-4 | std.number.Nat) =>
  error

NonZero

Enforces that a number is not equal to zero.

Examples

(1 | std.number.NonZero) =>
  1
(0.0 | std.number.NonZero) =>
  error

PosNat

Enforces that a number is a strictly positive natural number.

Examples

(42 | std.number.PosNat) =>
  42
(0 | std.number.PosNat) =>
  error
(-4 | std.number.PosNat) =>
  error

pow : Number -> Number -> Number

pow x y returns x to the power of y.

Examples

std.number.pow 2 8 =>
  256

Precision

Nickel numbers are arbitrary precision rationals. If the exponent y is an integer which fits into a 64-bit signed or unsigned integer (that is, if y is an integer between −2^63 and 2^64-1), the result is computed exactly.

Otherwise, both operands x and y are converted to the nearest 64 bit float (excluding NaN and infinity) and the result is computed as a 64 bit float. This result is then converted back to a rational. In this case, be aware that both the conversion from rationals to floats, and the power operation, might incur rounding errors.


truncate : Number -> Number

Truncates a number, rounding it towards 0.

Examples

std.number.truncate (-13.37) =>
  -13
std.number.truncate 42.5 =>
  42