Skip to content

Numbers

Integer and Float are separate types. Arithmetic uses operands of the same type. Convert an integer with gale_std.integer.to_float when you need a float.

mod numbers
alias gale_std.integer
alias gale_std.number
pub fn add(left: Integer, right: Integer) -> Integer {
left + right
}
pub fn half(value: Float) -> Result<Float, number.ArithmeticError> {
gale_std.float.divide(value, 2.0)
}
pub fn from_int(value: Integer) -> Result<Float, number.ArithmeticError> {
integer.to_float(value)
}

Integers and floats support digit separators, such as 1_000 and 1_000.5. Use gale_std.integer.div and gale_std.integer.rem for integer division and remainder and handle their Result values. Float arithmetic uses gale_std.float.add, subtract, multiply, and divide, which return Result<Float, number.ArithmeticError>. Mixing integer and float operands is a type error:

pub fn mixed() -> Float {
1 + 1.0
}