JavaScript Calculator Documentation

User Interface
Supported Functions
Input Errors
About The JavaScript Calculator

 

User Interface

input

The expression placed in the input text box is the expression that is calculated.

result

The result text box displays the result of the calculated expression.

clear

When clear is pressed, the values in each text box are cleared.

compute

When compute is pressed, the expression in the input text box is calculated and the answer is displayed on the result text box.

Area 1: Calculator Pad

The buttons on the calculator pad place characters and expressions into the input text box for building expressions for calculation.

Area 2: Memory Recall

An "M" button saves the current value displayed on the result text box. When a "MR" button is pressed, that value is then placed on the input text box, which can then be used in the current calculation.

Area 3: Extra Commands

Combinations: the C( n , m ) area evaluates to n! / ( (n - m)! * n! ).
Permutations: the P( n , m ) area evaluates to n! / (n - m)!
Factorial: the ( n )! area returns the factorial of n.
Reduced Fractions: The ( n ) / ( m ) area returns the equivalent fraction in reduced form.

Supported Functions

sin(x), asin(x), sinh(x), asinh(x), cos(x), acos(x), acosh(x), cosh(x), tan(x), atan(x), tanh(x), atanh(x), cot(x), acot(x), coth(x), acoth(x), sec(x), asec(x), sech(x), asech(x), csc(x), acsc(x), csch(x), acsch(x), ln(x), exp(x), log(x), sqrt(x)
sq(x) { return x * x; }
inv(x) { return 1/x; }
ip(x) { return Math.floor(x); }
fp(x) { return x - Math.floor(x); }
abs(x) { return x >= 0 ? x : -x; }
sgn(x) { return x == 0 ? 0 : (x > 0 ? 1 : -1); }

Input Errors

Input Error 1
Empty Parentheses - Make sure there is no empty parenthesis pair "()"

Input Error 2
Parentheses don't match - Make sure to each right parenth "(" there is associated a unique left parenth ")"

Input Error 3
Invalid substring in input � Make sure there is no illegal characters or expressions in the input. See above Supported Functions for legal expressions.

The "Special Characters" are: "^*/+-."
"Binary" Special Characters: "^*/+"
�Unitary� Special Character: "-"
Peculiar Special Character: "."

Input Error 4.1
Special character at end of input - Each special character cannot be at the end of input.

Input Error 4.2
Binary operator cannot follow a special character - each special character cannot be followed by a BINARY special character, but "." is even more strict, dealt with in #4 below

Input Error 4.3
Invalid decimal number - "." may be preceded by any special character except "." (itself), also, numbers may not have more than one decimal point.

Input Error 4.4
Decimal point is not followed by a whole number - the standalone text "10." is invalid, this is dealt with if "." is at the end of the input, in Input Error 4.1 above.

Input Error 4.5
"(" cannot precede a binary operator - "(" cannot precede a BINARY special character

Input Error 4.6
A binary operator cannot be followed by a ")" - each special character cannot be followed by ")". "." dealt with in Input Error 4.5.

About the JavaScript Calculator

The parser in this calculator is a slightly modified version of Partrick Dostert's code that he used to create a javascript math parser for his javascript function plotter.

We greatfully acknowledge his permission for the use of his code in our project.

Both e and pi are supported, and expressions such as epixcos(pie^x)-2x+x^pi will be converted to e*pi*x*cos(pi*exp(x))-2*x+pow(x,pi) with numerical values substituted for e and pi, and the function calls made for the cosine and the exponential functions.

Questions regarding the calculator can be sent to Joshua Haddick - joshua_haddick@yahoo.com, Jatindera Singh Walia - jatindera_walia@hotmail.com, Jeff Morgan - jmorgan@math.uh.edu