Class: Zakuro::Calculation::Type::OldFloat

Inherits:
Object
  • Object
show all
Defined in:
lib/zakuro/calculation/type/old_float.rb

Overview

Note:

四捨五入は常に絶対値に対して行う

  • value.negative? ? value.ceil : value.floor

  • 絶対値だけを取り出すことで、四捨五入を平易にする

OldFloat 浮動小数点数(古代)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ OldFloat

初期化

Parameters:

  • value (Float)

    符号つき浮動小数点数



27
28
29
30
# File 'lib/zakuro/calculation/type/old_float.rb', line 27

def initialize(value)
  @sign = value.negative? ? -1 : 1
  @abs = @sign * value
end

Instance Attribute Details

#absFloat (readonly)

Returns 絶対値.

Returns:

  • (Float)

    絶対値



20
21
22
# File 'lib/zakuro/calculation/type/old_float.rb', line 20

def abs
  @abs
end

#signInteger (readonly)

Returns 符号.

Returns:

  • (Integer)

    符号



18
19
20
# File 'lib/zakuro/calculation/type/old_float.rb', line 18

def sign
  @sign
end

Instance Method Details

#floorFloat

四捨五入する(非破壊的)

Returns:

  • (Float)

    絶対値



44
45
46
# File 'lib/zakuro/calculation/type/old_float.rb', line 44

def floor
  abs.floor
end

#floor!Object

四捨五入する



35
36
37
# File 'lib/zakuro/calculation/type/old_float.rb', line 35

def floor!
  @abs = floor
end

#getFloat

符号つき浮動小数点数を取得する

Returns:

  • (Float)

    符号つき浮動小数点数



53
54
55
# File 'lib/zakuro/calculation/type/old_float.rb', line 53

def get
  sign * abs
end

#negative?True, False

負数かどうか

Returns:

  • (True)

    負数

  • (False)

    正数



63
64
65
# File 'lib/zakuro/calculation/type/old_float.rb', line 63

def negative?
  @sign == -1
end