forked from realpdai/JavaKeeper
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfloat64.js
More file actions
77 lines (72 loc) · 2.29 KB
/
float64.js
File metadata and controls
77 lines (72 loc) · 2.29 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
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
//? if (FLOAT64) {
// types/floats/float64
/**
* Writes a 64bit float.
* @param {number} value Value to write
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
* @returns {!ByteBuffer} this
* @expose
*/
ByteBufferPrototype.writeFloat64 = function(value, offset) {
//? RELATIVE();
if (!this.noAssert) {
if (typeof value !== 'number')
throw TypeError("Illegal value: "+value+" (not a number)");
//? ASSERT_OFFSET();
}
//? ENSURE_CAPACITY(8);
//? if (NODE) {
this.littleEndian
? this.buffer.writeDoubleLE(value, offset, true)
: this.buffer.writeDoubleBE(value, offset, true);
//? } else if (DATAVIEW)
this.view.setFloat64(offset, value, this.littleEndian);
//? else
ieee754_write(this.view, value, offset, this.littleEndian, 52, 8);
//? RELATIVE(8);
return this;
};
//? if (ALIASES) {
/**
* Writes a 64bit float. This is an alias of {@link ByteBuffer#writeFloat64}.
* @function
* @param {number} value Value to write
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
* @returns {!ByteBuffer} this
* @expose
*/
ByteBufferPrototype.writeDouble = ByteBufferPrototype.writeFloat64;
//? }
/**
* Reads a 64bit float.
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
* @returns {number}
* @expose
*/
ByteBufferPrototype.readFloat64 = function(offset) {
//? RELATIVE();
if (!this.noAssert) {
//? ASSERT_OFFSET(8);
}
//? if (NODE) {
var value = this.littleEndian
? this.buffer.readDoubleLE(offset, true)
: this.buffer.readDoubleBE(offset, true);
//? } else if (DATAVIEW)
var value = this.view.getFloat64(offset, this.littleEndian);
//? else
var value = ieee754_read(this.view, offset, this.littleEndian, 52, 8);
//? RELATIVE(8);
return value;
};
//? if (ALIASES) {
/**
* Reads a 64bit float. This is an alias of {@link ByteBuffer#readFloat64}.
* @function
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
* @returns {number}
* @expose
*/
ByteBufferPrototype.readDouble = ByteBufferPrototype.readFloat64;
//? }
//? }