-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_gpm.html
More file actions
311 lines (295 loc) · 10.8 KB
/
calc_gpm.html
File metadata and controls
311 lines (295 loc) · 10.8 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<html>
<head>
<title>Calcolatore GPM</title>
</head>
<style type="text/css">
* {
padding: 0;
margin: 5px;
text-align: center;
}
body {
background-color: <!-- #ff9933; -->
}
.calculatore {
width: 330px;
height: 280px;
background-color: <!-- #c0c0c0; -->
box-shadow: 0px 0px 0px 10px #666;
border: 2px solid black;
border-radius: 10px;
}
#display {
width: 300px;
height: 40px;
text-align: left;
background-color: black; <!-- black; sfondo risultati-->
border: 3px solid white;
font-size: 18px;
left: 2px;
top: 2px;
color: #7fff00;
}
.btnTop{
color: white;
background-color: #6433FF; <!-- alternativa orig #6f6f6f; -->
font-size: 14px;
margin: auto;
width: 50px;
height: 25px; <!--in origine avevo messo 25px-->
}
.btnNum {
color: white;
background-color: #1F1066; <!-- black; tasti num.-->
font-size: 14px;
margin: auto;
width: 50px;
height: 25px;
}
.btnMath {
color: white;
background-color: #641273; <!-- #ff4561; -->
font-size: 14px;
margin: auto;
width: 50px;
height: 25px;
}
.btnOpps {
color: white;
background-color: #5D5472; <!-- #ff9933; -->
font-size: 14px;
margin: auto;
width: 50px;
height: 25px;
.btnOpps2 {
color: white;
background-color: #5D5472; <!-- #ff9933; -->
font-size: 14px;
margin: auto;
width: 50px;
height: 25px;
}
</style>
<body>
<!-- <div class = title >Calcolatore GPM per Test Univr</div> -->
<form name="sci-calcolatrice">
<table class="calculatore" cellspacing="1" cellpadding="5" BORDER="0">
<tr> <!-- copyright start -->
<td colspan="6">
<p style="text-align: center; font-size:16px; background-color: #64BFDD; Line-height:15px;">Calcolatore GPM Per Test Univr</p>
</td>
</tr><!-- copyright end-->
<tr>
<td colspan="6"><input id="display" name="display" value="0" size="28" maxlength="25"></td>
</tr>
<tr>
<td><input type="button" class="btnTop" name="btnTop" value="C" onclick="this.form.display.value= 0 "></td>
<td><button type="button" class="btnTop" name="btnTop" value="<--" onclick="deleteChar(this.form.display)">◄−−</button></td>
<td><input type="button" class="btnMath" name="btnMath" value="cos" onclick="if(checkNum(this.form.display.value)) { cos(this.form) }"></td>
<td><input type="button" class="btnMath" name="btnMath" value="sin" onclick="if(checkNum(this.form.display.value)) { sin(this.form) }"></td>
<td><input type="button" class="btnMath" name="btnMath" value="tan" onclick="if(checkNum(this.form.display.value)) { tan(this.form) }"></td>
<td><input type="button" class="btnMath" name="btnMath" value="π" onclick="addChar(this.form.display,'3.14159265359')"></td>
</tr>
<tr>
<td><input type="button" class="btnNum" name="btnNum" value="7" onclick="addChar(this.form.display, '7')"></td>
<td><input type="button" class="btnNum" name="btnNum" value="8" onclick="addChar(this.form.display, '8')"></td>
<td><input type="button" class="btnNum" name="btnNum" value="9" onclick="addChar(this.form.display, '9')"></td>
<td><button type="button" class="btnOpps" name="btnOpps" value="e^" onclick="if(checkNum(this.form.display.value)) { exp(this.form) }"> e<sup>x</sup></button></td>
<td><button type="button" class="btnOpps" name="btnOpps" onclick="if(checkNum(this.form.display.value)) {
uno_su_x(this.form)}">1/x</button></td>
<td><input type="button" class="btnMath" name="btnMath" value="/" onclick="addChar(this.form.display, '/')"></td>
<tr>
<td><input type="button" class="btnNum" name="btnNum" value="4" onclick="addChar(this.form.display, '4')"></td>
<td><input type="button" class="btnNum" name="btnNum" value="5" onclick="addChar(this.form.display, '5')"></td>
<td><input type="button" class="btnNum" name="btnNum" value="6" onclick="addChar(this.form.display, '6')"></td>
<td><input type="button" class="btnOpps" name="btnOpps" value="ln" onclick="if(checkNum(this.form.display.value)) { ln(this.form) }"></td>
<td><button type="button" class="btnOpps" name="btnOpps" onclick="if(checkNum(this.form.display.value)) {
lg(this.form)}">lg</button></td>
<td><input type="button" class="btnMath" name="btnMath" value="*" onclick="addChar(this.form.display, '*')"></td>
</tr>
<tr>
<td><input type="button" class="btnNum" name="btnNum" value="1" onclick="addChar(this.form.display, '1')"></td>
<td><input type="button" class="btnNum" name="btnNum" value="2" onclick="addChar(this.form.display, '2')"></td>
<td><input type="button" class="btnNum" name="btnNum" value="3" onclick="addChar(this.form.display, '3')"></td>
<td><input type="button" class="btnOpps" name="btnOpps" value="√x" onclick="if(checkNum(this.form.display.value)) { sqrt(this.form) }"></td>
<td><button type="button" class="btnOpps" name="btnOpps" onclick="if(checkNum(this.form.display.value)) {
sqrt_y(this.form)}"><sup>n</sup>√x </button></td>
<td><input type="button" class="btnMath" name="btnMath" value="-" onclick="addChar(this.form.display, '-')"></td>
</tr>
<tr>
<td><input type="button" class="btnMath" name="btnMath" value="±" onclick="changeSign(this.form.display)"></td>
<td><input type="button" class="btnNum" name="btnNum" value="0" onclick="addChar(this.form.display, '0')"></td>
<td><input type="button" class="btnMath" name="btnMath" value="." onclick="addChar(this.form.display, '.')"></td>
<td><button type="button" class="btnOpps" name="btnOpps" value="x^2" onclick="if(checkNum(this.form.display.value)) {
square(this.form)}"> x<sup>2</sup></button></td>
<td><button type="button" class="btnOpps" name="btnOpps" onclick="if(checkNum(this.form.display.value)) {
square_y(this.form)}"> x<sup>y</sup></button></td>
<td><input type="button" class="btnMath" name="btnMath" value="+" onclick="addChar(this.form.display, '+')"></td>
</tr>
<tr>
<td><input type="button" class="btnMath" name="btnMath" value="(" onclick="addChar(this.form.display, '(')"></td>
<td><input type="button" class="btnMath" name="btnMath" value=")" onclick="addChar(this.form.display,')')"></td>
<td><input type="button" class="btnMath" name="btnMath" value="%" onclick=" percent(this.form.display)"></td>
<td><button type="button" class="btnOpps" name="btnOpps" onclick="if(checkNum(this.form.display.value)) {
normal_z(this.form)}"> <p style="margin: 0px; text-align: center; font-size:9px; Line-height:8px;">Nor ►Z <br> x/μ/σ</p></button></td>
<td><button type="button" class="btnOpps" name="btnOpps" onclick="if(checkNum(this.form.display.value)) {
cdf_z(this.form)}" > Cdf Z</button></td>
<td><input type="button" class="btnTop" name="btnTop" value="=" onclick="if(checkNum(this.form.display.value)) { compute(this.form) }"></td>
</tr>
</table>
</form>
</body>
<script>
function addChar(input, character) {
if(input.value == null || input.value == "0")
input.value = character
else
input.value += character
}
function cos(form) {
form.display.value = Math.cos(form.display.value);
}
function sin(form) {
form.display.value = Math.sin(form.display.value);
}
function tan(form) {
form.display.value = Math.tan(form.display.value);
}
function sqrt(form) {
form.display.value = Math.sqrt(form.display.value);
}
function sqrt_y(form) {
//form.display.value = Math.sqrt(form.display.value);
globase = form.display.value; //eval(this.form.display.value);
//form.display.value = mybase;
//return mybase;
form.display.value = 'ⁿ' //eval(form.display.value) * eval(form.display.value)
}
function ln(form) {
form.display.value = Math.log(form.display.value);
}
function lg(form) {
form.display.value = Math.log10(form.display.value);
}
function exp(form) {
form.display.value = Math.exp(form.display.value);
}
function uno_su_x(form) {
form.display.value = eval(1/form.display.value);
}
function deleteChar(input) {
input.value = input.value.substring(0, input.value.length - 1)
}
var val = 0.0;
function percent(input) {
val = input.value;
input.value = input.value + "%";
}
function changeSign(input) {
if(input.value.substring(0, 1) == "-")
input.value = input.value.substring(1, input.value.length)
else
input.value = "-" + input.value
}
function square(form) {
form.display.value =eval(form.display.value) * eval(form.display.value)
}
//var globase = square(form)
function normal_z(form) {
var str = form.display.value;
var occure = (str.split("/").length - 1);
if (occure==2) {
var parts = str.split("/", 3);
var the_x = eval(parts[0]);
var the_mean =eval(parts[1]);
var the_var = eval(parts[2]);
var result =eval((the_x - the_mean)/the_var);
form.display.value = result;
return
};//form.display.value = mybase;
//return mybase;
form.display.value = "Insert to Normalize: x/mean/st.dev."; //eval(form.display.value) * eval(form.display.value)
}
function cdf_z(form) {
var j, k, kMax, m, values, total, subtotal, item, z, z2, z4, a, b, cdf_result;
z = eval(form.display.value);
// Power series is not stable at these extreme tail scenarios
if (z < -6) { //return 0; }
form.display.value="0";
return }
if (z > 6) {
form.display.value="1";
return }
m = 1; // m(k) == (2**k)/factorial(k)
b = z; // b(k) == z ** (2*k + 1)
z2 = z * z; // cache of z squared
z4 = z2 * z2; // cache of z to the 4th
values = [];
// Compute the power series in groups of two terms.
// This reduces floating point errors because the series
// alternates between positive and negative.
for (k=0; k<100; k+=2) {
a = 2*k + 1;
item = b / (a*m);
item *= (1 - (a*z2)/((a+1)*(a+2)));
values.push(item);
m *= (4*(k+1)*(k+2));
b *= z4;
}
// Add the smallest terms to the total first that
// way we minimize the floating point errors.
total = 0;
for (k=49; k>=0; k--) {
total += values[k];
}
// Multiply total by 1/sqrt(2*PI)
// Then add 0.5 so that stdNormal(0) === 0.5
result_cdf = 0.5 + 0.3989422804014327 * total;
form.display.value = result_cdf ;
}
function square_y(form) {
globase = form.display.value; //eval(this.form.display.value);
//form.display.value = mybase;
//return mybase;
form.display.value = '^' //eval(form.display.value) * eval(form.display.value)
}
//var globase = square(form)
var globase;
function compute(form) {
var str = form.display.value;
var cha = str.charAt(0);
//var the_string = (form.display.value);
if (cha=="^") {
var parts = str.split('^', 2);
var the_symbol = (parts[0]);
var the_exp = eval((parts[1]));
var mybase2 = globase;
form.display.value = Math.pow(mybase2, the_exp);
return;
}
if (cha=="ⁿ") {
var parts = str.split('ⁿ', 2);
//var the_symbol = (parts[0]);
var the_den = (parts[1]);
var the_exp =eval(1/the_den);
var mybase2 = globase;
form.display.value = Math.pow(mybase2, the_exp);
return;
}
form.display.value =eval(str);
}
function checkNum(str) {
for (var i = 0; i < str.length; i++) {
var ch = str.charAt(i);
if (ch < "0" || ch > "9") {
if (ch != "/" && ch != "*" && ch != "+" && ch != "-" && ch != "."
&& ch != "(" && ch!= ")" && ch != "%" && ch != "^" && ch != "ⁿ" && ch != ";") {
alert("invalid entry!")
return false
}
}
}
return true
}
</script>
</html>