-
-
Notifications
You must be signed in to change notification settings - Fork 687
Expand file tree
/
Copy pathfloat.js
More file actions
31 lines (25 loc) · 658 Bytes
/
float.js
File metadata and controls
31 lines (25 loc) · 658 Bytes
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
/**
* @fileoverview Floating point glue code for JavaScript.
* @license Apache-2.0
*/
/* eslint-disable no-undef */
const F64 = new Float64Array(1);
const F32 = new Float32Array(F64.buffer);
const I32 = new Int32Array(F64.buffer);
globalThis.f32_as_i32 = function f32_as_i32(value) {
F32[0] = value;
return I32[0];
};
globalThis.i32_as_f32 = function i32_as_f32(value) {
I32[0] = value;
return F32[0];
};
globalThis.f64_as_i64 = function f64_as_i64(value) {
F64[0] = value;
return i64_new(I32[0], I32[1]);
};
globalThis.i64_as_f64 = function i64_as_f64(value) {
I32[0] = i64_low(value);
I32[1] = i64_high(value);
return F64[0];
};