class Zakuro::Calculation::Type::OldFloat
OldFloat
浮動小数点数(古代)
@note 四捨五入は常に絶対値に対して行う
* value.negative? ? value.ceil : value.floor * 絶対値だけを取り出すことで、四捨五入を平易にする
Attributes
abs[R]
@return [Float] 絶対値
sign[R]
@return [Integer] 符号
Public Class Methods
new(value)
click to toggle source
初期化
@param [Float] value 符号つき浮動小数点数
# File lib/zakuro/calculation/type/old_float.rb, line 27 def initialize(value) @sign = value.negative? ? -1 : 1 @abs = @sign * value end
Public Instance Methods
floor()
click to toggle source
四捨五入する(非破壊的)
@return [Float] 絶対値
# File lib/zakuro/calculation/type/old_float.rb, line 44 def floor @abs.floor end
floor!()
click to toggle source
四捨五入する
# File lib/zakuro/calculation/type/old_float.rb, line 35 def floor! @abs = floor end
get()
click to toggle source
符号つき浮動小数点数を取得する
@return [Float] 符号つき浮動小数点数
# File lib/zakuro/calculation/type/old_float.rb, line 53 def get @sign * @abs end
negative?()
click to toggle source
負数かどうか
@return [True] 負数 @return [False] 正数
# File lib/zakuro/calculation/type/old_float.rb, line 63 def negative? @sign == -1 end