Making a Calculator
Compute basic functions using arithmetic operations.
Question
How can familiar functions be computed when a program is allowed to use only basic arithmetic?
Goals
- Implement roots, trigonometric functions, exponentials, and logarithms from arithmetic operations.
- Compare approximation methods and measure their numerical error.
Method
Build the calculator one mathematical routine at a time.
- Use iteration for roots and series approximations for functions such as sine, cosine, and the exponential.
- Reduce inputs to useful ranges and choose a clear stopping rule.
- Test the output against reference values and report where the approximation becomes inaccurate.
Try an example
Calculator!
Build numbers one digit at a time and apply one arithmetic operation at a time, just as a basic calculator does.
Controls: Click the number and operation keys. Use = to finish a calculation, BACK to remove the last digit, and C to clear.