Skip to content

accuracy of Math.cbrt, Math.expm1, Math.log1p #392

@Yaffle

Description

@Yaffle
var error = function (x, value) {
  return Math.abs(1 - x / value) / 2.220446049250313e-16; // error in number of ulps (http://en.wikipedia.org/wiki/Unit_in_the_last_place)
};

Firefox < 48 on Windows:

https://bugzilla.mozilla.org/show_bug.cgi?id=933257
https://bugzilla.mozilla.org/show_bug.cgi?id=897634

error(Math.log1p(0.0006516748007717887), 0.0006514625529548382) > 500;
error(Math.expm1(0.00001), 0.000010000050000166668) > 43000;
error(Math.cbrt(-3.9355663969868275e+307), -3.401489081587483e+102) > 50;
error(Math.asinh(-0.0005), -0.000499999979166669) > 100; // (caused by issues with `expm1` and `log1p` on Windows)
error(Math.atanh(-0.0005), -0.0005000000416666729) > 100; // (caused by issues with `expm1` and `log1p` on Windows)

Firefox

Math.exp(1) !== Math.E

Chrome < 54 on Windows:

https://code.google.com/p/v8/issues/detail?id=3468
https://code.google.com/p/v8/issues/detail?id=3509

error(Math.exp(-707.9999999999998), 3.30755300363916e-308) > 250;
Math.acosh(1e+308) === Infinity;
Math.asinh(1e+300) === Infinity;
Math.atanh(1e-300) === 0;

Konqueror 4.13 (Ubuntu):

https://github.com/KDE/kjs/blob/master/src/kjs/math_object.cpp

   Math.expm1 == undefined && Math.exmp1 != undefined
   Math.LOG10E !== 0.4342944819032518 // 0.43429448190325176
   Math.abs(+0) === 0 && 1 / Math.abs(+0) < 0
   Math.hypot.length === 0
   Math.hypot(1e200, 1e200) === 1 / 0 // overflow and underflow issues

   Math.asinh == undefined;
   Math.clz32 == undefeined;
   Math.imul() == undefined;

buggy Math.round in Safari 10 / Mobile Safari 10 / IE 11 / Edge 13 / Opera 12 / Konqueror 4.13:

Math.round(0.49999999999999994) !== 0

Math.pow issue in Firefox, Chrome, Safari, Edge when the second argument is an integer:

https://code.google.com/p/v8/issues/detail?id=3599
https://bugzilla.mozilla.org/show_bug.cgi?id=618251

error(Math.pow(10, 305), 1e+305) > 2;
error(Math.pow(10, 308), 1e+308) > 2;
error(Math.pow(9767, 77), 1.627839019440664e+307) > 8
error(Math.pow(1 + Math.pow(2, -27), Math.pow(2, 31) - 1), 8886109.924647752) > Math.pow(2, 28)

Chrome Mobile 52 (Android 5.1):

Math.pow(11, Math.pow(11, 9)) === 0;

Mobile Safari 10 (iOS 9.2):

Math.expm1(709.782712893384) === -1;
// note: Math.expm1(709.7827128933839) === 1.7976931348620688e+308

es6-shim:

nothing

core-js:

error(Math.acosh(1 + Number.EPSILON), 2.1073424255447017e-8) > 1e+7;
Math.asinh(1e-300) === 0;
Math.asinh(1e+300) === Infinity;
Math.atanh(1e-300) === 0;
error(Math.cbrt(1e-300), 1e-100) > 50;
Math.cosh(710) === Infinity;
error(Math.expm1(1e-6), 0.0000010000005000001665) > 1e+5;
error(Math.log1p(1e-8), 9.999999950000001e-9) > 1e+7;
+ Math.sinh, Math.tanh (because of expm1)

Traceur AND MDN's polyfills:

Math.acosh(1e+308) === Infinity;
error(Math.acosh(1 + Number.EPSILON), 2.1073424255447017e-8) > 1e+7;
Math.asinh(1e-300) === 0;
Math.asinh(1e+300) === Infinity;
Math.atanh(1e-300) === 0;
error(Math.cbrt(1e-300), 1e-100) > 50;
Math.cosh(710) === Infinity;
Math.sinh(710) === Infinity;
Math.sinh(1e-300) === 0;
Math.tanh(1e-300) === 0;
Math.tanh(1e+300) !== Math.tanh(1e+300);
Math.expm1(1e-300) === 0;
Math.log1p(1e-300) === 0;

Closure:

Math.acosh(1e+308) === Infinity;
error(Math.acosh(1 + Number.EPSILON), 2.1073424255447017e-8) > 1e+7;
Math.asinh(1e-300) === 0;
Math.asinh(1e+300) === Infinity;
error(Math.cbrt(1e-300), 1e-100) > 50;
Math.cosh(710) === Infinity;
Math.sinh(710) === Infinity;
Math.sinh(1e-300) === 0;
Math.tanh(1e-300) === 0;
Math.hypot(0, 0) !== Math.hypot(0, 0)
Math.hypot(1, Infinity) !== Math.hypot(1, Infinity)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions