ruby-core

Mailing list archive

[#102393] [Ruby master Feature#17608] Compact and sum in one step — sawadatsuyoshi@...

Issue #17608 has been reported by sawa (Tsuyoshi Sawada).

13 messages 2021/02/04

[#102438] [Ruby master Bug#17619] if false foo=42; end creates a foo local variable set to nil — pkmuldoon@...

Issue #17619 has been reported by pkmuldoon (Phil Muldoon).

10 messages 2021/02/10

[#102631] [Ruby master Feature#17660] Expose information about which basic methods have been redefined — tenderlove@...

Issue #17660 has been reported by tenderlovemaking (Aaron Patterson).

9 messages 2021/02/27

[#102639] [Ruby master Misc#17662] The herdoc pattern used in tests does not syntax highlight correctly in many editors — eregontp@...

Issue #17662 has been reported by Eregon (Benoit Daloze).

13 messages 2021/02/27

[#102652] [Ruby master Bug#17664] Behavior of sockets changed in Ruby 3.0 to non-blocking — ciconia@...

Issue #17664 has been reported by ciconia (Sharon Rosner).

23 messages 2021/02/28

[ruby-core:102514] [Ruby master Bug#17631] `Numeric#real?` incorrectly returns true for `NaN` and `INFINITY`

From: muraken@...
Date: 2021-02-16 03:25:20 UTC
List: ruby-core #102514
Issue #17631 has been updated by mrkn (Kenta Murata).


IEEE754 follows the extended real number system that is a real number system with positive and negative Infinities.  So, at least, `Float::INFINITY.real?` can return `true`.  `BigDecimal` also employs the extended real number system, so `BigDecimal::INFINITY.real?` can be `true`, too.

`Float::NAN` and `BigDecimal::NAN` are not-a-number, so `real?` of them may be reasonable to be `false` depending on the definition of the method.

----------------------------------------
Bug #17631: `Numeric#real?` incorrectly returns true for `NaN` and `INFINITY`
https://bugs.ruby-lang.org/issues/17631#change-90407

* Author: jtannas (Joel Tannas)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
In mathematics, infinity is not a real number. See https://math.stackexchange.com/a/750787
I don't have a source for this, but I also believe that `NaN` is not a real number.

`Numeric#real?` incorrectly returns `true` for both of these cases.

``` ruby
irb(main):001:0> Float::INFINITY.real?
=> true
irb(main):002:0> Float::NAN.real?
=> true
irb(main):003:0> require 'bigdecimal'
=> true
irb(main):004:0> BigDecimal::NAN.real?
=> true
irb(main):005:0> BigDecimal::INFINITY.real?
=> true
```

I ran into this while doing some math with logarithms, leading me to have to put in weird catches like `return nil if result.complex? || result.nan? || result.infinite?`

---
Originally reported here: https://stackoverflow.com/q/64795265/7950458



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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread