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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*
* Tests to verify we're writing doubles correctly
*/
var common = require('../common');
var ASSERT = require('assert');
function test(clazz) {
var buffer = new clazz(16);
buffer.writeDoubleBE(2.225073858507201e-308, 0);
buffer.writeDoubleLE(2.225073858507201e-308, 8);
ASSERT.equal(0x00, buffer[0]);
ASSERT.equal(0x0f, buffer[1]);
ASSERT.equal(0xff, buffer[2]);
ASSERT.equal(0xff, buffer[3]);
ASSERT.equal(0xff, buffer[4]);
ASSERT.equal(0xff, buffer[5]);
ASSERT.equal(0xff, buffer[6]);
ASSERT.equal(0xff, buffer[7]);
ASSERT.equal(0xff, buffer[8]);
ASSERT.equal(0xff, buffer[9]);
ASSERT.equal(0xff, buffer[10]);
ASSERT.equal(0xff, buffer[11]);
ASSERT.equal(0xff, buffer[12]);
ASSERT.equal(0xff, buffer[13]);
ASSERT.equal(0x0f, buffer[14]);
ASSERT.equal(0x00, buffer[15]);
buffer.writeDoubleBE(1.0000000000000004, 0);
buffer.writeDoubleLE(1.0000000000000004, 8);
ASSERT.equal(0x3f, buffer[0]);
ASSERT.equal(0xf0, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x02, buffer[7]);
ASSERT.equal(0x02, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0xf0, buffer[14]);
ASSERT.equal(0x3f, buffer[15]);
buffer.writeDoubleBE(-2, 0);
buffer.writeDoubleLE(-2, 8);
ASSERT.equal(0xc0, buffer[0]);
ASSERT.equal(0x00, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
ASSERT.equal(0x00, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0x00, buffer[14]);
ASSERT.equal(0xc0, buffer[15]);
buffer.writeDoubleBE(1.7976931348623157e+308, 0);
buffer.writeDoubleLE(1.7976931348623157e+308, 8);
ASSERT.equal(0x7f, buffer[0]);
ASSERT.equal(0xef, buffer[1]);
ASSERT.equal(0xff, buffer[2]);
ASSERT.equal(0xff, buffer[3]);
ASSERT.equal(0xff, buffer[4]);
ASSERT.equal(0xff, buffer[5]);
ASSERT.equal(0xff, buffer[6]);
ASSERT.equal(0xff, buffer[7]);
ASSERT.equal(0xff, buffer[8]);
ASSERT.equal(0xff, buffer[9]);
ASSERT.equal(0xff, buffer[10]);
ASSERT.equal(0xff, buffer[11]);
ASSERT.equal(0xff, buffer[12]);
ASSERT.equal(0xff, buffer[13]);
ASSERT.equal(0xef, buffer[14]);
ASSERT.equal(0x7f, buffer[15]);
buffer.writeDoubleBE(0 * -1, 0);
buffer.writeDoubleLE(0 * -1, 8);
ASSERT.equal(0x80, buffer[0]);
ASSERT.equal(0x00, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
ASSERT.equal(0x00, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0x00, buffer[14]);
ASSERT.equal(0x80, buffer[15]);
buffer.writeDoubleBE(Infinity, 0);
buffer.writeDoubleLE(Infinity, 8);
ASSERT.equal(0x7F, buffer[0]);
ASSERT.equal(0xF0, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
ASSERT.equal(0x00, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0xF0, buffer[14]);
ASSERT.equal(0x7F, buffer[15]);
ASSERT.equal(Infinity, buffer.readDoubleBE(0));
ASSERT.equal(Infinity, buffer.readDoubleLE(8));
buffer.writeDoubleBE(-Infinity, 0);
buffer.writeDoubleLE(-Infinity, 8);
ASSERT.equal(0xFF, buffer[0]);
ASSERT.equal(0xF0, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0x00, buffer[6]);
ASSERT.equal(0x00, buffer[7]);
ASSERT.equal(0x00, buffer[8]);
ASSERT.equal(0x00, buffer[9]);
ASSERT.equal(0x00, buffer[10]);
ASSERT.equal(0x00, buffer[11]);
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0xF0, buffer[14]);
ASSERT.equal(0xFF, buffer[15]);
ASSERT.equal(-Infinity, buffer.readDoubleBE(0));
ASSERT.equal(-Infinity, buffer.readDoubleLE(8));
buffer.writeDoubleBE(NaN, 0);
buffer.writeDoubleLE(NaN, 8);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[0] || 0xFF === buffer[0]);
// mips processors use a slightly different NaN
ASSERT(0xF8 === buffer[1] || 0xF7 === buffer[1]);
ASSERT(0x00 === buffer[2] || 0xFF === buffer[2]);
ASSERT(0x00 === buffer[3] || 0xFF === buffer[3]);
ASSERT(0x00 === buffer[4] || 0xFF === buffer[4]);
ASSERT(0x00 === buffer[5] || 0xFF === buffer[5]);
ASSERT(0x00 === buffer[6] || 0xFF === buffer[6]);
ASSERT(0x00 === buffer[7] || 0xFF === buffer[7]);
ASSERT(0x00 === buffer[8] || 0xFF === buffer[8]);
ASSERT(0x00 === buffer[9] || 0xFF === buffer[9]);
ASSERT(0x00 === buffer[10] || 0xFF === buffer[10]);
ASSERT(0x00 === buffer[11] || 0xFF === buffer[11]);
ASSERT(0x00 === buffer[12] || 0xFF === buffer[12]);
ASSERT(0x00 === buffer[13] || 0xFF === buffer[13]);
ASSERT(0xF8 === buffer[14] || 0xF7 === buffer[14]);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[15] || 0xFF === buffer[15]);
ASSERT.ok(isNaN(buffer.readDoubleBE(0)));
ASSERT.ok(isNaN(buffer.readDoubleLE(8)));
}
test(Buffer);
|