-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
600 lines (591 loc) · 20.2 KB
/
index.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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
<html manifest="uncertainty_calculator.appcache">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Calculate uncertainties easily with this calculator - Just use it like a normal one!">
<link rel="shortcut icon" href="assets/favicons/favicon.ico">
<link rel="apple-touch-icon" sizes="57x57" href="assets/favicons/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="114x114" href="assets/favicons/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="72x72" href="assets/favicons/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="144x144" href="assets/favicons/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="60x60" href="assets/favicons/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="120x120" href="assets/favicons/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="76x76" href="assets/favicons/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="152x152" href="assets/favicons/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon-180x180.png">
<link rel="apple-touch-startup-image" href="assets/favicons/splash.png">
<meta name="apple-mobile-web-app-title" content="Uncertainty Calculator">
<link rel="icon" type="image/png" href="assets/favicons/favicon-192x192.png" sizes="192x192">
<link rel="icon" type="image/png" href="assets/favicons/favicon-160x160.png" sizes="160x160">
<link rel="icon" type="image/png" href="assets/favicons/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="assets/favicons/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="assets/favicons/favicon-32x32.png" sizes="32x32">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-TileImage" content="assets/favicons/mstile-144x144.png">
<meta name="msapplication-config" content="assets/favicons/browserconfig.xml">
<meta name="application-name" content="Uncertainty Calculator">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="translucent-black">
<meta name="apple-mobile-web-app-title" content="Uncertainty Calculator">
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<meta http-equiv="cleartype" content="on">
<script type="text/javascript" src="assets/uncertainty.js"></script>
<script type="text/javascript" src="assets/IntervalArithmetic.js"></script>
<link rel="shortcut icon" href="assets/favicon.ico" />
<title>Olly's Uncertainty Calculator</title>
<link rel="stylesheet" type="text/css" media="screen" href="assets/screen.css">
<script type="text/javascript" src="assets/jquery-1.10.1.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55184680-1', 'auto');
ga('send', 'pageview');
</script>
<script type="text/javascript">
// Disable context menu on android
for (var i=0; i<$('button').length; i++)
if(navigator.userAgent.match(/Android/i))
$('.button')[i].addEventListener('contextmenu', function (e) { e.preventDefault() })
$(document).ready(function()
{
$('.calculator .button').click(handleButtonClick);
$('body').keypress(handleKeyPress);
$('.solar div').mouseover(start_drain);
$('.solar div').mouseout(stop_drain);
});
function start_drain(e)
{
clearInterval(drainID);
drainID = setInterval(drain,1000);
}
function stop_drain(e)
{
clearInterval(drainID);
drainID = setInterval(un_drain,1000);
}
function drain()
{
if (battery > 0 )
{
battery--;
update_screen(battery);
}
}
function un_drain()
{
battery++;
update_screen(battery);
if (battery>=20)
{
clearInterval(drainID);
}
}
function update_screen(level)
{
var screen=$('.calculator .screen textarea');
switch (level)
{
case (18):
screen.css({'background-color':'#E2E9BA'});
break;
case (15):
screen.css({'background-color':'#A8AE8A'});
break;
case (10):
screen.css({'background-color':'#4A4C3D'});
break;
case (5):
screen.css({'background-color':'#000000'});
$('body').css({'background-color':'#FFFFFF'});
break;
case (0):
$('body').css({'background-color':'#000000'});
break;
default:
break;
}
}
var drainID;
var battery=20
var ans=false;
var last_answer=false;
var realMode=false;
var historyStack=[''];
var historyIndex=0;
function handleKeyPress(e)
{
var keyCode = e.which || e.key || e.keyCode;
// Handle enter, but not shift-enter
if (keyCode == 13 && !e.shiftKey) {
e.preventDefault();
calculate();
}
// Ctrl Z
else if (keyCode == 26 && e.ctrlKey) {
e.preventDefault();
var screen=$('.calculator .screen textarea');
if (historyIndex<historyStack.length){
historyIndex++;
}
var new_exp = historyStack[historyStack.length-(historyIndex)];
if (new_exp!==undefined) {
screen.val(new_exp);
}
}
// Ctrl Y
else if (keyCode == 25 && e.ctrlKey) {
e.preventDefault();
var screen=$('.calculator .screen textarea');
if (historyIndex>0){
historyIndex--;
}
var new_exp = historyStack[historyStack.length-(historyIndex)];
if (new_exp!==undefined) {
screen.val(new_exp);
}
}
ans=false;
hide_links();
}
function handleButtonClick(e)
{
e.preventDefault();
var button=$(e.target).closest('.button').text();
input(button);
}
function input(button)
{
var isinput=true;
if (button!=='=' && button.indexOf('Scientific')===-1){hide_links();}
switch (button)
{
case ('='):
if (!ans)
calculate();
isinput=false;
break;
case ('Turn On Real Mode'):
isinput=false;
realMode=true;
$('.calculator .buttons.sci #real_mode').text('Turn Off Real Mode');
break;
case ('Turn Off Real Mode'):
isinput=false;
realMode=false;
$('.calculator .buttons.sci #real_mode').text('Turn On Real Mode');
break;
case ('Show Memory'):
isinput=false;
$('.calculator #memory').text('Hide Memory');
var toWidth=parseInt($('#memoryBank').width());
$('#memoryBank').css({'width':0,'display':'block','padding-left':0,'padding-right':0});
$('#memoryBank').animate({'width':toWidth,'padding':10},400,'swing',function(){$('#memoryBank').css('width','auto')});
break;
case ('Hide Memory'):
isinput=false;
$('.calculator #memory').text('Show Memory');
$('#memoryBank').animate({'width':0,'padding-left':0,'padding-right':0},400,'swing',function(){$('#memoryBank').css({'width':'auto','display':'none','padding':10})})
break;
case ('\u00B1(abs)'):
button='\u00B1';
break;
case ('\u00B1(rel)'):
button='\u00B1/';
break;
case ('\u00B1(%)'):
button='\u00B1%';
break;
case ('10x'):
button='10^';
if (ans)
button+='(ANS)';
break;
case ('DEL'):
isinput=false;
if (ans)
$('.calculator .screen textarea').val('');
else
var screen = $('.calculator .screen textarea');
screen.val(screen.val().substring(0,screen.val().length-1));
break;
case ('AC'):
isinput=false;
$('.calculator .screen textarea').val('');
last_answer=false;
ans=false;
break;
case ('+'):
if (ans)
button='ANS'+button;
else
button=button;
break;
case ('-'):
if (ans)
{
button='ANS'+button;
}
break;
case ('\u00F7'):
if (ans)
button='ANS'+button;
else
button=button;
break;
case ('\u00D7'):
if (ans)
button='ANS'+button;
else
button=button;
break;
case ('^'):
if (ans)
button='ANS'+button;
break;
case ('ex'):
button='e^';
if (ans)
button+='(ANS)';
break;
case ('Show Scientific'):
isinput=false;
toggle_scientific();
break;
case ('Hide Scientific'):
isinput=false;
toggle_scientific();
break;
case ('sin'):
if (ans)
button=button+'(ANS)';
break;
case ('cos'):
if (ans)
button=button+'(ANS)';
break;
case ('tan'):
if (ans)
button=button+'(ANS)';
break;
case ('log'):
if (ans)
button=button+'(ANS)';
break;
case ('ln'):
if (ans)
button=button+'(ANS)';
break;
case ('\u221A'):
if (ans)
button=button+'ANS';
break;
default:
break;
}
var screen=$('.calculator .screen textarea');
if (isinput)
{
screen.val((ans?'':screen.val())+button);
ans=false;
}
if (screen.val().indexOf('ANS')!==-1)
{
show_ANS_value();
} else if ($('.calculator .ans_value').css('display')!=='none') {
hide_ANS_value();
}
}
function raw_input(s)
{
var screen=$('.calculator .screen textarea');
screen.val(screen.val()+s);
}
function calculate()
{
// Send Analytics
ga('send', 'event', 'button', 'click', 'Equals');
// Calculate!
var screen=$('.calculator .screen textarea');
var expression=screen.val();
historyStack.push(expression);
historyIndex=0;
try
{
if (expression.indexOf('ANS')!==-1)
{
if (last_answer)
{
expression=expression.replace(/ANS/g, (last_answer.value+'\u00B1'+last_answer.uncertainty));
} else {
screen.val('ERROR');
throw "Answer isn't set";
}
}
// Abs all uncertainties
expression=expression.replace(/±\w*[-+]/g, '±');
var answer=parseExpression(expression);
screen.val(answer.value+'\u00B1'+answer.abs_uncertainty());
ans=answer;
last_answer=answer;
show_links();
} catch (e) {
console.log(e);
ans=true;
last_answer=false;
screen.val('ERROR');
}
}
function show_links()
{
$('.ans_links').css('visibility','visible');
}
function hide_links()
{
$('.ans_links').css('visibility','hidden');
var l=$('.ans_links a:nth-child(2)');
l.text('Show Relative');
}
function toggle_relative()
{
var screen=$('.calculator .screen textarea');
var l=$('.ans_links a:nth-child(2)');
if (l.text().indexOf('Absolute')==-1)
{
l.text('Show Absolute');
screen.val(ans.value+"(\u00B1"+ans.per_uncertainty()+"%)");
} else {
l.text('Show Relative');
screen.val(ans.value+"\u00B1"+ans.abs_uncertainty());
}
}
function round_to_final()
{
var screen=$('.calculator .screen textarea');
var l=$('.ans_links a:nth-child(2)');
if (l.text().indexOf('Absolute')==-1)
{
var unc=ans.abs_uncertainty(1);
var absolute=true;
} else {
var unc=ans.per_uncertainty(1);
var absolute=false;
}
if (unc===0)
{
screen.val(ans.value+'\u00B1'+unc);
return;
}
var dp_in_unc = parseInt(Math.log(unc)/Math.LN10); // -ve if < 0, otherwise how many 0s
var rounded_value=parseInt(Math.round(ans.value/Math.pow(10,dp_in_unc-1)))*Math.pow(10,dp_in_unc-1);
if (absolute)
{
screen.val(rounded_value+'\u00B1'+unc);
} else {
screen.val(rounded_value+'(\u00B1'+unc+'%)');
}
}
function toggle_scientific()
{
var l=$('.button.sci');
if (l.text().indexOf('Show')!==-1){
l.text('Hide Scientific');
$('.buttons.sci').animate({'height':132},400,'swing',fade_in);
} else {
l.text('Show Scientific');
$('.buttons.sci table').fadeOut(slide_away);
}
}
function fade_in()
{
$('.buttons.sci table').fadeIn();
}
function slide_away()
{
$('.buttons.sci').animate({'height':0});
}
function show_ANS_value()
{
$('.calculator .ans_value .value').text(last_answer?last_answer:'NONE');
$('.calculator .ans_value').fadeIn();
}
function hide_ANS_value()
{
$('.calculator .ans_value').fadeOut();
}
function mem_store (container) {
if (ans){
container.text(ans);
update_mem_display();
}
}
function mem_clear (container) {
container.text('Empty');
update_mem_display();
}
function mem_use (container) {
if (ans){
$('.calculator .screen textarea').val(container.text());
} else {
$('.calculator .screen textarea').val($('.calculator .screen textarea').val()+container.text());
}
}
function update_mem_display() {
var allFull=true;
$('#memoryBank .membox').each(function(){
var mem = $(this);
var val_cell = mem.children().first();
var hasContents = val_cell.text()!=="Empty";
mem.empty();
mem.append(val_cell);
var button = $('<span />');
if (hasContents) {
mem.append( $('<span />').addClass('use').text('Use').attr('onclick','mem_use($(this).prev())') );
mem.append( $('<span />').addClass('clr').text('Clear').attr('onclick','mem_clear($(this).prev().prev())') );
} else {
allFull=false;
mem.append( $('<span />').addClass('sto').text('Store').attr('onclick','mem_store($(this).prev())') );
}
});
if (allFull) {
var newRow = $('#memoryBank .memBox').last().clone();
newRow.empty();
newRow.append( $('<span />').addClass('cell').text('Empty') );
newRow.append( $('<span />').addClass('sto').text('Store').attr('onclick','mem_store($(this).prev())') );
$('#memoryBank').append(newRow);
}
}
</script>
</head>
<body>
<table class="frame">
<tr>
<td>
<table class="calculator" cellspacing="7px;">
<tr><td colspan='2' class='cite'><a href='http://www.ollyfg.com'>from Olly F-G</a> v1.4</td><td class="solar" colspan='3'><div></div><div></div><div></div><div></div></td></tr>
<tr>
<td class="screen" colspan='5'>
<textarea></textarea>
<div class='ans_links'>
<a onclick="round_to_final()">Round To Final Answer</a>
<a onclick="toggle_relative()">Show Relative</a>
</div>
<div style="height:1em"><div class="ans_value">ANS = <span class="value"></span></div></div>
</td>
</tr>
<tr>
<td class="button sci" colspan='5'>Show Scientific</td>
</tr>
<tr class='buttons sci'>
<td colspan="5">
<table style="width:235px;" cellspacing="10px;">
<tr>
<td class="button">^</td>
<td class="button">√</td>
<td class="button">10<sup>x</sup></td>
<td class="button">log</td>
<td class="button">ln</td>
</tr>
<tr>
<td class="button">sin</td>
<td class="button">cos</td>
<td class="button">tan</td>
<td class="button">π</td>
<td class="button"><i>e<sup>x</sup></i></td>
</tr>
<tr>
<td class="button" id="real_mode" colspan="5">Turn On Real Mode</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="button">(</td>
<td class="button">)</td>
<td class="button">±</td>
<td class="button" colspan="2" id="memory">Show Memory</td>
</tr>
<tr>
<td class="button">7</td>
<td class="button">8</td>
<td class="button">9</td>
<td class="button del">DEL</td>
<td class="button del">AC</td>
</tr>
<tr>
<td class="button">4</td>
<td class="button">5</td>
<td class="button">6</td>
<td class="button">×</td>
<td class="button">÷</td>
</tr>
<tr>
<td class="button">1</td>
<td class="button">2</td>
<td class="button">3</td>
<td class="button">+</td>
<td class="button">-</td>
</tr>
<tr>
<td class="button">0</td>
<td class="button">.</td>
<td class="button">ANS</td>
<td class="button eq" colspan='2'>=</td>
</tr>
</table>
<div id="memoryBank"><table>
<tr><th>Memory</th></tr>
<tr><td class="hint">Click "Store" to save an answer in one, and <br />"Use" to insert it back into the calculator</td></tr>
<tr><td class="memBox">
<span class="cell">Empty</span>
<span class="sto" onclick="mem_store($(this).prev())">Store</span>
</td></tr>
</table></div>
</td>
</tr>
<tr>
<td style="text-align:center;">
<a onclick='$(".help.this").slideToggle()'><h2>How do you use this calculator?</h2></a>
<div class="help this">
<p>Just like a real one!</p>
<p>The only big difference is that you can click the ± button and then enter the (absolute) uncertainty for that value. </p>
</div>
<a onclick='$(".help.what").slideToggle()'><h2>What is an uncertainty?</h2></a>
<div class='help what'>
<p>In real life, you can't measure something perfectly.
Take a moment to think about that. Take a ruler for example - you can measure that a pencil is 15cm long,
you can probably measure that it's 15.1cm if you look closely. But can we say that the pencil is 15.100000cm long?
No, we can't, because we aren't sure if all those 0's are actually 0, they could be 5's, of 9's or anything!</p>
<p>So what can we do about this?
This is where uncertainties come in. when we can say that the pencil is 15.1cm long <i>plus or minus</i> 0.05cm!
What this means is that the actual length of the pencil could be anywhere between 15.1+0.05cm (15.15cm) and 15.1-0.05cm (15.05cm).
In mathematical terms we use the funny ± symbol to mean plus or minus, so our pencil length would be this: 15.01±0.05cm.</p>
<p>Now when someone comes along with a fancy new super-ruler, and says "Aha! This pencil isn't 15.1cm long, it's 15.09cm long!" we can
still say that we're right, because 15.09 is between 15.05 and 15.15.</p>
<p>This is why it's always important to record the uncertainty of things that you measure, because it means that you always know exactly
<i>how</i> exact your measurement is (smaller uncertainties mean a more exact measurement).</p>
</div>
<a onclick='$(".help.real_mode").slideToggle()'><h2>What is "real mode"?</h2></a>
<div class="help real_mode">
<p>The way to calculate uncertainty estimates that I was taught at university was wrong (or at least very simplified for certain uses).
By default this calculator still uses this way, as it is what I use it most for, however, by using "real mode" you can calculate more accurate error estimates.
The real mode uses a type of mathematics called "interval arithmetic", which bascially means that we are doing maths with ranges of numbers.
The actual maths is pretty complicated, and I don't pretend to understand it all, but by standing on the shoulders of giants
(<a href="https://github.com/Jeff-Tian/JavaScriptIntervalArithmetic">Jeff Tian</a>), I have managed to build it into this calculator. In most cases you shouldn't
see massive differences, except when dealing with very large errors.</p>
<p>It should be noted that real mode is much better at dealing (correctly) with errors in exponents, square roots, logs, and all those more advanced functions.</p>
</div>
<a onclick='$(".help.contact").slideToggle()'><h2>I've found a bug, or have a suggestion!</h2></a>
<div class="help contact">
<p>Wonderful! Please send me an email either by filling in the form on <a href="http://ollyfg.com/#contact">my website</a>, or just
send me an email at <a href="mailto:[email protected]">[email protected]</a>. I love hearing about bugs and improvements people want,
as it means that this calculator will always be improving.</p>
<p>If you yourself know your way around javascript, you can feel free to make changes and submit pull
requests to this calculator on <a href="https://github.com/ollyfg/Uncertainty-Calculator">Github</a>.</p>
</div>
</td>
</tr>
</table>
</body>
</html>