2
0

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