[#41916] Proposal: Bitmap Marking GC — Narihiro Nakamura <authornari@...>

Hi.

18 messages 2012/01/05

[#41941] [ruby-trunk - Bug #5851][Open] make check fails when compiling with GCC 4.7 - *** longjmp causes uninitialized stack frame *** — Vit Ondruch <v.ondruch@...>

12 messages 2012/01/06

[#41979] [ruby-trunk - Bug #5865][Open] Exception#== should return false if the classes differ — Hiro Asari <asari.ruby@...>

10 messages 2012/01/08

[#42003] [ruby-trunk - Bug #5871][Open] regexp \W matches some word characters when inside a case-insensitive character class — Gareth Adams <gareth@...>

14 messages 2012/01/09

[#42016] [ruby-trunk - Feature #5873][Open] Adopt FFI over DL — Heesob Park <phasis@...>

15 messages 2012/01/10

[#42149] [ruby-trunk - Feature #5899][Open] chaining comparsions. — Ondrej Bilka <neleai@...>

12 messages 2012/01/16

[#42164] [ruby-trunk - Feature #5903][Open] Optimize st_table (take 2) — Yura Sokolov <funny.falcon@...>

18 messages 2012/01/17

[ruby-core:42077] [ruby-trunk - Bug #5884] Float::NAN and 0.0/0.0 is represented differently when packed with 'g'

From: Yui NARUSE <naruse@...>
Date: 2012-01-12 02:14:42 UTC
List: ruby-core #42077
Issue #5884 has been updated by Yui NARUSE.


Yui NARUSE wrote:
> Hiro Asari wrote:
> > Besides it being status quo, what is the rationale behind not having Float::NAN and 0.0/0.0 act identically?
> 
> * I thought it should be quiet NaN
> * no reason to choose "\xFF\xC0\x00\x00" there is many NaNs and platform dependent
> * the result of 0.0/0.0 may differ on each call

I must add one more reason; the NaN seems not what I defined.
The NaN is provided by the system's math.h.

And additional to say, you should use unpack('G') because it is double.


Hiro Asari wrote:
> I am not presenting a real use case. That is not my intent. My intent is to clarify the design of Float::NAN, especially in relation to 0.0/0.0. Since there is no way to distinguish the two without it, it seems to me that Array#pack is as good a use case as any. It is useful to the extent that we can distinguish the two, now that it is established that they can (and perhaps *should*) be different.

The design of Float::NAN is to provide a NaN.
It may equal to a result of 0.0/0.0 as a binary and maybe not.
The reason why there is no straight way to distinguish the two is people shouldn't need it.

> I see that my assumption that these objects should behave the same was flat out misguided.
> 
> It is acknowledged that there are many NaN's. As there is no way to distinguish these multiple NaN values that are passed to Array#pack,

If you know the environment's floating point number system supports IEEE 754 and its endian,
you can know what binary is NaN.

> then, am I correct to conclude that [Float::NAN].pack("g"), as well as [0.0/0.0].pack("g"), is indeterminate?

Yes, its binary expression is out of the spec.
The one accurate thing is the binary is a NaN on the environment.

> Also, am I correct to conclude that the value generated on one machine may not be identical to the one that is generated on another?
>
> (I understand that this is mostly academic; the two different values make a round trip correctly in and out of their respective packed counterpart, one way or another.)

Yes, of course.
There is non IEEE 754 systems.
# for example VAX is not an IEEE 754 system and doesn't have NaN. (Ruby 1.9 or later doesn't support it)

And IEEE 754/other specs doesn't say what NaN should be returned.

Anyway if both system is IEEE 754 system, a NaN on a system is also a NaN on another system.
----------------------------------------
Bug #5884: Float::NAN and 0.0/0.0 is represented differently when packed with 'g'
https://bugs.ruby-lang.org/issues/5884

Author: Hiro Asari
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.0.0dev (2011-12-31 trunk 34165) [x86_64-darwin11.2.0] 


$ ruby2.0 -e 'p [Float::NAN].pack("g")'
"\x7F\xC0\x00\x00"

$ ruby2.0 -e 'p [0.0/0.0].pack("g")'
"\xFF\xC0\x00\x00"

It would be nice to have Float::NAN and 0.0/0.0 behave identically in this regard.


-- 
http://bugs.ruby-lang.org/

In This Thread