write_infinity.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
  2. var B = require('../').Buffer
  3. var test = require('tape')
  4. test('write/read Infinity as a float', function (t) {
  5. var buf = new B(4)
  6. t.equal(buf.writeFloatBE(Infinity, 0), 4)
  7. t.equal(buf.readFloatBE(0), Infinity)
  8. t.end()
  9. })
  10. test('write/read -Infinity as a float', function (t) {
  11. var buf = new B(4)
  12. t.equal(buf.writeFloatBE(-Infinity, 0), 4)
  13. t.equal(buf.readFloatBE(0), -Infinity)
  14. t.end()
  15. })
  16. test('write/read Infinity as a double', function (t) {
  17. var buf = new B(8)
  18. t.equal(buf.writeDoubleBE(Infinity, 0), 8)
  19. t.equal(buf.readDoubleBE(0), Infinity)
  20. t.end()
  21. })
  22. test('write/read -Infinity as a double', function (t) {
  23. var buf = new B(8)
  24. t.equal(buf.writeDoubleBE(-Infinity, 0), 8)
  25. t.equal(buf.readDoubleBE(0), -Infinity)
  26. t.end()
  27. })
  28. test('write/read float greater than max', function (t) {
  29. var buf = new B(4)
  30. t.equal(buf.writeFloatBE(4e38, 0), 4)
  31. t.equal(buf.readFloatBE(0), Infinity)
  32. t.end()
  33. })
  34. test('write/read float less than min', function (t) {
  35. var buf = new B(4)
  36. t.equal(buf.writeFloatBE(-4e40, 0), 4)
  37. t.equal(buf.readFloatBE(0), -Infinity)
  38. t.end()
  39. })