From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id EE2001F5AE for ; Sat, 1 Aug 2020 18:02:26 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 86E1F120A29; Sun, 2 Aug 2020 03:01:46 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 13467120A1C for ; Sun, 2 Aug 2020 03:01:43 +0900 (JST) Received: by filterdrecv-p3mdw1-7ff865655c-r62j4 with SMTP id filterdrecv-p3mdw1-7ff865655c-r62j4-19-5F25AE23-79 2020-08-01 18:02:11.897588092 +0000 UTC m=+258352.575251150 Received: from herokuapp.com (unknown) by ismtpd0023p1iad2.sendgrid.net (SG) with ESMTP id t5O7DK6cRu2bupxmJJb2Qw for ; Sat, 01 Aug 2020 18:02:11.804 +0000 (UTC) Date: Sat, 01 Aug 2020 18:02:11 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75271 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17098 X-Redmine-Issue-Author: chrisseaton X-Redmine-Sender: Eregon X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr1MwS54Pj0h6hdDZxOYnF?= =?us-ascii?Q?asuKN5KORfBF0XtmnoFSFXAv=2F09B5RK5q75LHjw?= =?us-ascii?Q?yqn1piKxX+OCYtNmvywUYnyDs4sxF1Q4Onowvke?= =?us-ascii?Q?6mleAuEN3yxjxErsawhgHJGXCH4XAP1r5msk9cn?= =?us-ascii?Q?sJ08965ja32k+biBWkHgzFaUgX0zIxnVZt+p5ga?= =?us-ascii?Q?V4SdwWs8vYAeiiknM=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99442 Subject: [ruby-core:99442] [Ruby master Bug#17098] Float#negative? reports negative zero as not negative X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17098 has been updated by Eregon (Benoit Daloze). chrisseaton (Chris Seaton) wrote in #note-5: > then another option could be to add a new predicate `Float#negative_zero?` - that would allow people to differentiate as needed. Interesting, I thought `equal?` would work for that (it does on TruffleRuby) but it does not on CRuby 2.6.6: ``` [19] pry(main)> 0.0.equal?(0.0) => true [20] pry(main)> -0.0.equal?(-0.0) => false ``` I guess it's a result of implementing Float as tagged (flonum) but only for a subset of Float: ``` [25] pry(main)> a=-0.0 => -0.0 [26] pry(main)> a.equal?(a) => true ``` `eql?` and `==` do not differentiate 0.0 and -0.0. One way to test for -0.0 seems `(-f).equal?(0.0)` but that's kind of brittle as it relies on 0.0 being a flonum on CRuby. I tend to agree that `0.0.positive? == -0.0.negative?` and since `0.positive? => false` then both as `false` seems to make sense (essentially they are the same as `> 0` and `< 0`). ---------------------------------------- Bug #17098: Float#negative? reports negative zero as not negative https://bugs.ruby-lang.org/issues/17098#change-86897 * 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/