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-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.7 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 shortcircuit=no autolearn=no 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 A25CA1F466 for ; Wed, 15 Jan 2020 06:19:21 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B48EE120A5D; Wed, 15 Jan 2020 15:19:03 +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 DFEBD120A5D for ; Wed, 15 Jan 2020 15:19:00 +0900 (JST) Received: by filterdrecv-p3iad2-57f487d66-r5wpm with SMTP id filterdrecv-p3iad2-57f487d66-r5wpm-20-5E1EAEDB-55 2020-01-15 06:19:08.011839706 +0000 UTC m=+2525549.327830275 Received: from herokuapp.com (unknown [54.227.193.20]) by ismtpd0111p1mdw1.sendgrid.net (SG) with ESMTP id UrpdGQYESMy-M2Y4g9c16Q for ; Wed, 15 Jan 2020 06:19:07.853 +0000 (UTC) Date: Wed, 15 Jan 2020 06:19:08 +0000 (UTC) From: sawadatsuyoshi@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 72531 X-Redmine-Project: ruby-master X-Redmine-Issue-Id: 5321 X-Redmine-Issue-Author: mrkn X-Redmine-Issue-Assignee: matz X-Redmine-Sender: sawa 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?jFXA8Rt481sXUUIO9tYW1AJlMOZdNdlSw=2F5TfLCefGvLMr5PbWZJnpHeyZOqs2?= =?us-ascii?Q?QJO=2FK8=2FzqvpnzWSta05MltimdijlKl8AZPfOpsz?= =?us-ascii?Q?aGD3NUwrAq49jHGVdWsCh4gFFmuXuWYPWKiiQD=2F?= =?us-ascii?Q?96oU2wRCpEw8CPF=2FcPWL8yDRMO3pr24DA5VbozR?= =?us-ascii?Q?SsTYixEFfXRezqzg4NCzDJWE0IIuGIflJmaNqRk?= =?us-ascii?Q?J2zLFQybF+sORbl6Y=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96868 Subject: [ruby-core:96868] [Ruby master Feature#5321] Introducing Numeric#exact? and Numeric#inexact? 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 #5321 has been updated by sawa (Tsuyoshi Sawada). akr (Akira Tanaka) wrote: > Do you have good definition of exactness of numeric classes? Like alexeymuranov, I misread the proposal. I took it for `Integer.exact?`, etc. instead of `Numeric#exact?`, etc. As for the notion of **instance method** `exact?` (on numeric instances), I don't think it would be practical. For float, the same number may be exact or inexact depending on its history. The history may include mathematical operations by which it was created, as well as simply as literal interpretation. For example, `2.5` achieved by the following literal may be naturally considered exact: ```ruby 2.5 # => 2.5 ``` but the same `2.5` achieved in the following way is inexact: ```ruby 2.5000000000000001 # => 2.5 ``` So we may expect it to be possible to have "multiple instances" of 2.5, with different exactness, but that is impossible given Ruby's object system. As for the notion of **class method** `exact?` (on numeric classes), I think we can define that based on whether the literal interpretation is "transparent". `Float` is not exact because different literals are interpreted as the same instance, as with `2.5` above. I am being careful to use the word "transparent" above, which can be paraphrased as "one-to-one in some relevant sense". `Rational` should be considered exact even though `1/2r` and `2/4r` represent the same instance. `Integer` is exact. However, the use case that mrkn provided (https://bugs.ruby-lang.org/issues/5321#note-13) requires the instance method `exact?`. I became not so confident with my argument. ---------------------------------------- Feature #5321: Introducing Numeric#exact? and Numeric#inexact? https://bugs.ruby-lang.org/issues/5321#change-83881 * Author: mrkn (Kenta Murata) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- Ruby has several numeric classes such as Integer. These classes are classified whether their instances represent numbers exactly. According to this, Integer and Rational are exact, and Float and BigDecimal are inexact because they're always including error. The exactness of a Complex depends on its real and imaginary parts. Now, Ruby's numeric classes doesn't provide predicators to investigate the exactness of their instances. So, if we want to examine whether a number is exactly zero, we must investigate the class of the number. I want simple way to examine the number exactness. I propose to introduce Numeric#exact? and/or Numeric#inexact? for resolving this inconvenience. ---Files-------------------------------- numeric-exact-5321.patch (7.33 KB) -- https://bugs.ruby-lang.org/