-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfloat3test.html
More file actions
61 lines (55 loc) · 1.77 KB
/
Copy pathfloat3test.html
File metadata and controls
61 lines (55 loc) · 1.77 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Float 3 Adds Test</title>
</head>
<body>
<script type="module">
const a = 0.7221859097480774;
const b = 0.1175905168056488;
const c = -0.8397552371025085;
const ar = Math.fround(a);
const br = Math.fround(b);
const cr = Math.fround(c);
console.log("a b c", a, b, c);
console.log("a+b+c", a + b + c);
console.log("a+(b+c)", a + (b + c));
console.log("ar+br+cr", ar + br + cr);
console.log("ar+(br+cr)", ar + (br + cr));
let f32a = new Float32Array([
0.7221859097480774, 0.1175905168056488, -0.8397552371025085,
]);
console.log("f32a: a+b+c", f32a[0] + f32a[1] + f32a[2]);
const sm = 0.000001;
const lg = 1000000;
console.log("sm + lg", sm + lg);
const smr = Math.fround(sm);
const lgr = Math.fround(lg);
console.log("smr + lgr", smr + lgr);
let smlg = new Float32Array([sm, lg]);
let smlgout = new Float32Array(1);
console.log("f32: sm + lg", smlg[0] + smlg[1]);
smlgout[0] = smlg[0] + smlg[1];
console.log("f32: Float32Array(sm + lg)", smlgout[0]);
const f32array = new Float32Array(3);
const op = (a, b) => {
f32array[1] = a;
f32array[2] = b;
f32array[0] = f32array[1] + f32array[2];
return f32array[0];
};
console.log("op: f32: Float32Array(sm + lg)", op(sm, lg));
const t0 = new Float32Array(1);
const t1 = new Float32Array(1);
const t2 = new Float32Array(1);
function fadd(a, b) {
t0[0] = a;
t1[0] = b;
t2[0] = t0[0] + t1[0];
return t2[0];
}
console.log("fadd op: f32: Float32Array(sm + lg)", fadd(sm, lg));
</script>
</body>
</html>