LOG10E mystery constant

# Mark S. Miller (14 years ago)

The specification of Math.LOG10E says:

15.8.1.5 LOG10E

The Number value for the base-10 logarithm of e, the base of the natural logarithms; this value is approximately 0.4342944819032518.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

NOTE The value of Math.LOG10E is approximately the reciprocal of the value of Math.LN10.

This is the only constant whose actual value differs across browsers:

0.43429448190325176 v8 version 2.3.9 [console: dumb] 0.4342944819032518 Chrome 11.0.672.2 dev 0.4342944819032518 Chrome 11.0.672.0 canary build 0.4342944819032518 FF 3.6.13 0.4342944819032518 FF 4.0b12pre 0.43429448190325176 Safari 5.0.1 (5533.17.8) 0.43429448190325176 WebKit nightly Safari 5.0.1 (5533.17.8, r78794) 0.4342944819032518 Opera 11.01 Build 1190 0.4342944819032518 IE 9.0.8080.16413CO

Anyone know why? Which value is more correct?

I don't really care about Math.LOG10E, but it's easier to write tests if only one value is actually correct.

# Mark S. Miller (14 years ago)

On Sun, Feb 20, 2011 at 9:26 PM, John Cowan <cowan at mercury.ccil.org> wrote:

Mark S. Miller scripsit:

This is the only constant whose actual value differs across browsers:

0.43429448190325176 v8 version 2.3.9 [console: dumb] 0.4342944819032518 Chrome 11.0.672.2 dev

[etc.]

The two values are really the same value when represented as an IEEE double. The difference is in the printing routine, not the internal representation. Specifically, the "...2518" browsers are rounding, the "...25176" browsers are not.

But they convert to back to two different floating point numbers, at least on all the browsers I quickly tried.

0.43429448190325176 === 0.4342944819032518

false

0.43429448190325176 < 0.4342944819032518

true

0.43429448190325176 > 0.4342944819032518

false

A little more testing reveals that the two numbers seem to be consecutive, in the sense that there are no intermediate representable numbers.

# Mark S. Miller (14 years ago)

That's what I needed. Thanks.

# Gavin Barraclough (14 years ago)

I've fixed this value for Safari in WebKit r79246.

# Tom Mitchell (14 years ago)

On Sun, Feb 20, 2011 at 9:16 PM, Mark S. Miller <erights at google.com> wrote:

The specification of Math.LOG10E says:

15.8.1.5 LOG10E

The Number value for the base-10 logarithm of e, the base of the natural logarithms; this value is approximately 0.4342944819032518.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

NOTE The value of Math.LOG10E is approximately the reciprocal of the value of Math.LN10.

This is the only constant whose actual value differs across browsers:

0.43429448190325176   v8 version 2.3.9 [console: dumb] 0.4342944819032518     Chrome 11.0.672.2 dev 0.4342944819032518     Chrome 11.0.672.0 canary build 0.4342944819032518     FF 3.6.13 0.4342944819032518     FF 4.0b12pre 0.43429448190325176   Safari 5.0.1 (5533.17.8) 0.43429448190325176   WebKit nightly Safari 5.0.1 (5533.17.8, r78794) 0.4342944819032518     Opera 11.01 Build 1190 0.4342944819032518     IE 9.0.8080.16413CO

Anyone know why? Which value is more correct? I don't really care about Math.LOG10E, but it's easier to write tests if only one value is actually correct.

It makes sense to look at some number tables.

$ grep 4342944 /usr/include/.h /usr/include/lcms.h:# define LOGE 0.4342944819 /usr/include/math.h:# define M_LOG10E 0.43429448190325182765 / log_10 e / /usr/include/math.h:# define M_LOG10El 0.4342944819032518276511289189166051L / log_10 e */

Thus it is necessary to test the difference between the internal and external representation. In my mind 0.43429448190325176 is less correct than 0.4342944819032518 but since the first correctly rounds to the second they are equal values underneath but not equal display strings.

My guess is that the underlying value is correct but we are looking at rounding differences.

I might note that 0.43429448190325182765 rounded to 17 sdp does not round to 0.43429448190325176 so is less 'correct'.

It can also be interesting to report the processor being used when math details are being inspected. For example Intel has dedicated 80 bit registers in their FPU and in some cases only rounds when values are exported from FPU registers to 64 bit memory objects. Also it is important to know if the browser is a 32 bit or a 64 bit version as well as the underlying OS. And also the underlying math library as used in the link line, compiler and compiler flags.

This link might be interesting if it did not mix php and js. phpjs.org/functions/get_defined_constants:839

In an ideal world browsers should use the system math lib. Yet there is always some code that #defines PI 3.1415 and reports bugs when the result differs in the 19th value to the right of the decimal.

And if someone was 'clever' and built all of base 10 on something else like: "To get log base 10 we can define the function log10(x):= log(x)/log(10) = 0.43429448190325* log(x)" from www1.uprh.edu/rbaretti/MaximaPrimer2feb2011.htm other rounding issues would surface and "approximatively" as indicated in the standard quoted would apply.

And since one of the recent assaults on php involved math this area is worthy of testing both for correctness as well as robustness.

# P T Withington (14 years ago)

On 2011-02-21, at 00:47, Mark S. Miller wrote:

But they convert to back to two different floating point numbers, at least on all the browsers I quickly tried.

0.43429448190325176 === 0.4342944819032518 false 0.43429448190325176 < 0.4342944819032518 true 0.43429448190325176 > 0.4342944819032518 false

A little more testing reveals that the two numbers seem to be consecutive, in the sense that there are no intermediate representable numbers.

Have we forgotten this lesson:

portal.acm.org/citation.cfm?id=93559

?

# Waldemar Horwat (14 years ago)

On 02/20/11 21:16, Mark S. Miller wrote:

The specification of Math.LOG10E says:

15.8.1.5 LOG10E

The Number value for the base-10 logarithm of e, the base of the natural logarithms; this value is approximately 0.4342944819032518.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

NOTE The value of Math.LOG10E is approximately the reciprocal of the value of Math.LN10.

This is the only constant whose actual value differs across browsers:

0.43429448190325176 v8 version 2.3.9 [console: dumb] 0.4342944819032518 Chrome 11.0.672.2 dev 0.4342944819032518 Chrome 11.0.672.0 canary build 0.4342944819032518 FF 3.6.13 0.4342944819032518 FF 4.0b12pre 0.43429448190325176 Safari 5.0.1 (5533.17.8) 0.43429448190325176 WebKit nightly Safari 5.0.1 (5533.17.8, r78794) 0.4342944819032518 Opera 11.01 Build 1190 0.4342944819032518 IE 9.0.8080.16413CO

Anyone know why? Which value is more correct?

I don't really care about Math.LOG10E, but it's easier to write tests if only one value is actually correct.

0.4342944819032518 is correct. 0.43429448190325176 is wrong.

The high-precision value of log10(e) is 0.4342944819032518276511289189166050822943970058036665661144...

The closest IEEE double to this is 0.43429448190325181666793241674895398318767547607421875, which prints as 0.4342944819032518.

0.43429448190325176 evaluates to the different IEEE double 0.434294481903251761156781185491126962006092071533203125.

On 02/20/11 21:26, John Cowan wrote:

The two values are really the same value when represented as an IEEE double. The difference is in the printing routine, not the internal representation. Specifically, the "...2518" browsers are rounding, the "...25176" browsers are not.

No, that's not what is happening here.

 Waldemar