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=-4.1 required=3.0 tests=AWL,BAYES_00, 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 822B11F4B4 for ; Mon, 5 Oct 2020 05:08:27 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 80B5E12096F; Mon, 5 Oct 2020 14:07: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 6C8DC12096B for ; Mon, 5 Oct 2020 14:07:44 +0900 (JST) Received: by filterdrecv-p3las1-6f66587546-d82vt with SMTP id filterdrecv-p3las1-6f66587546-d82vt-19-5F7AAA3E-17 2020-10-05 05:08:14.441315559 +0000 UTC m=+1148971.481829700 Received: from herokuapp.com (unknown) by ismtpd0087p1mdw1.sendgrid.net (SG) with ESMTP id I0C9QxepSsCf1qE2zHx_IQ for ; Mon, 05 Oct 2020 05:08:14.312 +0000 (UTC) Date: Mon, 05 Oct 2020 05:08:14 +0000 (UTC) From: nobu@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76140 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17214 X-Redmine-Issue-Author: karatedog X-Redmine-Sender: nobu 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?q8Dly+pU2+3ektTtZVXgZtbJPXwqo7p86jCsvYTW4Bzv0gXqaVxiP7=2FrOYNWYC?= =?us-ascii?Q?vMy53O9vCEcJAvlnnxwULTfrbPKF+mN+1Gu9rLR?= =?us-ascii?Q?PGCVp2c06Sa7gKqvF3uvRB4=2FocprlYPTbY=2Fi=2FkX?= =?us-ascii?Q?XA5Dad7meLxw=2FuO6Gao01bFjjI5=2F7TYesw48eO2?= =?us-ascii?Q?+NEW8NChFQ4dXe5QXVwWpHKMqzFP5UlfJF9L6XF?= =?us-ascii?Q?+UhFN=2FeB7B+pCKvSs=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 100298 Subject: [ruby-core:100298] [Ruby master Bug#17214] BigDecimal exponentiation gives incorrect results 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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17214 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Rejected `BigDecimal` instances hold the precision, and it is not enough in that cas= e. You need to override the default precision in some operations. ```ruby BigDecimal(2222).power(3.5, Float::DIG).to_i #=3D> 517135308457 ``` ---------------------------------------- Bug #17214: BigDecimal exponentiation gives incorrect results https://bugs.ruby-lang.org/issues/17214#change-87883 * Author: karatedog (F=F6ldes L=E1szl=F3) * Status: Rejected * Priority: Normal * ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- This is an incorrect value: ```ruby (BigDecimal("2222") ** BigDecimal("3.5")).to_i # =3D> 517135311000 ``` This is the correct value (within Float precision): ```ruby 2222 ** 3.5 # =3D> 517135308457.25256 ``` As the Base gets larger, the problem is more visible. Wrong value, number o= f trailing zeroes increase: ```ruby (BigDecimal("22222") ** BigDecimal("3.5")).to_i # =3D> 1635840670000000 ``` Nearing maximum Float precision: ```ruby 22222 ** 3.5 # =3D> 1635840670214066.5 ``` -- = https://bugs.ruby-lang.org/ Unsubscribe: