abstract struct Float
- Float
- Number
- Value
- Object
Overview
Float is the base type of all floating point numbers.
There are two floating point types, Float32 and Float64,
which correspond to the binary32
and binary64
types defined by IEEE.
A floating point literal is an optional #+ or - sign, followed by
a sequence of numbers or underscores, followed by a dot,
followed by numbers or underscores, followed by an optional exponent suffix,
followed by an optional type suffix. If no suffix is present, the literal's type is Float64.
1.0 # Float64
1.0_f32 # Float32
1_f32 # Float32
1e10 # Float64
1.5e10 # Float64
1.5e-7 # Float64
+1.3 # Float64
-0.5 # Float64
The underscore _ before the suffix is optional.
Underscores can be used to make some numbers more readable:
1_000_000.111_111 # better than 1000000.111111
See Float literals in the language reference.
Included Modules
- Comparable(Float)
Defined in:
crystalg/geometry/extensions.crInstance Method Summary
- #+(other : Float)
-
#<=>(other : Float)
The comparison operator.
- #===(other : Float)
-
#sign : Int
Returns the sign of this number as an
Int32. - #sqrt
Instance Method Detail
The comparison operator. Returns 0 if the two objects are equal,
a negative number if this object is considered less than other,
a positive number if this object is considered greater than other,
or nil if the two objects are not comparable.
Subclasses define this method to provide class-specific ordering.
The comparison operator is usually used to sort values:
# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]
# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]
Returns the sign of this number as an Int32.
-1if this number is negative0if this number is zero1if this number is positive
123.sign # => 1
0.sign # => 0
-42.sign # => -1