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