Fork me on GitHub

JavaScript Calculator: Calc SS3

Calc SS3
Google Chrome™ Edition


This extension for Google Chrome™ is a CSS3 remake of the well known iPhone™ calculator.
This scientific calculator works just like most other calculators of its kind and probably
doesn't need any further explanations ;o). Find some more info/help by clicking the ? in the left top corner of the calculator extension's screen or see the 'Using the Calculator' section below.

For now this online demo here only works with Chrome, Safari, Shiira and FireFox browsers!!
In FireFox 3.x it's super slow... it takes forever to render, therefore typing is slow, but it works.

0
Rad
>
.
?
2nd
(
)
%
1/x
x2
x3
yx
x!
xy
log
sin
cos
tan
ln
sinh
cosh
tanh
ex
Deg
π
EE
Rand
mc
m+
m-
mr
AC
+/–
÷
×
7
8
9
4
5
6
+
1
2
3
=
0
.
^ back to top

Download

chromeCalc SS3
Google Chrome™ Edition


Calc SS3 can be installed directly from Google or from the Google Chrome web store:

See http://dematte.at/CalcSS3 for a clean and nice 1-file demo of Calc SS3

^ back to top

Features

^ back to top

About Precision

This calculator operates with a precision of (only) 15 digits after the decimal point. This is due to a 'problem' with how JavaScript handles floating point numbers.
This isn't actually a Javascript feature but a feature of the way the IEEE define how floating point numbers are stored in memory. Any language using this definition suffers from this 'feature', for instance C does as well and since JavaScript is often implemented in C so does JavaScript.

The problem is that Javascript is using 32 bits of data which have 4294967296 different combinations to hold any value in the range 1.7976931348623158e+308 to 2.2250738585072014e–308.
It does this by using a smaller presision value and using some of the bits as a exponent (this can also be done in 16 bits with a smaller range and less presision) which results in it being able to approximate any value in the range but not exactly represent them all (because in real number terms the are an infinaite number of values between any 2 given values).
As part of your calculcation clearly the internal representation of the value is going outside the available presision and you are ending up with an approximation to the value instead of an exact value.

See following links that explain this situation more precise:

Getting around this would mean to programm a high precission calculation engine which would slow down the calculations dramandously and blow up the script, or to send the calculations to an external calculator (as web services, Ajax request or so) which would aslo slow down the calculations and would make this calculator an 'online' programm, which you probably wouldn't want to have.

Most 'real' calculators as the TI-30X or the HP 12c have a 'displayed' precission of <= 10 digits (internal it's higher though) which relativizes this problem here anyhow...

Reducing the precission down to 15 digits solves some issues (people commonly like to point out) like:
0.1 + 0.2 = 0.30000000000000004 or
2.01 - 2 = 0.009999999999999787.
But there are still some calculations that are not precise enough for 15 digits after the decimal point:
15.99 + 1 = 16.990000000000002

I could reduce the accuracy down to 14 digits to avoid confusion, but... well.

^ back to top

Speed issues

This calculator's skin is made with DIVs and CSS3 only. Most of those StyleSheet commands take a longer time to be rendered in FireFox. This is a reason why the reaction time of the virtual key board and the input through the 'real' key board seems to be a little slow. Although not too slow so that I'd have to change the technology to something else like real images or realizing it with canvas or SVG.
This way it might be a little slow with some older computers or on FF but still very small and simple.
My intentions to program this were actually to practices CSS3 features and to be able to realize a draft.

See http://dematte.at/CalcSS3 for a clean, nice and even faster 1-file version of Calc SS3

^ back to top

iPhone calc issue(s)

The calculator of the iPhone (OS4) has some weird issues. One of them is the continuous equation calculation: So, if you type 1+1= you expect 2. If you hit = again it's 3, so the last operation (+1) is being continued. But, what if you do 2*(3+4)=... it's 14 and again =...
Well, in this case it doesn't make sense to see +4 as the last operation because it's part of a parentheses,
so, *(3+4) or better *7 would be the last operation which would (should) cause the result of 98 to be correct (=686=4802...).

The iPhone calc has two different (weird) results to offer, depending on closeing the last bracket or not:
2*(3+4)=14=21=28... and
2*(3+4 =14=18=22
This doesn't quite make sens!? In the first case you get the result of the parentheses, so 7 but with the wrong operand (+), the last one typed in... and in the second case you get the last operand and last number typed in as operand and value even though it's only a part of the parentheses.
Both results are not comprehensible and I'd say, incorrect.

The second obvious issue is x!
There is no factorial of floating point values... but with the iPhone calc there is...?
Calc SS3 rounds the input first to calculate with an integer.

There are some more issues with the iPhone calc, like the white ring around the 'mr' even though the result is 0 (so: mc 8 m+ m- causes the iPhone to still have the ring around 'mr' even though 'mr' returns zero), or the missing ring around the '(' when a parentheses is active, which is no bug but a missing feature,... but then, it has a higher precision then javaScript.^ back to top

Using the Calculator [version: 0.9.95]

Click on numbers and functions in Calculator just as you would with a standard calculator.
When you click the add, subtract, multiply, or divide button (in scientific mode also: yx, x√y, EE and the opened round bracket), a white ring appears around the button to let you know the operation to be carried out. The ring around the opened round bracket will stay until all parentheses expressions are closed.

This calculator uses an algebraic method of entry that allows you to enter mathematical sequences in the same order that they are algebraically stated (PEMDAS / AOS™).
PEMDAS: "Parentheses, Exponents, Multiplication or Division, and Addition or Subtraction". Multiplication and division have the same ranking. Addition and subtraction as well.

Hovering the ? symbol will bring up more options (> and .).

Switch between the 4 digit grouping modes (1 234.5), (1 234,5), (1,234.5) or (1.234,5) by clicking the circle on the left (showing the modes . , ,. or .,) or by typing [h, Shift+G]

Click on the > or < sign in the left side of the display, double-click the display or hit [TAB] to toggle between scientific and simple calculator.

Keyboard support

There is full keyboard support for each button on the calculator.

Standard Functions

The stored number, the display, all constant and pending operations and the key states remain in memory when you switch between the standard and scientific calculators and even if you turn the calculator 'off' by loosing focus of the app or hitting the 'Esc' key.

Scientific Calculator Keys

Click on the > or < sign in the left side of the display, double-click the display or hit [TAB] to toggle between scientific and simple calculator.

^ back to top