Project

General

Profile

Actions

Bug #13279

closed

Math.log10 accuracy regression

Added by jgoizueta (Javier Goizueta) about 7 years ago. Updated about 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:79907]

Description

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

Updated by nobu (Nobuyoshi Nakada) about 7 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: DONTNEED, 2.3: DONTNEED, 2.4: REQUIRED
Actions #2

Updated by nobu (Nobuyoshi Nakada) about 7 years ago

  • Status changed from Open to Closed

Applied in changeset r57779.


math.c: more accuracy

Updated by naruse (Yui NARUSE) about 7 years ago

  • 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0