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.
Source Code
lib/ttfunk/sci_form.rb, line 16
16 | def initialize(significand, exponent = 0) |
17 | @significand = significand |
18 | @exponent = exponent |
19 | end
|
Instance Attribute Details
#exponent ⇒ Float, Integer (readonly)
Exponent
Source Code
lib/ttfunk/sci_form.rb, line 12
12 | def exponent |
13 | @exponent
|
14 | end
|
#significand ⇒ Float, Integer (readonly)
Significand
Source Code
lib/ttfunk/sci_form.rb, line 8
8 | def significand |
9 | @significand
|
10 | end
|
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check equality to another number.
Source Code
lib/ttfunk/sci_form.rb, line 32
32 | def ==(other) |
33 | case other |
34 | when Float |
35 | other == to_f # rubocop: disable Lint/FloatComparison |
36 | when self.class |
37 | other.significand == significand && |
38 | other.exponent == exponent |
39 | else
|
40 | false
|
41 | end
|
42 | end
|
#to_f ⇒ Float
Convert to Float.
Source Code
lib/ttfunk/sci_form.rb, line 24
24 | def to_f |
25 | significand * (10**exponent) |
26 | end
|