A student recently emailed me with this related question. Thought the answer may also interest others.
___
Hi Dr.McDonald,
I got a question out of interest inspired by a lab question. We know that calculating the floating number is inaccurate in computer. I was thinking how the computing software works like Mathematica, which is wildly used in computing area and its really powerful. I also known Mathematica is written in C and Java. So, how do we solve this kind of problem caused by floating numbers.
___
There's a number of libraries, and programming languages, that support what's termed multi-precision arithmetic, or arbitrary precision arithmetic, supporting both 'infinitely large' integers, and floating-point values with an 'unlimited' number of decimal places. Often these libraries will recognise standard values, such as
e
,
sqrt(2)
, and
1 / pi
as exact values, and perform their arithmetic using symbolic computation, where they can, rather than converting the values to imprecise approximations.
Here's a good list:
https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software
Here's an example of using the standard
bc
utility to calculate
the first 1000 digits of pi:
time bc -l <<< "scale=1000;4*a(1)"
Hope this helps,