-
Notifications
You must be signed in to change notification settings - Fork 16
/
jmat_console.html
165 lines (144 loc) · 5.44 KB
/
jmat_console.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>Jmat.js Console</title>
<style type="text/css">
body {
color: #444;
margin: 0;
font: 16px Monospace, sans-serif
}
</style>
</head>
<body>
<script type="text/javascript" src="jmat_real.js" ></script>
<script type="text/javascript" src="jmat_complex.js" ></script>
<script type="text/javascript" src="jmat_matrix.js" ></script>
<script type="text/javascript" src="jmat_quaternion.js" ></script>
<script type="text/javascript" src="jmat_special.js" ></script>
<script type="text/javascript" src="jmat_bigint.js" ></script>
<script type="text/javascript" src="jmat.js" ></script>
<script type="text/javascript" src="jmat_plot.js" ></script>
<script type="text/javascript" src="jmat_test.js" ></script>
<script type="text/javascript">
/*
Copyright (c) 2011-2020, Lode Vandevenne
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
function makeElement(parent, tag) {
var el = document.createElement(tag);
parent.appendChild(el);
return el;
}
function makeRelElement(px, py, parent, tag) {
var el = document.createElement(tag);
el.style.position = 'relative';
el.style.left = '' + Math.floor(px) + 'px';
el.style.top = '' + Math.floor(py) + 'px';
parent.appendChild(el);
return el;
}
function makeRelDivAt(px, py, parent) {
return makeRelElement(px, py, parent, 'div');
}
function makeBlockDivAt(px, py, parent) {
var el = makeBlockDiv(parent);
el.style.paddingLeft = '' + Math.floor(px) + 'px';
el.style.paddingTop = '' + Math.floor(py) + 'px';
parent.appendChild(el);
return el;
}
function makeBlockDiv(parent) {
var el = document.createElement('div');
parent.appendChild(el);
return el;
}
var evalContainer = makeBlockDiv(document.body);
var area = makeElement(evalContainer, 'textarea');
area.style.width = '500px';
area.style.height = '50px';
var button = makeRelDivAt(0, 5, evalContainer);
button.innerHTML = 'eval';
button.style.textAlign = 'center';
button.style.backgroundColor = '#eee';
button.style.border = '1px solid black';
button.style.width = '50px';
button.style.height = '20px';
var result = makeBlockDivAt(0, 10, evalContainer);
result.style.width = '500px';
result.style.wordWrap = 'break-word';
button.onclick = function() {
var before = new Date().getTime();
var a = eval(area.value);
var after = new Date().getTime();
var time = (after - before) / 1000;
a = '' + a;
var resultsize = (a.length > 1) ? (' (size: ' + a.length + ' chars)') : '';
var evaluated = (time > 0.5) ? (' (evaluated in ' + ((after - before) / 1000) + 's)') : '';
a = a.replace(/\n/g, '<br/>').replace(/ /g, ' ');
result.innerHTML = 'answer' + evaluated + resultsize + ':<p/>' + a;
};
var examples = makeBlockDivAt(0, 10, evalContainer);
examples.style.color = '#aaa';
examples.style.width = '1000px';
examples.style.fontSize = 'small';
examples.innerHTML = 'Examples:<br/>' +
'<ul>' +
'<li>BigInt.factorial(\'10000\') </li>' +
'<li>Complex(\'1+2i\').add(Complex(\'3+4i\')) </li>' +
'<li>Jmat.besselj(5, Complex(5.5, 1)) </li>' +
'<li>Jmat.fft([[1,2],[3,4]]).toString()</li>' +
'<li>Jmat.eig([[1,2],[3,4]]).l.toString()</li>' +
'<li>Jmat.gamma(5.5).add(Jmat.trigamma(5.5)) </li>' +
'<li>Jmat.factorize(30030) </li>' +
'</ul>';
info = makeBlockDivAt(0, 10, document.body);
info.style.width = '500px';
info.innerHTML = 'This software is provided \'as-is\', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.<p/>' +
'Copyright (c) 2011-2015 by Lode Vandevenne.';
function localStorageSupported() {
try {
return 'localStorage' in window && window['localStorage'] != null;
} catch(e) {
return false;
}
}
function setLocalStorage() {
if(!localStorageSupported()) return;
localStorage['jmat_console_value'] = area.value;
}
//no longer a cookie, but html5 local storage
function getLocalStorage() {
if(!localStorageSupported()) return;
area.value = localStorage['jmat_console_value'] || '';
}
window.onbeforeunload = setLocalStorage;
getLocalStorage();
B = Jmat.BigIntC || Jmat.BigInt;
C = Jmat.Complex;
Q = Jmat.Quaternion;
M = Jmat.Matrix;
R = Jmat.Real;
</script>
</body>
</html>