ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / Atom feed
From: sawadatsuyoshi@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:99444] [Ruby master Bug#17098] Float#negative? reports negative zero as not negative
Date: Sun, 02 Aug 2020 12:21:27 +0000 (UTC)
Message-ID: <redmine.journal-86899.20200802122127.8671@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-17098.20200801010523.8671@ruby-lang.org>

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/

      parent reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-01  1:05 [ruby-core:99426] " chris
2020-08-01  2:18 ` [ruby-core:99427] " merch-redmine
2020-08-01 12:18 ` [ruby-core:99432] " chris
2020-08-01 12:38 ` [ruby-core:99433] " sawadatsuyoshi
2020-08-01 12:50 ` [ruby-core:99434] " chris
2020-08-01 16:00 ` [ruby-core:99441] " chris
2020-08-01 18:02 ` [ruby-core:99442] " eregontp
2020-08-01 19:41 ` [ruby-core:99443] " marcandre-ruby-core
2020-08-02 12:21 ` sawadatsuyoshi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-86899.20200802122127.8671@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ruby-core@ruby-lang.org archive (unofficial mirror)

Archives are clonable: git clone --mirror https://public-inbox.org/ruby-core

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.core
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.core
	nntp://news.gmane.io/gmane.comp.lang.ruby.core

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git