CompositionMathUnary.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 foo() {}
  6. var all = [ undefined, null,
  7. true, false, new Boolean(true), new Boolean(false),
  8. NaN, +0, -0, 0, 1, 10.0, 10.1, -1, -5, 5,
  9. 124, 248, 654, 987, -1026, +98768.2546, -88754.15478,
  10. 1<<32, -(1<<32), (1<<32)-1, 1<<31, -(1<<31), 1<<25, -1<<25,
  11. Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY,
  12. new Number(NaN), new Number(+0), new Number( -0), new Number(0), new Number(1),
  13. new Number(10.0), new Number(10.1),
  14. new Number(Number.MAX_VALUE), new Number(Number.MIN_VALUE), new Number(Number.NaN),
  15. new Number(Number.POSITIVE_INFINITY), new Number(Number.NEGATIVE_INFINITY),
  16. "", "hello", "hel" + "lo", "+0", "-0", "0", "1", "10.0", "10.1",
  17. new String(""), new String("hello"), new String("he" + "llo"),
  18. new Object(), [1,2,3], new Object(), [1,2,3] , foo
  19. ];
  20. function AsmModule(stdlib) {
  21. "use asm";
  22. var fround = stdlib.Math.fround;
  23. function dbConvNot(y) {
  24. y = +y;
  25. var i = 0;
  26. i = ~((~~y)|0);
  27. return (!!i)|0;
  28. }
  29. function fltConvNot(y) {
  30. y = fround(y);
  31. var i = 0;
  32. i = ~((~~y)|0);
  33. return (!!i)|0;
  34. }
  35. return {
  36. dbConvNot : dbConvNot ,
  37. fltConvNot : fltConvNot ,
  38. };
  39. }
  40. var asmModule = AsmModule({Math:Math});
  41. for (var i=0; i<all.length; ++i) {
  42. print("i +a["+i+"](" + all[i] +") = " + (asmModule.dbConvNot(all[i])));
  43. print("i +a["+i+"](" + all[i] +") = " + (asmModule.fltConvNot(all[i])));
  44. }