-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (33 loc) · 973 Bytes
/
index.js
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
/* @flow */
import hashFloat64 from "../../hash-functions/float64";
import type Backing from "backing";
import type {Realm} from "../..";
export function make ({PrimitiveType}: Realm): PrimitiveType<float64> {
return new PrimitiveType({
name: 'Float64',
byteAlignment: 8,
byteLength: 8,
cast (input: any): float64 {
return +input || 0;
},
accepts (input: any): boolean {
return typeof input === 'number' && !isNaN(input);
},
store (backing: Backing, address: float64, value: number): void {
backing.setFloat64(address, +value || 0);
},
load (backing: Backing, address: float64): float64 {
return backing.getFloat64(address);
},
emptyValue (): float64 {
return 0;
},
randomValue (): float64 {
return ((Math.random() * Math.pow(2, 16)) * Math.pow(2, 8)) - Math.random() * Math.pow(2, 24)
},
hashValue: hashFloat64,
flowType () {
return `float64`;
}
});
}