exp.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // interesting floating point limits
  6. checkNaN(NaN);
  7. check(1, +0);
  8. check(1, -0.0);
  9. check(+Infinity, +Infinity);
  10. check(0, -Infinity);
  11. check(Math.E * Math.E * Math.E, 3);
  12. if(!isNaN(Math.exp()))
  13. {
  14. WScript.Echo("error: Math.exp() is not NaN");
  15. }
  16. WScript.Echo("done");
  17. function check(result, n) {
  18. var rs = Math.exp(n);
  19. if (isNaN(result) || isNaN(n) ||
  20. Math.abs(rs - result) > 0.00000000001) {
  21. WScript.Echo("exp(" + n + ") != " + result);
  22. WScript.Echo(" wrong result is exp(" + n + ") = " + rs);
  23. }
  24. }
  25. function checkNaN(x) {
  26. var rs = Math.exp(x);
  27. if (!isNaN(rs)) {
  28. WScript.Echo("exp(" + x + ") != NaN");
  29. WScript.Echo(" wrong result is exp(" + x + ") = " + rs);
  30. }
  31. }