Class: TTFunk::SciForm

Inherits:
Object
  • Object
show all
Defined in:
lib/ttfunk/sci_form.rb

Overview

Scientific number representation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(significand, exponent = 0) ⇒ SciForm

Returns a new instance of SciForm.

Parameters:

  • significand (Float, Integer)
  • exponent (Float, Integer) (defaults to: 0)
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

#exponentFloat, Integer (readonly)

Exponent

Returns:

  • (Float, Integer)
Source Code
lib/ttfunk/sci_form.rb, line 12
12
def exponent
13
  @exponent
14
end

#significandFloat, Integer (readonly)

Significand

Returns:

  • (Float, Integer)
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.

Parameters:

Returns:

  • (Boolean)
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_fFloat

Convert to Float.

Returns:

  • (Float)
Source Code
lib/ttfunk/sci_form.rb, line 24
24
def to_f
25
  significand * (10**exponent)
26
end