-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
68 lines (63 loc) · 1.72 KB
/
demo.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>cnum demo</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" href="./src/style.css" />
</head>
<body>
<h1>cnum demo</h1>
<p>
<em>cnum v<span id="version">0.0.0</span></em>
</p>
<script src="./dist/index.umd.js"></script>
<script>
const tests = {}
</script>
<h2>Rat</h2>
<h3>Create and Reduce</h3>
<pre id="rat-init" class="output"></pre>
<script>
const Rat = cnum.Rat
tests['rat-init'] = () => {
const out = []
const n = 6, d = 9
const r = new Rat(n, d)
out.push(`new Rat(${n}, ${d})`)
out.push('')
out.push(`toString: ${r}`)
out.push(`valueOf: ${+r}`)
return out
}
</script>
<h3>Multiply</h3>
<pre id="rat-mul" class="output"></pre>
<script>
tests['rat-mul'] = () => {
const out = []
const n1 = 71, d1 = 7
const n2 = 35, d2 = 113
out.push(`a = new Rat(${n1}, ${d1})`)
const a = new Rat(n1, d1)
out.push(`b = new Rat(${n2}, ${d2})`)
const b = new Rat(n2, d2)
out.push(`c = a.mul(b)`)
const c = a.mul(b)
out.push('')
out.push(`toString: ${c}`)
out.push(`valueOf: ${+c}`)
return out
}
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('version').innerText = cnum.version
for (const [id, test] of Object.entries(tests)) {
const out = document.getElementById(id)
out.innerHTML = test().join('\n')
}
})
</script>
</body>
</html>