forked from davidcarlisle/html5mathml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongadd.html
executable file
·126 lines (110 loc) · 3.12 KB
/
longadd.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<!-- MathML mlongdiv generator
may be distributed under the MIT licence
-->
<html xmlns:m="http://www.w3.org/1998/Math/MathML" >
<head>
<title>MathML addition mstack generator</title>
<style>
td {
border: solid thin black;
padding-left: 1em;
padding-right: 1em;
}
</style>
<object id=MathPlayer classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987" title="MathPlayer"></object>
<?import namespace="m" implementation="#MathPlayer" ?>
<script>
function padtol (s,l) {
var v = "";
for (var tmp = s; tmp< l; tmp++) {
v = v + " ";
}
return v;
}
function longadd() {
var istr = document.getElementById("i").value.replace(/[^0-9]/g,'');
var jstr = document.getElementById("j").value.replace(/[^0-9]/g,'');
il=istr.length;
jl=jstr.length;
var ans="";
var carry="";
var c=0;
var m = Math.max(il,jl)+1;
for (k=1;k<=m;k++){
carry=((c==0)? " " : "1") + carry;
tmp=parseInt((k>il)? 0 : istr.charAt(il-k)) + parseInt((k>jl)? 0 : jstr.charAt(jl-k)) + c;
d=(tmp<10)? tmp : tmp-10;
if(k<m || d==1) ans = d + ans;
c=(tmp<10)? 0 : 1;
}
var mline="";
for(k=0;k<m;k++){
mline=mline + "-";
}
var aaaa = document.getElementById("a");
aaaa.innerHTML= "\n" +
padtol((istr+ "").length,m) + istr + " \n" +
padtol((jstr+ "").length,m) +jstr + " +\n" +
mline + "\n" +
padtol((ans+ "").length,m) + ans + "\n" +
mline + "\n" +
padtol((carry+ "").length,m) + carry + "\n";
var bbbb = document.getElementById("b");
bbbb.innerHTML= "\n<math xmlns='http://www.w3.org/1998/Math/MathML'>" +
"\n<mstack>" +
"\n<mn>" +istr + "</mn>" +
"\n<msrow><mn>" +jstr + "</mn><mo>+</mo></msrow>" +
"\n<msline length=\"" + m + "\"/>" +
"\n<mn>" +ans + "</mn>" +
"\n<msline length=\"" + m + "\"/>" +
"\n<mscarries>" +carry.replace(/^ */,'').replace(/1/g,'<mn>1</mn>').replace(/ /g,'<none/>') + "</mscarries>" +
"\n</mstack>" +
"\n</math>\n" ;
var cccc = document.getElementById("c");
cccc.innerHTML= "\n<math xmlns='http://www.w3.org/1998/Math/MathML'>" +
"\n<mstack>" +
"\n<mn>" +istr + "</mn>" +
"\n<msrow><mn>" +jstr + "</mn><mo>+</mo></msrow>" +
"\n<msline length=\"" + m + "\"></msline>" +
"\n<mn>" +ans + "</mn>" +
"\n<msline length=\"" + m + "\"></msline>" +
"\n<mscarries>" +carry.replace(/^ */,'').replace(/1/g,'<mn>1</mn>').replace(/ /g,'<none></none>') + "</mscarries>" +
"\n</mstack>" +
"\n</math>\n" ;
}
window.addEventListener('load', longadd, false);
</script>
<script src="html5mathml.js"></script>
</head>
<body>
<p>
<input type="text" id="i" width="15" value="12345">
+
<input type="text" id="j" width="10" value="325"><br>
<button id="submit" text="submit" onclick="longadd();">Update</button>
</p>
<table border>
<thead>
<tr>
<th>ASCII</th>
<th>MathML Markup</th>
<th>MathML Rendering</th>
</tr>
</th>
<tbody>
<tr>
<td><pre id="a"></pre></td>
<td><pre id="b"></pre></td>
<td><div id="c"></div>
</tr>
<tr>
<td><pre id="a2"></pre></td>
<td><pre id="b2"></pre></td>
<td><div id="c2"></div>
</tr>
</tbody>
</table>
</body>
</html>