[#40961] [Bug #3137] complex.rb changes exceptions of Math — Yusuke Endoh <redmine@...>

Bug #3137: complex.rb changes exceptions of Math

15 messages 2010/04/12
[#40967] Re: [Bug #3137] complex.rb changes exceptions of Math — keiju@... (石塚圭樹) 2010/04/13

けいじゅ@いしつかです.

[#41038] Windows と DL が使用条件の libffi — Aaron Patterson <aaron.patterson@...>

こんにちは!アーロンです。

17 messages 2010/04/22
[#41039] Re: Windows と DL が使用条件の libffi — "U.Nakamura" <usa@...> 2010/04/22

こんにちは、なかむら(う)です。

[#41040] Re: Windows と DL が使用条件の libffi — "NARUSE, Yui" <naruse@...> 2010/04/22

成瀬です。

[#41059] Re: Windows と DL が使用条件の libffi — Aaron Patterson <aaron.patterson@...> 2010/04/26

2010/4/21 NARUSE, Yui <naruse@airemix.jp>:

[#41060] Re: Windows と DL が使用条件の libffi — Yugui <yugui@...> 2010/04/26

2010/4/26 Aaron Patterson <aaron.patterson@gmail.com>:

[#41067] [Feature #3203] LazySweepGC patch — Narihiro Nakamura <redmine@...>

Feature #3203: LazySweepGC patch

15 messages 2010/04/26
[#41069] Re: [Feature #3203] LazySweepGC patch — Yusuke ENDOH <mame@...> 2010/04/27

遠藤です。

[#41104] Rails3 M17N — Yukihiro Matsumoto <matz@...>

まつもと ゆきひろです

29 messages 2010/04/30
[#41111] Re: Rails3 M17N — Urabe Shyouhei <shyouhei@...> 2010/04/30

Yukihiro Matsumoto =E3=81=95=E3=82=93=E3=81=AF=E6=9B=B8=E3=81=8D=E3=81=BE=

[#41113] Re: Rails3 M17N — Yukihiro Matsumoto <matz@...> 2010/04/30

まつもと ゆきひろです

[ruby-dev:40969] Re: [Bug #3137] complex.rb changes exceptions of Math

From: keiju@... (石塚圭樹)
Date: 2010-04-13 07:30:38 UTC
List: ruby-dev #40969
けいじゅ@いしつかです.

In [ruby-dev:40968] the message: "[ruby-dev:40968] Re: [Bug #3137]
complex.rb changes exceptions of Math", on Apr/13 15:19(JST) Yukihiro
Matsumoto writes:

>まつもと ゆきひろです

>|ただ, Complex#atanh等で, 
>|>  -e:1:in `atanh': can't convert nil into Float (TypeError)
>|という例外はふさわしくない気もします. Complex#atanhの実装を知らないと
>|わけの分からないエラーになっている気がしません? 

>そう? nil渡して「nilじゃダメ」と言われてるんだから明確でな
>いかと。「Floatでなくてもいいじゃん」ってことなんだと思うけ
>ど、そこは致命的ではないのでは。

実装案を見ると:

  def exp(z)
    begin
      if z.real?
	exp!(z)
      else
	ere = exp!(z.real)
	Complex(ere * cos!(z.imag),
		ere * sin!(z.imag))
      end
    rescue NoMethodError => exp
      if exp.name == :real?
	raise "error"
      end
      raise
    end
  end

こんな感じです. "error"のところの例外をどうするかって話で, ここで

>|>  -e:1:in `atanh': can't convert nil into Float (TypeError)

ちょっと分かりづらい例外かとおもったんですね.

あと, 

  def exp(z)
    begin
      if z.real?
	exp!(z)
      else
	ere = exp!(z.real)
	Complex(ere * cos!(z.imag),
		ere * sin!(z.imag))
      end
    rescue NoMethodError => exp
      if exp.name == :real?
	return exp(Float(z))
      end
      raise
    end
  end

はあるかなぁ... Numericとそのサブクラスしか, real? って持ってませんの
で, それ以外のクラスはMathと同じ振る舞いということで, Floatに変換して
試すはありかも. これだと, CMathの担当範囲外はMathと同じ結果になります.
ちょっと, くどい気がしなくもありませんが...


__
---------------------------------------------------->> 石塚 圭樹 <<---
---------------------------------->> e-mail: keiju@ishitsuka.com <<---

In This Thread