abstract struct Number
- Number
- Value
- Object
Overview
The top-level number type.
Included Modules
- Comparable(Number)
- Steppable
Direct Known Subclasses
Defined in:
chem/core_ext/number.crConstant Summary
-
DEGREE_TO_RADIAN =
Math::PI / 180
-
RADIAN_TO_DEGREE =
180 / Math::PI
Instance Method Summary
- #*(other : Chem::Spatial::Vec3) : Chem::Spatial::Vec3
-
#close_to?(rhs : Number, delta : Number = 0) : Bool
Returns
true
if numbers are within delta from each other, elsefalse
. - #degree
- #degrees
- #radian
- #radians
-
#scale(min : Number, max : Number) : Float64
Scales the number into the given range.
-
#scale(range : Range(Number, Number)) : Float64
Scales the number into the given range.
-
#unscale(min : Number, max : Number) : Float64
Reverts the scaling in the given range.
-
#unscale(range : Range(Number, Number)) : Float64
Reverts the scaling in the given range.
Instance Method Detail
Returns true
if numbers are within delta from each other, else
false
.
1.0.close_to?(1.0) # => true
1.0_f32.close_to?(1.0) # => true
1.0.close_to?(1.0 + Float64::EPSILON) # => true
1.0_f32.close_to?(1.0 + Float32::EPSILON) # => true
1.0.close_to?(1.0005, 1e-3) # => true
1.0.close_to?(1.0 + Float64::EPSILON*2) # => false
1.0_f32.close_to?(1.0 + Float32::EPSILON*2) # => false
1.0.close_to?(1.01, 1e-3) # => false
Scales the number into the given range. The result will be between zero and one.
10.scale(0, 100) # => 0.1
2.5.scale(0, 5) # 0.5
401.scale(50, 500) # => 0.78
Scales the number into the given range. The result will be between zero and one.
10.scale(0, 100) # => 0.1
2.5.scale(0, 5) # 0.5
401.scale(50, 500) # => 0.78
Reverts the scaling in the given range.
0.5.unscale(0, 100) # => 50.0 0.1.unscale(0, 5) # => 0.05 5.scale(-4, 20).unscale(-4, 20) # => 5.0
Reverts the scaling in the given range.
0.5.unscale(0, 100) # => 50.0 0.1.unscale(0, 5) # => 0.05 5.scale(-4, 20).unscale(-4, 20) # => 5.0