From: mustafa@seas.smu.edu (Mustafa Kocaturk)
Subject: Re: NO NUMBERS! (or even SHORT INTS!)
Summary: bc - an arbitrary precision calculator with a C-like syntax
Keywords: pi calculator precision
Organization: SMU School Of Engineering and Applied Science
Date: Sun, 11 Oct 1992 19:29:31 GMT

In article <1992Oct7.211144.27881@alchemy.chem.utoronto.ca> mroussel@alchemy.chem.utoronto.ca (Marc Roussel) writes:
>
>     Hmmph.  I like to compute my own constants as much as possible, but
>this sort of thing is dangerous.  At the very least you would have to
>make sure you do this right (using some sort of series summation method
>and doing careful error control, presumably in some exact arithmetic
>system).  I would not want to rely on the value of PI generated by some
>application of inverse trig functions nor would I want to sum a series
>for PI in floating point arithmetic.  On most machines, this would be
>OK, but it's not too hard to find hardware/compiler combinations that
>are ridiculously poor at evaluating some functions for extreme values
>of the arguments.  It is probably best in all but the most unusual of
>cases to simply get a well-authenticated value of PI valid to some large
>number of digits, type it in once, verify it many times (from
>different sources) and use that consistently thereafter.
>
>				Marc R. Roussel
>                                mroussel@alchemy.chem.utoronto.ca

There are software tools that give more precision than that available
in hardware.  The arbitrary precision calculator utility `bc' that is
available on Unix systems, for example, can perform floating point
calculations with precision up to 56 decimal digits.
I think results obtained from inverse tangent routines written in the `bc'
language would be reliable enough for use even with double precision floating
point in compiled code.

I am running the command `bc -lm' with the following input lines,
where a(x) is the arctangent function.

scale = 56 ;
4*a(1);

and here is the result, which is supposed to be close to pi
up to 56 decimal points:

3.14159265358979323846264338327950288419716939937510582096

and with scale set to 99 we obtain:

3.141592653589793238462643383279502884197169399375105820974944592307816\
406286208998628034825342117060

The difference shows up at the 56'th digit after the decimal point, which
is the last significant digit in the first example. IMHO, it would be safe
to round the last digit off.

You can authenticate these values (or your compiler/math library/(FP hardware),
whichever you doubt most ;-) ) by writing simple test programs
with maximum available FP precision. I suppose you can also use sources like
CRC Mathematical Tables for more digits of pi after the decimal point.

The routine for a(x) in the math library file (/usr/lib/lib.b) of `bc'
uses series summation. The same library, accessed by using the `-lm' option,
also provides Bessel, Exponential, Logarithm, Sine and Cosine functions.
User defined functions can be defined in a script file or on the fly, using
single-character identifiers an a familiar, C-like syntax. Finally,
`bc' implements floating point arbitrary precision in *software*,
so the results should be machine-independent.

Yours respectfully,
-- 
Mustafa KOCATURK  mustafa@seas.smu.edu   Electrical Engineering Department
Home:(214)706-5954  Work:(214)692-2541   SMU Box 753190, Dallas, TX 75275-3190