atan2.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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, NaN);
  7. checkNaN(2, NaN);
  8. checkNaN(NaN, -3);
  9. check((Math.PI) / 2, 3, +0);
  10. check((Math.PI) / 2, 3, -0);
  11. check(0, 0, 3);
  12. check(0, 0, 0);
  13. check(Math.PI, 0, -0);
  14. check(Math.PI, 0, -2);
  15. check(-0, -0, 3);
  16. check(-0, -0, 0);
  17. check(-Math.PI, -0, -0);
  18. check(-Math.PI, -0, -2);
  19. check(-(Math.PI) / 2, -3, +0);
  20. check(-(Math.PI) / 2, -3, -0);
  21. check(0, 3, +Infinity);
  22. check((Math.PI), 3, -Infinity);
  23. check(-0, -3, +Infinity);
  24. check((Math.PI)/2, +Infinity, 3);
  25. check(-(Math.PI) / 2, -Infinity, 3);
  26. check((Math.PI) / 2, +Infinity, -3);
  27. check(-(Math.PI) / 2, -Infinity, -3);
  28. check((Math.PI) / 4, 5, 5.0);
  29. if(!isNaN(Math.atan2()))
  30. {
  31. WScript.Echo("error: Math.atan2() is not NaN");
  32. }
  33. WScript.Echo("done");
  34. function check(result, y, x) {
  35. var res = Math.atan2(y, x);
  36. if (Math.abs(res - result) > 0.00000000001) {
  37. WScript.Echo("atan2(" + y + " , " + x + ") != " + result);
  38. WScript.Echo(" the wrong result is atan2(" + y + " , " + x + ") = " + res);
  39. }
  40. }
  41. function checkNaN(y, x) {
  42. var rs = Math.atan2(y, x);
  43. if (!isNaN(rs)) {
  44. WScript.Echo("atan2(" + y + " , " + x + ") != NaN");
  45. WScript.Echo(" wrong result is atan2(" + y + " , " + x + ") = " + rs);
  46. }
  47. }