@head @module std @title Class std::Float @index Float @implements Comparable @supertypes

Instances of the Float class are floating-point numbers (floats). A float is an approximation of a real number, and can represent whole and fractional numbers, both small and large in magnitude. Internally Float objects are 64-bit IEEE double-precision floating-point numbers, with up to 15 significant digits of accuracy. @class Float(x) @desc Construct an object of the Float type. Call the _float() method of the argument and return a value equal to the result, provided that it is a float. Of the primitive types, Str and Int objects provide a _float method. String arguments may contain optional blank and tab characters before and after the number. Otherwise, the syntax of the string arguments must follow the Alore float literal syntax. @end

Operations

Float objects support the following operations (f below refers to a Float value): @op f + x @optype{Float + Float -> Float; Float + Int -> Float} @desc Perform a floating point addition operation. The right operand x may be an integer or a float; the result is a float. @end @op f + x @optype{Float + Addable -> T} @desc If x is neither an integer or a float, return x + n (switch operands). @end @op f * x @optype{Float * Float -> Float; Float * Int -> Float} @desc Perform a floating point multiplication operation. The right operand x may be an integer or a float; the result is a float. @end @op f * x @optype{Float * Multipliable -> T} @desc If x is neither an integer or a float, return x * n (switch operands). @end @op f - x @optype{Float - Float -> Float; Float - Int -> Float} @desc Perform a subtraction operation. The right operands x may be an integer or a float, and the result is a float. @end @op f / x @optype{Float / Float -> Float; Float / Int -> Float} @desc Perform a division operation. The right operands x may be an integer or a float, and the result is a float. @end @op f div x @optype{Float div Float -> Int; Float div Int -> Int} @desc Perform integer division. The result is f / x rounded down to the nearest integer represented as a float. The right operand x may be an integer or a float. @example 7.1 div 3.0 -- 2.0 -4.2 div 3.0 -- -2.0 @end @end @op f mod x @optype{Float mod Float -> Float; Float mod Int -> Float} @desc Perform the modulus operation. The result is chosen so that (f div x) * x + f mod x == f (the equality is only approximate due to the inexact nature of floating point numbers). The right operand x may be an integer or a float, and the result is a float. @end @op f ** x @optype{Float ** Float -> Float; Float ** Int -> Float} @desc Perform the exponentiation (power) operation. The right operand may be an integer or a float, and the result is a float. The operator follows the following rules in special conditions:

@end @op -f @optype{-Float -> Float} @desc Return the negation of a float. @end @op f == x @optype{Float == Object -> Boolean} @desc Floats can be compared for equality with arbitrary objects. A float object is equal to an equivalent float or integer value. If x is neither an integer nor a float, the operation is evaluated as x == f instead. @note The last property enables user-defined types to be compared with floats usefully. @end @end @op f < x @optype{Float < Float -> Boolean; Float < Int -> Boolean} @op f > x @optype{Float > Float -> Boolean; Float > Int -> Boolean} @desc Floats can be compared for order with floats and integers. If x is neither a float nor an integer, the operation is evaluated as x > f (for a < operation) or x < f (for a > operation). @note The last property allows user-defined types to be compared with floats usefully. @end @end @op Str(f) @desc Convert a float to a string. The result contains up to approximately 10 significant digits. @end @op Repr(f) @desc Convert a float to a string. The result contains up to approximately 16 significant digits. @end @op Int(f) @desc Convert a float to an integer, truncating any fraction. @end @op Hash(f) @desc Return the hash value of a float. @end