Feature #8994

add methods for Float to get if an NaN is quiet or not, also add class methods for Float to "generate" an quiet NaN and an loud NaN

Added by Hanmac (Hans Mackowiak) about 7 years ago. Updated about 1 year ago.

Target version:


Currently its not easy possible to know of an NaN in ruby is silent or not

like Float::NAN.quiet?

there should also methods to make an new NaN like Float::quiet_nan, maybe with the possibility to set user data

also there is

[Float::NAN].pack("g") #=> "\x7F\xC0\x00\x00"
[0.0/0.0].pack("g") #=> "\xFF\xC0\x00\x00"


[-(0.0/0.0)].pack("g") #=> "\x7F\xC0\x00\x00"

so it seems that - can turn an quiet NaN into an loud one? (i am not 100% clear about that)
specially when using two different NaN in one operation like

[(0.0/0.0) + Float::NAN].pack("g") #=> "\xFF\xC0\x00\x00"
[Float::NAN + (0.0/0.0)].pack("g") #=> "\x7F\xC0\x00\x00"

Wikipedia says:
For example, a bit-wise IEEE floating-point standard single precision (32-bit) NaN would be: s111 1111 1axx xxxx xxxx xxxx xxxx xxxx where s is the sign (most often ignored in applications), a determines the type of NaN, and x is an extra payload (most often ignored in applications). If a = 1, it is a quiet NaN; if a is zero and the payload is nonzero, then it is a signaling NaN.

so it seems that the negation does it a bit wrong? i mean -@ should not change the value like that?


Updated by jeremyevans0 (Jeremy Evans) about 1 year ago

  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)
  • ruby -v deleted (ruby 2.1.0dev (2013-10-01) [x86_64-darwin12.5.0])
  • Tracker changed from Bug to Feature

Also available in: Atom PDF