From: naruse@... Date: 2017-03-12T17:24:56+00:00 Subject: [ruby-core:80070] [Ruby trunk Bug#13279] Math.log10 accuracy regression Issue #13279 has been updated by Yui NARUSE. Backport changed from 2.2: DONTNEED, 2.3: DONTNEED, 2.4: REQUIRED to 2.2: DONTNEED, 2.3: DONTNEED, 2.4: DONE ruby_2_4 r57928 merged revision(s) 57778,57779. ---------------------------------------- Bug #13279: Math.log10 accuracy regression https://bugs.ruby-lang.org/issues/13279#change-63499 * Author: Javier Goizueta * Status: Closed * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.2: DONTNEED, 2.3: DONTNEED, 2.4: DONE ---------------------------------------- I've notice a degradation in the precision of Math.log10 in Ruby 2.4 with respect to 2.1: ~~~ 2.1.2 :136 > Math.log10 10**1000 => 1000.0 2.4.0 :009 > Math.log10 10**1000 => 999.9999999999999 ~~~ The problem has been introduced in this commit: git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e (https://github.com/ruby/ruby/commit/fd2c613b1cec46d0b02df722bb00ae01154d5dc3) The use of arithmetic to compute the log10(2) introduces some roundoff error in that constant: ~~~ 2.1.2 :140 > M_LN2 = 0.693147180559945309417232121458176568 => 0.6931471805599453 2.1.2 :141 > M_LN10 = 2.30258509299404568401799145468436421 => 2.302585092994046 2.1.2 :142 > l2 == M_LN2/M_LN10 => false 2.1.2 :144 > l2 => 0.3010299956639812 2.1.2 :145 > M_LN2/M_LN10 => 0.30102999566398114 ~~~ * The correct value of the constant (base-10 log of 2) is 0.301029995663981195213738894724... * The log10(2) function yields a correctly rounded approximation of 0.3010299956639812 * But the computed division of constants results in 0.30102999566398114 -- https://bugs.ruby-lang.org/ Unsubscribe: