cos.js 1.1 KB

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