From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 9C69A17C453F for ; Mon, 31 Oct 2011 23:23:53 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 1F19DEA699C for ; Mon, 31 Oct 2011 23:13:42 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 13DC98FC28 for ; Mon, 31 Oct 2011 23:13:43 +0900 (JST) X-Virus-Scanned: amavisd-new at funfun.nagaokaut.ac.jp Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by localhost (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XqqjoE5wjSF3 for ; Mon, 31 Oct 2011 23:13:42 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id E6CAC8FC26 for ; Mon, 31 Oct 2011 23:13:42 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id D024B95241B for ; Mon, 31 Oct 2011 23:13:38 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id B25F83C21E21C; Mon, 31 Oct 2011 23:13:37 +0900 (JST) Received: from fluorine.ruby-lang.org (www.rubyist.net [210.251.121.216]) by carbon.ruby-lang.org (Postfix) with ESMTP id 96F5F3C21F74F for ; Mon, 31 Oct 2011 23:13:32 +0900 (JST) Received: from ruby-lang.org (localhost [127.0.0.1]) by fluorine.ruby-lang.org (Postfix) with ESMTP id 86D26251AD for ; Mon, 31 Oct 2011 23:13:32 +0900 (JST) Delivered-To: ruby-core@ruby-lang.org Date: Mon, 31 Oct 2011 23:13:32 +0900 Posted: Mon, 31 Oct 2011 23:13:32 +0900 From: Alexey Muranov Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:40561] [ruby-trunk - Feature #5321] Introducing Numeric#exact? and Numeric#inexact? To: ruby-core@ruby-lang.org Message-Id: References: X-ML-Name: ruby-core X-Mail-Count: 40561 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= X-Mailer: Redmine X-Spam-Checker-Version: SpamAssassin 3.1.7-deb3 (2006-10-05) on carbon.ruby-lang.org X-Spam-Level: X-Spam-Status: No, score=0.6 required=7.0 tests=BAYES_50,CONTENT_TYPE_PRESENT, FORGED_RCVD_HELO,TOOLONGSTR,X_MAILER_PRESENT autolearn=disabled version=3.1.7-deb3 X-Redmine-Issue-Author: mrkn X-Redmine-Issue-Assignee: matz X-Redmine-Issue-Id: 5321 X-Redmine-Mailinglistintegration-Message-Ids: 10081 X-Redmine-Project: ruby-trunk Auto-Submitted: auto-generated X-Redmine-Site: Ruby Issue Tracking System X-Redmine-Host: redmine.ruby-lang.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: Issue #5321 has been updated by Alexey Muranov. Kenta Murata wrote: > So I want to raise Math::DomainError for the function with exact zero. > But I don't want to raise the error for inexact zeros, such as 0.0, -0.0, > BigDecimal("0"), and others which are instances of classes I don't know. In my opinion, checking `x.class.exact?` would be good enough. If you will be checking the instance property #exact? for inputs, you are likely to find most input floats inexact, if they were produced as output of other operations, as operations on floats are not *intended* to be exact. I think that all exact values should be grouped in separate classes, like Rational, distinguished by their *intended* use. (Isn't the different intended uses the reason to have more than one class?) It may make sense to me to create a subclass of Numeric where each value is exact or inexact. ---------------------------------------- Feature #5321: Introducing Numeric#exact? and Numeric#inexact? http://redmine.ruby-lang.org/issues/5321 Author: Kenta Murata Status: Assigned Priority: Normal Assignee: Yukihiro Matsumoto Category: 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. -- http://redmine.ruby-lang.org