### PI routines

- Posted by Robert Craig <robert_craig at COMPUSERVE.COM> Mar 24, 1997
- 554 views

James Powell writes: > However, there is a *minor* bug in the Euphoria version that I > cannot quite figure out. It seems that it does not want to properly > calculate the last two (2 :) ) digits of PI. ie, when calculating to 50 > digits, PI.EX responds with: > 3.141592653589793238462643383279502884197169399374 > but PI.BAS returns: > 3.1415926535897932384626433832795028841971693993751 In the Basic version you say "OPTION BASE 0" (which is the default anyway I believe). This means that when the user asks for 50 digits, you calculate using an array dimensioned from 0 to 50, i.e. *51* digits. At the end you only print from 0 to 49, so only 50 digits are displayed. The 51st digit which may not be very accurate, is not displayed. In the Euphoria version you calculate PI with a sequence that is indexed from *1* to 50, i.e. only 50 digits. You then print elements 1 to 49, i.e. only 49 digits. You'll notice above that the Euphoria output has one less digit displayed. If you add 1 to the number of digits requested by the Euphoria user, the Euphoria and QBasic programs will have identical results. Thanks for the interesting benchmark. Rob Craig Rapid Deployment Software