Skip to main content
Version: Next

Int, Float, Bool Modules

Hosted interpreter permissions: Every function and value on this page requires no host permissions. Higher-order functions still enforce the requirements of their callbacks. These checks do not apply to CLI execution or compilation. See Host permissions.

Int​

Int.tryParse : string -> int option​

None

Parses an invariant integer string.

let maybeN = Int.tryParse "42"

Int.toString : int -> string​

None

Formats an integer using invariant formatting.

let text = Int.toString 42

Float​

Float.tryParse : string -> float option​

None

Parses an invariant floating-point string.

let maybePi = Float.tryParse "3.14"

Float.toString : float -> string​

None

Formats a float using a round-trippable representation.

let text = Float.toString 3.14

Bool​

Bool.tryParse : string -> bool option​

None

Parses true or false.

let maybeFlag = Bool.tryParse "true"

Bool.toString : bool -> string​

None

Formats a boolean as lowercase text.

let text = Bool.toString true

Parsing pattern​

Use parsing helpers with options:

let port =
Int.tryParse "8080"
|> Option.defaultValue 80

Pure support additions​

Scalar math uses signed 64-bit integers and IEEE-754 doubles. Transcendental functions follow the host math library; last-bit results may differ across platforms, so they are not a portable bitwise cache-key format. Invalid floating math domains generally produce NaN/infinity as specified below.

Int.abs​

None
Int.abs : int -> int

Returns the absolute value. The minimum signed 64-bit integer raises an error because its positive value is out of range.

Int.abs (0 - 3)
// 3

Int.sign​

None
Int.sign : int -> int

Returns -1, 0, or 1.

Int.sign (0 - 3)
// -1

Int.min​

None
Int.min : int -> int -> int

Returns the smaller value.

Int.min 2 3
// 2

Int.max​

None
Int.max : int -> int -> int

Returns the larger value.

Int.max 2 3
// 3

Int.clamp​

None
Int.clamp : int -> int -> int -> int

Bounds the value inclusively. Reversed bounds raise an error.

Int.clamp 0 10 20
// 10

Float.abs​

None
Float.abs : float -> float

Returns the absolute value, propagating NaN.

Float.abs (0.0 - 3.0)
// 3

Float.sign​

None
Float.sign : float -> int

Returns -1, 0, or 1. NaN raises an error.

Float.sign (0.0 - 3.0)
// -1

Float.min​

None
Float.min : float -> float -> float

Returns the smaller value. Either NaN input produces NaN.

Float.min 2.0 3.0
// 2

Float.max​

None
Float.max : float -> float -> float

Returns the larger value. Either NaN input produces NaN.

Float.max 2.0 3.0
// 3

Float.clamp​

None
Float.clamp : float -> float -> float -> float

Bounds the value inclusively. Reversed or NaN bounds raise an error; a NaN value produces NaN.

Float.clamp 0.0 10.0 20.0
// 10

Float.floor​

None
Float.floor : float -> float

Rounds toward negative infinity; the result remains a float.

Float.floor 1.8
// 1

Float.ceil​

None
Float.ceil : float -> float

Rounds toward positive infinity; the result remains a float.

Float.ceil 1.2
// 2

Float.round​

None
Float.round : float -> float

Rounds to the nearest integer-valued float, with ties to even.

Float.round 2.5
// 2

Float.truncate​

None
Float.truncate : float -> float

Discards the fractional part toward zero; the result remains a float.

Float.truncate (0.0 - 1.8)
// -1

Float.sqrt​

None
Float.sqrt : float -> float

Returns the square root. Negative inputs produce NaN.

Float.sqrt 9.0
// 3

Float.log​

None
Float.log : float -> float

Returns the natural logarithm. Zero produces negative infinity; negative inputs produce NaN.

Float.log 1.0
// 0

Float.log10​

None
Float.log10 : float -> float

Returns the base-10 logarithm. Zero produces negative infinity; negative inputs produce NaN.

Float.log10 100.0
// 2

Float.exp​

None
Float.exp : float -> float

Returns the natural exponential. Overflow produces positive infinity.

Float.exp 0.0
// 1

Float.sin​

None
Float.sin : float -> float

Returns the sine of an angle in radians.

Float.sin 0.0
// 0

Float.cos​

None
Float.cos : float -> float

Returns the cosine of an angle in radians.

Float.cos 0.0
// 1

Float.tan​

None
Float.tan : float -> float

Returns the tangent of an angle in radians.

Float.tan 0.0
// 0

Float.asin​

None
Float.asin : float -> float

Returns the inverse sine in radians. Inputs outside [-1, 1] produce NaN.

Float.asin 0.0
// 0

Float.acos​

None
Float.acos : float -> float

Returns the inverse cosine in radians. Inputs outside [-1, 1] produce NaN.

Float.acos 1.0
// 0

Float.atan​

None
Float.atan : float -> float

Returns the inverse tangent in radians.

Float.atan 0.0
// 0

Float.pow​

None
Float.pow : float -> float -> float

Raises the first argument to the power of the second.

Float.pow 2.0 3.0
// 8

Float.atan2​

None
Float.atan2 : float -> float -> float

Returns the angle in radians for coordinates (y, x): the first argument is y, the second x.

Float.atan2 0.0 1.0
// 0

Float.isNaN​

None
Float.isNaN : float -> bool

Tests for NaN.

Float.isNaN (Float.sqrt (0.0 - 1.0))
// true

Float.isInfinity​

None
Float.isInfinity : float -> bool

Tests for either positive or negative infinity.

Float.isInfinity (Float.exp 1000.0)
// true

Float.isFinite​

None
Float.isFinite : float -> bool

Tests that the value is neither NaN nor infinity.

Float.isFinite 1.0
// true

Float.pi​

None
Float.pi : float

The double-precision constant π. This is a value, not a function.

Float.pi > 3.0 && Float.pi < 4.0
// true

Int.toFloat​

None
Int.toFloat : int -> float

Converts an integer to a float. Values beyond the exact integer range of a double may lose precision.

Int.toFloat 3
// 3

Float.tryToInt​

None
Float.tryToInt : float -> int option

Truncates toward zero and returns Some int. NaN, infinity, or an input outside [-2^63, 2^63) returns None.

Float.tryToInt (0.0 - 2.9)
// Some -2