zero.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. function write(v) { WScript.Echo(v + ""); }
  6. function is_negative_zero(n)
  7. {
  8. if(n == 0 && 1/n < 0)
  9. return true;
  10. else
  11. return false;
  12. }
  13. function itself(a) { return a; }
  14. var x; var y;
  15. // mul
  16. x = 0*0; write(" 0* 0 : " + x + " " + is_negative_zero(x));
  17. x = -0*0; write("-0* 0 : " + x + " " + is_negative_zero(x));
  18. x = 0*-0; write(" 0*-0 : " + x + " " + is_negative_zero(x));
  19. x = -0*-0; write("-0*-0 : " + x + " " + is_negative_zero(x));
  20. x = 5*5; write(" 5* 5 : " + x + " " + is_negative_zero(x));
  21. x = -5*5; write("-5* 5 : " + x + " " + is_negative_zero(x));
  22. x = 5*-5; write(" 5*-5 : " + x + " " + is_negative_zero(x));
  23. x = -5*-5; write("-5*-5 : " + x + " " + is_negative_zero(x));
  24. x = 0*5; write(" 0* 5 : " + x + " " + is_negative_zero(x));
  25. x = -0*5; write("-0* 5 : " + x + " " + is_negative_zero(x));
  26. x = 0*-5; write(" 0*-5 : " + x + " " + is_negative_zero(x));
  27. x = -0*-5; write("-0*-5 : " + x + " " + is_negative_zero(x));
  28. // Div
  29. x = 0/0; write(" 0/ 0 : " + x + " " + is_negative_zero(x));
  30. x = -0/0; write("-0/ 0 : " + x + " " + is_negative_zero(x));
  31. x = 0/-0; write(" 0/-0 : " + x + " " + is_negative_zero(x));
  32. x = -0/-0; write("-0/-0 : " + x + " " + is_negative_zero(x));
  33. x = 5/5; write(" 5/ 5 : " + x + " " + is_negative_zero(x));
  34. x = -5/5; write("-5/ 5 : " + x + " " + is_negative_zero(x));
  35. x = 5/-5; write(" 5/-5 : " + x + " " + is_negative_zero(x));
  36. x = -5/-5; write("-5/-5 : " + x + " " + is_negative_zero(x));
  37. x = 0/5; write(" 0/ 5 : " + x + " " + is_negative_zero(x));
  38. x = -0/5; write("-0/ 5 : " + x + " " + is_negative_zero(x));
  39. x = 0/-5; write(" 0/-5 : " + x + " " + is_negative_zero(x));
  40. x = -0/-5; write("-0/-5 : " + x + " " + is_negative_zero(x));
  41. // Mod
  42. x = 0%0; write(" 0% 0 : " + x + " " + is_negative_zero(x));
  43. x = -0%0; write("-0% 0 : " + x + " " + is_negative_zero(x));
  44. x = 0%-0; write(" 0%-0 : " + x + " " + is_negative_zero(x));
  45. x = -0%-0; write("-0%-0 : " + x + " " + is_negative_zero(x));
  46. x = 5%5; write(" 5% 5 : " + x + " " + is_negative_zero(x));
  47. x = -5%5; write("-5% 5 : " + x + " " + is_negative_zero(x));
  48. x = 5%-5; write(" 5%-5 : " + x + " " + is_negative_zero(x));
  49. x = -5%-5; write("-5%-5 : " + x + " " + is_negative_zero(x));
  50. x = 0%5; write(" 0% 5 : " + x + " " + is_negative_zero(x));
  51. x = -0%5; write("-0% 5 : " + x + " " + is_negative_zero(x));
  52. x = 0%-5; write(" 0%-5 : " + x + " " + is_negative_zero(x));
  53. x = -0%-5; write("-0%-5 : " + x + " " + is_negative_zero(x));
  54. y = 1 / (0 / -1); write(y + " " + (y === -Infinity));
  55. y = 1 / (0 * -1); write(y + " " + (y === -Infinity));
  56. y = 1 / (+0 / -1); write(y + " " + (y === Number.NEGATIVE_INFINITY));
  57. y = 1 / (+0 * -1); write(y + " " + (y === Number.NEGATIVE_INFINITY));
  58. y = 2 / (-5 % 5 ); write(y + " " + (y === Number.NEGATIVE_INFINITY));
  59. y = -2/ (-5 % 5 ); write(y + " " + (y === Number.NEGATIVE_INFINITY));
  60. y = 2 / (-5 %-5 ); write(y + " " + (y === Number.NEGATIVE_INFINITY));
  61. y = -2/ (-5 %-5 ); write(y + " " + (y === Number.NEGATIVE_INFINITY));
  62. function op_test() {
  63. var x = 0;
  64. var y = 0;
  65. if ( itself(1) )
  66. {
  67. x = 0;
  68. y = -1;
  69. }
  70. else
  71. {
  72. x = 5;
  73. y = 10;
  74. }
  75. var r;
  76. r = x * y; write(r + " " + is_negative_zero(r));
  77. r = x / y; write(r + " " + is_negative_zero(r));
  78. r = x % y; write(r + " " + is_negative_zero(r));
  79. }
  80. op_test();