atan2.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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((-Math.PI), -3, -Infinity);
  24. check(-0, -3, +Infinity);
  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) / 2, -Infinity, -3);
  29. check(Math.PI / 4, +Infinity, +Infinity);
  30. check(3 * Math.PI / 4, +Infinity, -Infinity);
  31. check(-Math.PI / 4, -Infinity, +Infinity);
  32. check(-3 * Math.PI / 4, -Infinity, -Infinity);
  33. check((Math.PI) / 4, 5, 5.0);
  34. if(!isNaN(Math.atan2()))
  35. {
  36. WScript.Echo("error: Math.atan2() is not NaN");
  37. }
  38. WScript.Echo("done");
  39. function check(result, y, x) {
  40. var res = Math.atan2(y, x);
  41. if (Math.abs(res - result) > 0.00000000001) {
  42. WScript.Echo("atan2(" + y + " , " + x + ") != " + result);
  43. WScript.Echo(" the wrong result is atan2(" + y + " , " + x + ") = " + res);
  44. }
  45. }
  46. function checkNaN(y, x) {
  47. var rs = Math.atan2(y, x);
  48. if (!isNaN(rs)) {
  49. WScript.Echo("atan2(" + y + " , " + x + ") != NaN");
  50. WScript.Echo(" wrong result is atan2(" + y + " , " + x + ") = " + rs);
  51. }
  52. }