From: WATANABE Hirofumi Date: 2001-03-07T13:54:11+09:00 Subject: [ruby-dev:12385] Re: NaN, Infinity (Bug?) わたなべです。 ちと調べてみました。 GOTO Kentaro writes: :In message "[ruby-talk:12132] Re: NaN, Infinity (Bug?)" : on 01/03/06, Dave Thomas writes: :>I just ran this again on my box here (ruby 1.6.2 (2001-02-02) [i686-linux]): :> :> a = -1.0 # => -1.0 :> a.nan? # => false :> a = Math.log(a) # => NaN :> a.nan? # => true :> :>So, there seems to be a difference between a Linux box and a :>Windows/cygwin box. Anyone any ideas? : :I ran: : : #include : main(){printf("%f\n", log(-1.0));} : :on my Cygwin box with `gcc version 2.95.2 19991024 (release)' and got: : : -Inf : :I think this is wrong. :Should the configure detect this incompatibility? Cygwinは内部的にnewlibという名前のlibcを使ってますが、 log()は実はwrapperで、下請けの__ieee754_log()の結果を 変更してNaNを-Infにしてます。 コメントにもそう書いてあるので意図的なものみたい。 newlib/libm/math/w_log.c: >RETURNS >Normally, returns the calculated value. When <[x]> is zero, the >returned value is <<-HUGE_VAL>> and <> is set to <>. >When <[x]> is negative, the returned value is <<-HUGE_VAL>> and ><> is set to <>. You can control the error behavior via ><>. どうしようかなあ?とりあえずこれでcommitしてみます。 #if defined __CYGWIN__ #define log(x) ((x) < 0.0 ? ((x) - (x)) / 0.0 : log(x)) #endif -- わたなべひろふみ