Class: TTFunk::SciForm
- Inherits:
-
Object
- Object
- TTFunk::SciForm
- Defined in:
- lib/ttfunk/sci_form.rb
Overview
Scientific number representation
Instance Attribute Summary collapse
-
#exponent ⇒ Float, Integer
readonly
Exponent.
-
#significand ⇒ Float, Integer
readonly
Significand.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check equality to another number.
-
#initialize(significand, exponent = 0) ⇒ SciForm
constructor
A new instance of SciForm.
-
#to_f ⇒ Float
Convert to Float.
Constructor Details
#initialize(significand, exponent = 0) ⇒ SciForm
Returns a new instance of SciForm.
16 17 18 19 |
# File 'lib/ttfunk/sci_form.rb', line 16 def initialize(significand, exponent = 0) @significand = significand @exponent = exponent end |
Instance Attribute Details
#exponent ⇒ Float, Integer (readonly)
Exponent
12 13 14 |
# File 'lib/ttfunk/sci_form.rb', line 12 def exponent @exponent end |
#significand ⇒ Float, Integer (readonly)
Significand
8 9 10 |
# File 'lib/ttfunk/sci_form.rb', line 8 def significand @significand end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check equality to another number.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ttfunk/sci_form.rb', line 32 def ==(other) case other when Float other == to_f # rubocop: disable Lint/FloatComparison when self.class other.significand == significand && other.exponent == exponent else false end end |
#to_f ⇒ Float
Convert to Float.
24 25 26 |
# File 'lib/ttfunk/sci_form.rb', line 24 def to_f significand * (10**exponent) end |