Math-constants.js 822 B

12345678910111213141516171819202122232425262728
  1. function assert(x) { if (!x) throw 1; }
  2. // FIXME: The parser seems to have issues with decimals,
  3. // so we multiply everything and compare with whole numbers.
  4. // I.e. 1233 < X * 1000 < 1235 instead of 1.233 < X < 1.235
  5. try {
  6. // approx. 2.718
  7. assert(2717 < Math.E * 1000 < 2719);
  8. // approx. 0.693MATH
  9. assert(692 < Math.LN2 * 1000 < 694);
  10. // approx. 2.303
  11. assert(2302 < Math.LN10 * 1000 < 2304);
  12. // approx. 1.443
  13. assert(1442 < Math.LOG2E * 1000 < 1444);
  14. // approx. 0.434
  15. assert(433 < Math.LOG10E * 1000 < 435);
  16. // approx. 3.1415
  17. assert(31414 < Math.PI * 10000 < 31416);
  18. // approx. 0.707
  19. assert(706 < Math.SQRT1_2 * 1000 < 708);
  20. // approx. 1.414
  21. assert(1413 < Math.SQRT2 * 1000 < 1415);
  22. console.log("PASS");
  23. } catch (e) {
  24. console.log("FAIL: " + e);
  25. }