-
Notifications
You must be signed in to change notification settings - Fork 0
/
16-bit-precision.html
49 lines (49 loc) · 1.25 KB
/
16-bit-precision.html
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
<!DOCTYPE html>
<html>
<head>
<title>16 Bit Precision</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<style>
body {background-color: #222; position: relative; left: 10px; width: 90vw; height: 90vh;}
a, div, h1, p, span {color: #fff; font-family: verdana;}
span {width: 105px; line-height: 20px; display: inline-block; font-size: 50%; font-family: arial; text-align: center; vertical-align: top; position: relative; right: 6px;}
</style>
</head>
<body>
<h1>16 Bit Precision</h1>
<p>See all possible 16 bit floating point values in ascending binary order. (Warning: Lag!)</p>
<script>
function text(txt) {
let span = document.createElement("span");
span.innerText = String(Number(txt).toFixed(50).replace(/^0+(?!\.)|(?:\.|(\..*?))0+$/gm, "$1")) + "\n";
document.body.appendChild(span);
}
let sign = 1;
for (l = 0; l < 2; l++) {
let mantissa = 0;
for (j = 0; j < 64; j++) {
for (i = 0; i < 16; i++) {
text(mantissa * 2 ** -24 * sign);
mantissa++;
}
}
let exponent = -24;
for (k = 0; k < 30; k++) {
mantissa = 1024;
for (j = 0; j < 64; j++) {
for (i = 0; i < 16; i++) {
text(mantissa * 2 ** exponent * sign);
mantissa++;
}
}
exponent++;
}
text(mantissa * Infinity * sign);
for (j = 0; j < 1023; j++) {
text(NaN);
}
sign -= 2;
}
</script>
</body>
</html>