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
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
@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