| id | stdlib-scalars |
|---|---|
| title | Int, Float, Bool Modules |
| slug | /stdlib/scalars |
Parses an invariant integer string.
let maybeN = Int.tryParse "42"Formats an integer using invariant formatting.
let text = Int.toString 42Parses an invariant floating-point string.
let maybePi = Float.tryParse "3.14"Formats a float using a round-trippable representation.
let text = Float.toString 3.14Parses true or false.
let maybeFlag = Bool.tryParse "true"Formats a boolean as lowercase text.
let text = Bool.toString trueUse parsing helpers with options:
let port =
Int.tryParse "8080"
|> Option.defaultValue 80Scalar 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 : int -> intReturns the absolute value. The minimum signed 64-bit integer raises an error because its positive value is out of range.
Int.abs (0 - 3)
// 3Int.sign : int -> intReturns -1, 0, or 1.
Int.sign (0 - 3)
// -1Int.min : int -> int -> intReturns the smaller value.
Int.min 2 3
// 2Int.max : int -> int -> intReturns the larger value.
Int.max 2 3
// 3Int.clamp : int -> int -> int -> intBounds the value inclusively. Reversed bounds raise an error.
Int.clamp 0 10 20
// 10Float.abs : float -> floatReturns the absolute value, propagating NaN.
Float.abs (0.0 - 3.0)
// 3Float.sign : float -> intReturns -1, 0, or 1. NaN raises an error.
Float.sign (0.0 - 3.0)
// -1Float.min : float -> float -> floatReturns the smaller value. Either NaN input produces NaN.
Float.min 2.0 3.0
// 2Float.max : float -> float -> floatReturns the larger value. Either NaN input produces NaN.
Float.max 2.0 3.0
// 3Float.clamp : float -> float -> float -> floatBounds the value inclusively. Reversed or NaN bounds raise an error; a NaN value produces NaN.
Float.clamp 0.0 10.0 20.0
// 10Float.floor : float -> floatRounds toward negative infinity; the result remains a float.
Float.floor 1.8
// 1Float.ceil : float -> floatRounds toward positive infinity; the result remains a float.
Float.ceil 1.2
// 2Float.round : float -> floatRounds to the nearest integer-valued float, with ties to even.
Float.round 2.5
// 2Float.truncate : float -> floatDiscards the fractional part toward zero; the result remains a float.
Float.truncate (0.0 - 1.8)
// -1Float.sqrt : float -> floatReturns the square root. Negative inputs produce NaN.
Float.sqrt 9.0
// 3Float.log : float -> floatReturns the natural logarithm. Zero produces negative infinity; negative inputs produce NaN.
Float.log 1.0
// 0Float.log10 : float -> floatReturns the base-10 logarithm. Zero produces negative infinity; negative inputs produce NaN.
Float.log10 100.0
// 2Float.exp : float -> floatReturns the natural exponential. Overflow produces positive infinity.
Float.exp 0.0
// 1Float.sin : float -> floatReturns the sine of an angle in radians.
Float.sin 0.0
// 0Float.cos : float -> floatReturns the cosine of an angle in radians.
Float.cos 0.0
// 1Float.tan : float -> floatReturns the tangent of an angle in radians.
Float.tan 0.0
// 0Float.asin : float -> floatReturns the inverse sine in radians. Inputs outside [-1, 1] produce NaN.
Float.asin 0.0
// 0Float.acos : float -> floatReturns the inverse cosine in radians. Inputs outside [-1, 1] produce NaN.
Float.acos 1.0
// 0Float.atan : float -> floatReturns the inverse tangent in radians.
Float.atan 0.0
// 0Float.pow : float -> float -> floatRaises the first argument to the power of the second.
Float.pow 2.0 3.0
// 8Float.atan2 : float -> float -> floatReturns the angle in radians for coordinates (y, x): the first argument is y, the second x.
Float.atan2 0.0 1.0
// 0Float.isNaN : float -> boolTests for NaN.
Float.isNaN (Float.sqrt (0.0 - 1.0))
// trueFloat.isInfinity : float -> boolTests for either positive or negative infinity.
Float.isInfinity (Float.exp 1000.0)
// trueFloat.isFinite : float -> boolTests that the value is neither NaN nor infinity.
Float.isFinite 1.0
// trueFloat.pi : floatThe double-precision constant π. This is a value, not a function.
Float.pi > 3.0 && Float.pi < 4.0
// trueInt.toFloat : int -> floatConverts an integer to a float. Values beyond the exact integer range of a double may lose precision.
Int.toFloat 3
// 3Float.tryToInt : float -> int optionTruncates 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