パスワードを忘れた? アカウント作成
17159 journal

t-nissieの日記: Ruby-1.9.0-0のComplex#cproj

日記 by t-nissie

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)

アレたまに掲載してみよう。
誰も読まないだろうし、どうでもよいことなんですが。

この議論は賞味期限が切れたので、アーカイブ化されています。 新たにコメントを付けることはできません。
typodupeerror

犯人はmoriwaka -- Anonymous Coward

読み込み中...