Class: Zakuro::Calculation::Type::OldFloat
- Inherits:
-
Object
- Object
- Zakuro::Calculation::Type::OldFloat
- Defined in:
- lib/zakuro/calculation/type/old_float.rb
Overview
Note:
四捨五入は常に絶対値に対して行う
-
value.negative? ? value.ceil : value.floor
-
絶対値だけを取り出すことで、四捨五入を平易にする
OldFloat 浮動小数点数(古代)
Instance Attribute Summary collapse
-
#abs ⇒ Float
readonly
絶対値.
-
#sign ⇒ Integer
readonly
符号.
Instance Method Summary collapse
-
#floor ⇒ Float
四捨五入する(非破壊的).
-
#floor! ⇒ Object
四捨五入する.
-
#get ⇒ Float
符号つき浮動小数点数を取得する.
-
#initialize(value) ⇒ OldFloat
constructor
初期化.
-
#negative? ⇒ True, False
負数かどうか.
Constructor Details
#initialize(value) ⇒ OldFloat
初期化
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
#abs ⇒ Float (readonly)
Returns 絶対値.
20 21 22 |
# File 'lib/zakuro/calculation/type/old_float.rb', line 20 def abs @abs end |
#sign ⇒ Integer (readonly)
Returns 符号.
18 19 20 |
# File 'lib/zakuro/calculation/type/old_float.rb', line 18 def sign @sign end |
Instance Method Details
#floor ⇒ 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 |
#get ⇒ Float
符号つき浮動小数点数を取得する
53 54 55 |
# File 'lib/zakuro/calculation/type/old_float.rb', line 53 def get sign * abs end |
#negative? ⇒ True, False
負数かどうか
63 64 65 |
# File 'lib/zakuro/calculation/type/old_float.rb', line 63 def negative? @sign == -1 end |