With this app you can solve expressions without any floating point innaccuracies or implicit approximations.
Calculate "pi", and you will be given an answer of 3.14159265359
But everyone knows that Pi has more than 11 decimal places?!
Calculate "10 / 3", and you will be told that the answer is exactly 3.33333333333
But everyone knows that the 3 should recur forever, not just 11 times?!
Calculate "10^20 + 1", and you will be told that the answer is exactly 1e+20
But 1e+20 = 10^20
. Where did my + 1
go?
Did this calculator just ignore me?!
$ do-math-right
> PI
=> 3.1415926536 ± 1/10000000000
The symbol ±
denotes plus or minus
, which is an explicit annotation of the accuracy of the result.
Therefore if your project only requires an accuracy of 0.0001
units, you can use this result with confidence.
$ do-math-right
> 10/3
=> 3.(3)
The decimal (3)
denotes 3 recurring
, which describes an infinitely repeating pattern in the decimal.
Therefore regardless of the accuracy of your project, you can use this result with confidence.
$ do-math-right
> 10*10*10*10*10*10*10*10*10*10*10*10*10*10*10*10*10*10*10*10+1
=> 100000000000000000001
The numbers in this application are not stored as traditional fixed size floating points.
Therefore this calculator can theoretically perform operations accurately on numbers infinitely large.
All numbers are converted to their fractional representations using the formula (n * 10^d) / (10^d)
, where n
is the decimal number, and d
is the number of decimal places.
3 + 2
becomes(3/1) + (2/1)
0.2
becomes(2/10)
Numbers in this app can be infinitely large because they are not constrained by the conventional 64 bit size constraints of a floating point in hardware.
Every number x
has an associated accuracy y
where x ± y
.
A result of x ± y
implies that the exact result lies between n - x
and n + x
.
- Whole numbers such as
2
would be2 ± 0
(which simplifies to2
) - Approximations such as
Pi
would be3.14 ± 1/100
The app never operates on decimals, it is only used as an optional method of representing the result.
10 / 3
represented decimally is3.(3)
22 / 7
represented decimally is3.14285 ± 1/100000
All irrational numbers (Pi) and approximate functions (sine) cannot be represented fractionally and therefore have innaccuracies, and when those approximations are operated on they can rapidly become very inaccurate. So to achieve higher accuracies the solver will repeat your calculation with increasingly accurate approximations until the requirement is met.
E.g. PI * 100
may internally resolve to 314.159 ± 1/1000
, because we only generate Pi to 5 DP. But if our accuracy requirement is 1/100000
, this result will not satisfy us. So the solver will re-evaluate with a more accurate approximation of Pi, it achieves our desired result of 314.159 ± 1/100000
.
- Whitespace is ignored
- Negative numbers
(-1)
must be wrapped in parentheses- otherwise there is ambiguity:
-5^2
could be-(5^2) = -25
or(-5)^2 = -25
- otherwise there is ambiguity:
- Decimal numbers between
1
and-1
must precede with0
- the number
.2
will fail to be parsed, where the number0.2
will succeed
- the number
- Constants
PI
are all upper case - Functions
SIN(1)
are all upper case, and arguments are wrapped in parentheses
stack install
stack build
stack test
Arithmetic:
- whole numbers
100
- basic operators
+
-
/
*
- scoping operators
(
)
- decimal numbers
1.0
- constants
PI
- functions
SIN(180)
Modes:
- answer type
APPROXIMATE(1)
APPROXIMATE(0)
- required accuracy
SETDP(10)
- angle units
IN_RADIANS(..)
IN_DEGREES(..)
Interactivity:
- input and output loop
- use last result with
ANS
- arrow key support
Display:
- output in Latex syntax
- expression syntax errors
Research:
- Can we determine the required accuracy of irrational numbers or function approximations before generating the first result