fabs2asmjs.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  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. /*
  6. This file is executed from fabs1.js
  7. fabs from ucrtbase.dll doesn't restore the FPU Control word correctly when passed a NaN.
  8. This is exposed if we WScript.LoadScriptFile() code with Math.Abs(NaN) in it.
  9. Causing an assertion failure in SmartFPUControl. The change special-handles NaN without calling fabs
  10. */
  11. function AsmModule(stdlib, foreign, heap) {
  12. "use asm";
  13. var abs = stdlib.Math.abs;
  14. function testOp(av) {
  15. av = +av;
  16. return +abs(av);
  17. };
  18. return {testOp : testOp};
  19. }
  20. var asmModule = AsmModule({Math:Math},{}, new ArrayBuffer(1<<20));
  21. WScript.Echo(asmModule.testOp(-123.334) === 123.334);
  22. WScript.Echo(isNaN(asmModule.testOp(NaN)));
  23. WScript.Echo(isNaN(asmModule.testOp(-NaN)));
  24. WScript.Echo(asmModule.testOp(Infinity) === Infinity);
  25. WScript.Echo(asmModule.testOp(-Infinity) === Infinity);
  26. WScript.Echo(asmModule.testOp(0.0) === 0.0);
  27. WScript.Echo(asmModule.testOp(-0.0) === 0.0);