Issue #17098 has been updated by sawa (Tsuyoshi Sawada).


Ruby or IEEE 754 seem to regard `-0.0` and `0.0` not as 0 in the mathematical sense, bit as (something like) negative and positive infinitesimal. Taking this into account, I started to think `-0.0.negative?` and `0.0.positive?` should both be `true`.

Regarding the fact that `-0.0 == 0.0` is true, I think it should be understood as '`-0.0` approaches `0.0`' rather than '`-0.0` is `0.0`'. Then it would not contradict with the above. Floating point numbers are approximated numbers to begin with, so it does not make much sense to talk about their exact identity. Hence it makes sense to regard `Float#==` to mean 'close enough' rather than 'exactly the same'.

----------------------------------------
Bug #17098: Float#negative? reports negative zero as not negative
https://bugs.ruby-lang.org/issues/17098#change-86899

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Is this intended behaviour?

```
irb(main):001:0> neg_zero = -0.0
=> -0.0
irb(main):002:0> neg_zero.negative?
=> false
irb(main):003:0> neg_zero < 0
=> false
```

It happens because `Numeric#negative?` uses `< 0`. My understanding of IEEE floating point is that negative zero is not less than zero, but I think it should still report as negative.



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

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