たけ(tk)です
複素数の四捨五入という概念はないのでしょうか?
## Complex#to_f should return Float (TypeError)
##G:\Apollo\TkUtils\Numeric_round_to.rb:32:in `round'
----
#! ruby -Ks
#-- Complex_round.rb
require "complex"
class Complex
def round
Complex(self.real.round,self.image.round)
end
def floor
Complex(self.real.floor,self.image.floor)
end
def ceil
Complex(self.real.ceil,self.image.ceil)
end
require "Numeric_bankers_round"
def bankers_round
Complex(self.real.bankers_round,self.image.bankers_round)
end
end
if __FILE__ == $0
require "Numeric_round_to"
p Complex(2.200000048,1.799999952).round_to(-4) #=> Complex(2.2, 1.8)
p Complex(2.200000048,1.799999952).floor_to(-4) #=> Complex(2.2, 1.7999)
p Complex(2.200000048,1.799999952).ceil_to(-4) #=> Complex(2.2001, 1.8)
p Complex(2.200000048,1.799999952).bankers_round_to(-4) #=> Complex(2.2001, 1.8)
end
----
Take_tk = KUMAGAI Hidetake
たけ(tk)=熊谷秀武