forked from fingerecho/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprecision.js
More file actions
41 lines (36 loc) · 1.24 KB
/
precision.js
File metadata and controls
41 lines (36 loc) · 1.24 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
QUnit.test('WebGL Decimal Precision', function(assert) {
var gpu = new GPU({mode: 'webgl'});
var add = gpu.createKernel(function(a, b) {
return a + b;
}).setOutput([1]);
var addResult = add(0.1, 0.2)[0];
assert.equal(addResult.toFixed(7), (0.1 + 0.2).toFixed(7));
var reflectValue = gpu.createKernel(function(a) {
return a;
}).setOutput([1]);
//Just for sanity's sake, recurse the value to see if it spirals out of control
for (var i = 0; i < 100; i++) {
var newAddResult = reflectValue(addResult)[0];
assert.equal(newAddResult, addResult);
addResult = newAddResult;
}
gpu.destroy();
});
QUnit.test('WebGL2 Decimal Precision', function(assert) {
var gpu = new GPU({mode: 'webgl2'});
var add = gpu.createKernel(function(a, b) {
return a + b;
}).setOutput([1]);
var addResult = add(0.1, 0.2)[0];
assert.equal(addResult.toFixed(7), (0.1 + 0.2).toFixed(7));
var reflectValue = gpu.createKernel(function(a) {
return a;
}).setOutput([1]);
//Just for sanity's sake, recurse the value to see if it spirals out of control
for (var i = 0; i < 100; i++) {
var newAddResult = reflectValue(addResult)[0];
assert.equal(newAddResult, addResult);
addResult = newAddResult;
}
gpu.destroy();
});