t-nissieの日記: Ruby-1.9.0-0のComplex#cproj
Ruby-1.9.0-0の最も知られていない新機能のComplex#cprojですが、
現状:
#
# Projection of z onto the Riemann sphere
#
def cproj
if @real.infinite? or @image.infinite?
if @image>=0.0
Complex.new(1.0/0.0, 0.0)
else
Complex.new(1.0/0.0, -0.0)
end
else
self
end
end
より、これのほうがよいかなぁ:
#
# Projection of z onto the Riemann sphere
#
def cproj
if @real.infinite? or @image.infinite?
if @image==0.0
Complex.new(1.0/0.0, @image)
elsif @image>0.0
Complex.new(1.0/0.0, 0.0)
else
Complex.new(1.0/0.0, -0.0)
end
else
self
end
end
現状(gcc-4.3.0の実装はたぶんこっち):
$ ruby -r complex -e 'p Complex(1.0/0.0, 0.0).cproj'
Complex(Infinity, 0.0)
$ ruby -r complex -e 'p Complex(1.0/0.0,-0.0).cproj'
Complex(Infinity, 0.0)
上の変更後:
$ ruby -r complex -e 'p Complex(1.0/0.0, 0.0).cproj'
Complex(Infinity, 0.0)
$ ruby -r complex -e 'p Complex(1.0/0.0,-0.0).cproj'
Complex(Infinity, -0.0)
アレたまに掲載してみよう。
誰も読まないだろうし、どうでもよいことなんですが。
Ruby-1.9.0-0のComplex#cproj More ログイン