Return to calculator                         Calculator Differences

About Rolf's Calculator

This calculator was written using JavaScript by Rolf Howarth, 4 March 1996.

To switch from scientific to logical display press the 'HEX' key. To switch back to scientific mode press the 'DEC' key twice.

I wrote the author of the calculator:

The only problem I have found with this awesome JavaScript is a cosine display error:

cos 90o = 0,  NOT wpe2.jpg (1845 bytes) 

The problem is just one of accuracy and display, it's not a 'bug'. The result given (6e-17) pretty much IS zero, to 16 decimal places! (Mathematically, trig functions are actually defined and calculated in terms of radians, so I suspect the problem is that 90 degrees or pi/2 is irrational and doesn't have an exact representation in computer notation, hence the inaccuracy).

-Rolf Howarth

This makes sense.

wpe2.jpg (1845 bytes) = 0.00000006123031769

This is indeed a very small number and when rounded even to the nearest 1/10 000 000 it  is still equal to zero!!

This applet illustrates several JavaScript features:
  • the use of a client-side image map for the keypad
  • the use of cookies (to store the calculator's memory)
  • how to format numeric output (controlling the number of decimal places, which is quite a task in JavaScript, and outputting in other bases such as hex and binary)
  • launching new windows without a toolbar to simulate a floating palette
  • how to prevent users from typing into output fields.

A fully featured scientific calculator is implemented, including trig functions and logarithms, factorials, 12 levels of parentheses, logs to base 2 (one of my favourite functions!), bitwise logical operators, hex, octal, binary and ascii display.

(Warning: you may occasionally notice strange results in the Windows version due to problems with its floating point implementation.)


Disclaimer All the above code is copyrighted, but may be freely used and distributed provided no charge is made
for them. They are provided 'as is' for educational purposes only and no warranty as to their fitness for any
particular use is given.