paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 387 forks source link

- #338

Closed Yaffle closed 8 years ago

Yaffle commented 9 years ago

Fixes #334.

Yaffle commented 9 years ago

@ljharb , OK, what do you think now?

ljharb commented 9 years ago

The tests look good, and fail as expected on Chrome 42, node 0.8/0.10/0.11/0.12, and iojs 1.7.

ljharb commented 9 years ago

Thanks, this is looking great. I'll test it in a number of browsers before merging it.

Yaffle commented 9 years ago

any chance to finish this?

ljharb commented 9 years ago

Absolutely - it'll need to be freshly rebased on top of master, and then I'll do a fresh round of browser testing - but I don't think it needs much more work.

Yaffle commented 8 years ago

Math.acosh, Math.asinh, Math.cosh, Math.sinh are still not accurate ...

Math.acosh(1 + Number.EPSILON)
Math.asinh(Number.MAX_VALUE)
var EXP_NO_OVERFLOW = 709.782712893384; // Math.log(Number.MAX_VALUE)
Math.cosh(EXP_NO_OVERFLOW + 1 / Math.LOG2E);
Math.sinh(EXP_NO_OVERFLOW + 1 / Math.LOG2E);
ljharb commented 8 years ago

@Yaffle I'd love to bring this PR in if you want to freshly rebase it - it's been about 10 months :-)

Yaffle commented 7 years ago

~2 years

ljharb commented 7 years ago

@Yaffle yes, it's been 1 year since you closed the PR and deleted the branch without rebasing it, and since nobody else seems to understand this topic as well as you do, it will basically never be fixed.

I'd be delighted if you reopened the PR and rebased the branch, then it could get in very soon.

Yaffle commented 7 years ago

I have put all implementations of not precise ES6 Math functions to the comment at https://github.com/kangax/compat-table/issues/392#issuecomment-240196072

ljharb commented 7 years ago

Yes, thank you, but a dump of implementations doesn't help me change anything. What is helpful is a set of test cases, justified with evidence (browser results, spec steps, etc), and then also an implementation if a good one isn't apparent.

Yaffle commented 7 years ago

@ljharb, 1) a set of test cases: Math.asinh(1e+300) should not be equal to +∞; Math.atanh(1e-300) should not be equal to +0; Math.cosh(710) should not be equal to +∞; Math.sinh(710) should not be equal to +∞; Math.acosh(1 + Number.EPSILON) should be near Math.sqrt(2 * Number.EPSILON) 2) in good implementations (Chrome 54+, Firefox 48+, Safari 10+, Edge): Math.asinh(1e+300) returns ~691.4686750787736; Math.atanh(1e-300) returns 1e-300; Math.cosh(710) returns ~1.1169973830808557e+308; Math.sinh(710) returns ~1.1169973830808557e+308; Math.acosh(1 + Number.EPSILON) returns ~2.1073424255447017e-8; And so the relative error is very big. Note: Chrome < 54 on Windows fails tests for Math.asinh, Math.atanh and Math.acosh. Chrome < 40 ? on Windows fails tests for Math.cosh and Math.sinh. 3) The implementations are available at https://github.com/kangax/compat-table/issues/392#issuecomment-240196072

ljharb commented 7 years ago

Thank you, that is much more helpful!

ljharb commented 7 years ago

@Yaffle thanks, those first 4 are taken care of in ec76d49; i missed the edit for the 5th and will follow up with a fix for that.

ljharb commented 7 years ago

I'm unable to reproduce the acosh test failure on Chrome 53, 50, even down to 40.

Yaffle commented 7 years ago

@ljharb , the test for acosh might look similar to test for cbrt at https://github.com/paulmillr/es6-shim/blob/ec76d49cb801a03fb0a98041e2bba190a41b8288/es6-shim.js#L2083 :

Math.abs(1 - (Math.acosh(1 + Number.EPSILON) / Math.sqrt(2 * Number.EPSILON))) / Number.EPSILON > 8

Math.abs(1 - actual / expected) / Number.EPSILON returns something like "ulp" distance - https://en.wikipedia.org/wiki/Unit_in_the_last_place , while "almostEquals" measures only the absolute error.

ljharb commented 7 years ago

thanks, i'll update that.

Yaffle commented 7 years ago

@ljharb, thanks

ljharb commented 7 years ago

k, should be all set.