std.number

abs : Number -> Number

Returns the absolute value of a number.

Examples

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

std.number.abs 42
# => 42

arccos : Number -> Number

arccos x returns the arccosinus of x.

Examples

std.number.arccos 0
# => 1.570796326794897

std.number.arccos 1
# => 0

arcsin : Number -> Number

arcsin x returns the arccsinus of x.

Examples

std.number.arcsin 0
# => 0

std.number.arcsin 1
# => 1.570796326794897

arctan : Number -> Number

arctan x returns the arctangent of x.

Examples

std.number.arctan 1
# => 0.7853981633974482

arctan2 : Number -> Number -> Number

`arctan2 y x returns the four quadrant arctangent of y over x.

Examples

std.number.arctan2 1 0
# => 1.570796326794897

std.number.arctan2 (-0.5) (-0.5)
# => -2.356194490192345

compare : Number -> Number -> [| 'Lesser, 'Equal, 'Greater |]

Compares two numbers.

Examples

std.number.compare 1 2
# => 'Lesser

cos : Number -> Number

cos x returns the cosinus of x.

Examples

std.number.cos (std.number.pi / 4)
# => 0.70710678118

e : Number

Euler's number, the e mathematical constant.


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

log : Number -> Number -> Number

log x base returns the logarithm of x with respect to the given base.

Examples

std.number.log 2 1024
# => 10

std.number.log 100 10
# => 2

std.number.log 10 std.number.e
# => 2.302585

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

pi : Number

The π mathematical constant.


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.


sin : Number -> Number

sin x returns the sinus of x.

Examples

std.number.sin (std.number.pi / 2)
# => 1

sqrt : Number -> Number

sqrt x return the square root of x.

Examples

std.number.sqrt 4
# => 2

tan : Number -> Number

tan x returns the tangent of x.

Examples

std.number.tan (std.number.pi / 4)
# => 1

truncate : Number -> Number

Truncates a number, rounding it towards 0.

Examples

std.number.truncate (-13.37)
# => -13

std.number.truncate 42.5
# => 42