www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Corrected pi.d

There were a few deficiencies in the pi.d sample, including the display 
error pointed out by Sampsa.

I took the opportunity to modify the sample to show off dynamic array
size language feature of D.  I also noticed that there is a calculation
error on the last digit, so I modified the source to calculate one more
digit than it would display.  This seems to solve the most egregious and
obvious errors.  (i.e. PI does not equal 3.12, it should be 3.14).

I added a little checking so that we don't try to compute a negative
number of digits--and print out a nice message.  Also, instead of
forcing someone to never compute more than 4000 digits, I had it able
to compute any number of digits the user entered.  Although, it does
print out a warning "Be prepared to wait a while..." if the number is
larger than 4000.

While I can't vouch for the perfectness of the math (I did nothing to
change it), it no longer outputs obviously wrong info when low precision
is used.

Please include it in the next version release samples.
Jul 23 2004