abs.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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(+0, +0);
  8. check(+0, -0);
  9. check(+Infinity, +Infinity);
  10. check(+Infinity, -Infinity);
  11. check(3.14, -3.14);
  12. check(3.14, 3.14);
  13. check(5, -5);
  14. check(5, 5);
  15. check(2147483647, 2147483647); /* INT_MAX */
  16. check(2147483648, -2147483648); /* INT_MIN */
  17. if(!isNaN(Math.abs()))
  18. {
  19. WScript.Echo("error: Math.abs() is not NaN");
  20. }
  21. WScript.Echo("done");
  22. function check(result, n) {
  23. var rs = Math.abs(n);
  24. if (rs != result) {
  25. WScript.Echo("abs(" + n + ") != " + result);
  26. WScript.Echo(" wrong result is abs(" + n + ") = " + rs);
  27. }
  28. }
  29. function checkNaN(x) {
  30. var rs = Math.abs(x);
  31. if (!isNaN(rs)) {
  32. WScript.Echo("abs(" + x + ") != NaN");
  33. WScript.Echo(" wrong result is abs(" + x + ") = " + rs);
  34. }
  35. }