2
0

NegativeNaN.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 f(){
  6. f64 = new Float64Array([NaN]);
  7. u8 = new Uint8Array(f64.buffer);
  8. print(u8)
  9. f64 = new Float64Array([-NaN]);
  10. u8 = new Uint8Array(f64.buffer);
  11. print(u8)
  12. f64 = new Float32Array([NaN]);
  13. u8 = new Uint8Array(f64.buffer);
  14. print(u8)
  15. f64 = new Float32Array([-NaN]);
  16. u8 = new Uint8Array(f64.buffer);
  17. print(u8)
  18. // GitHub bug #398
  19. function numberToRawBits(v) {
  20. var isLittleEndian = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
  21. var reduce = Array.prototype[isLittleEndian ? 'reduceRight' : 'reduce'];
  22. var uint8 = new Uint8Array(new Float64Array([v]).buffer);
  23. return reduce.call(uint8, (a, v) => a + (v < 16 ? "0" : "") + v.toString(16), "");
  24. }
  25. console.log(numberToRawBits(NaN));
  26. console.log(numberToRawBits(-NaN));
  27. }
  28. f()
  29. f()