Math.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * @author humbletim / https://github.com/humbletim
  3. */
  4. module( "Math" );
  5. //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  6. //http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.sign
  7. /*
  8. 20.2.2.29 Math.sign(x)
  9. Returns the sign of the x, indicating whether x is positive, negative or zero.
  10. If x is NaN, the result is NaN.
  11. If x is -0, the result is -0.
  12. If x is +0, the result is +0.
  13. If x is negative and not -0, the result is -1.
  14. If x is positive and not +0, the result is +1.
  15. */
  16. test( "Math.sign/polyfill", function() {
  17. ok( isNaN( Math.sign(NaN) ) , "If x is NaN<NaN>, the result is NaN.");
  18. ok( isNaN( Math.sign(new THREE.Vector3()) ) , "If x is NaN<object>, the result is NaN.");
  19. ok( isNaN( Math.sign() ) , "If x is NaN<undefined>, the result is NaN.");
  20. ok( isNaN( Math.sign('--3') ) , "If x is NaN<'--3'>, the result is NaN.");
  21. ok( Math.sign(-0) === -0 , "If x is -0, the result is -0.");
  22. ok( Math.sign(+0) === +0 , "If x is +0, the result is +0.");
  23. ok( Math.sign(-Infinity) === -1 , "If x is negative<-Infinity> and not -0, the result is -1.");
  24. ok( Math.sign('-3') === -1 , "If x is negative<'-3'> and not -0, the result is -1.");
  25. ok( Math.sign('-1e-10') === -1 , "If x is negative<'-1e-10'> and not -0, the result is -1.");
  26. ok( Math.sign(+Infinity) === +1 , "If x is positive<+Infinity> and not +0, the result is +1.");
  27. ok( Math.sign('+3') === +1 , "If x is positive<'+3'> and not +0, the result is +1.");
  28. });