LOG10E mystery constant
Tom Mitchell
mitch at niftyegg.com
Mon Feb 21 16:35:14 PST 2011
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.
http://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 http://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.
> --
> Cheers,
> --MarkM
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
--
T o m M i t c h e l l
mitch-at-niftyegg-dot-com
"My lifetime goal is to be the kind of person my dogs think I am."
More information about the test262-discuss
mailing list