Bug #6370
closedNaNTest failed for Ruby 1.9.3 P194
Description
The Ruby 1.9.3 is compibled by GCC 4.7.0 (MinGW64) under Windows64. Configure line is as following:
.configure --build=x86_64-w64-mingw32 CFLAGS="-Ofast -mieee-fp -I/usr/local/include" CPPFLAGS="-Ofast -mieee-fp -I/usr/local/include" LDFLAGS="-L/usr/local/lib"
When compiled complete, run make test, it reports:
not ok float 15 -- C:/msys/1.0/home/beta/ruby-1.9.3-p194/sample/test.rb:1410:in nan_test' not ok float 20 -- C:/msys/1.0/home/beta/ruby-1.9.3-p194/sample/test.rb:1410:in
nan_test'
not ok float 25 -- C:/msys/1.0/home/beta/ruby-1.9.3-p194/sample/test.rb:1410:in nan_test' not ok float 30 -- C:/msys/1.0/home/beta/ruby-1.9.3-p194/sample/test.rb:1410:in
nan_test'
not ok float 35 -- C:/msys/1.0/home/beta/ruby-1.9.3-p194/sample/test.rb:1410:in nan_test' not ok float 40 -- C:/msys/1.0/home/beta/ruby-1.9.3-p194/sample/test.rb:1410:in
nan_test'
not ok float 45 -- C:/msys/1.0/home/beta/ruby-1.9.3-p194/sample/test.rb:1410:in `nan_test'
not ok/test: 903 failed 7
marked these 7 lines could pass the test
#nan_test(nan, 0)
#nan_test(nan, 1)
#nan_test(nan, -1)
#nan_test(nan, 1000)
#nan_test(nan, -1000)
#nan_test(nan, 1_000_000_000_000)
#nan_test(nan, -1_000_000_000_000)
Updated by mame (Yusuke Endoh) almost 12 years ago
Could you run the following script and show the result?
nan = 0.0 / 0
p nan
p [nan].pack("D")
p nan <=> 0
p nan != 0
p nan < 0
p nan > 0
p nan <= 0
p nan >= 0
--
Yusuke Endoh mame@tsg.ne.jp
Updated by raylinn@gmail.com (ray linn) almost 12 years ago
Here is the result:
beta@beta-PC ~
$ ruby test.rb
NaN
"\x00\x00\x00\x00\x00\x00\xF8\xFF"
nil
false
false
false
false
false
Updated by mame (Yusuke Endoh) almost 12 years ago
- Status changed from Open to Assigned
- Assignee set to luislavena (Luis Lavena)
I have no idea why (nan != 0) is evaluated to false.
Luis, Usa-san, Hongli Lai, can you reproduce it?
--
Yusuke Endoh mame@tsg.ne.jp
Updated by phasis68 (Heesob Park) almost 12 years ago
I can reproduce this issue on GCC 4.7.0 Mingw32.
The optimization flag -Ofast is the root cause of this issue.
Accoring to the manual, -Ofast is same to -O3 and -ffast-math.
And -ffast-math sets -fno-math-errno, -funsafe-math-optimizations, -ffinite-math-only, -fno-rounding-math, -fno-signaling-nans and -fcx-limited-range.
The flag -ffinite-math-only means
"Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or +-Infs."
So the nan test is not worked as expected.
The workaround is adding -fno-finite-math-only in case of -Ofast flag.
Updated by nobu (Nobuyoshi Nakada) almost 12 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r35497.
ray, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- configure.in (optflags): disable unsafe optimizations.
[ruby-core:44679][Bug #6370]
Updated by mame (Yusuke Endoh) almost 12 years ago
Heesob Park, thank you!
And I'm very sorry. I made a mistake with your name in [ruby-core:44692].
--
Yusuke Endoh mame@tsg.ne.jp