Why don't I get the whole number but only 3.14?
global sub main()
{
print("PI calculation");
print("with the Bailey-Borwein-Plouffe formula");
print("implemented in Aurora by Sebe");
print("");print("");
print("Setting variables...");
def should_be_PI as DOUBLE;
should_be_PI = 3.1415926535897932;
def our_PI as double;
our_PI = 0.0;
def our_k as double;
our_k = 0.0;
def term1 as double;
term1 = 0.0;
def term2 as double;
term2 = 0.0;
def term3 as double;
term3 = 0.0;
def term4 as double;
term4 = 0.0;
print("");print("");
print("Starting calculation...");
do
{
term1 = 4.0/((8.0*our_k)+1.0);
term2 = 2.0/((8.0*our_k)+4.0);
term3 = 1.0/((8.0*our_k)+5.0);
term4 = 1.0/((8.0*our_k)+6.0);
our_PI = our_PI + ((1.0/(16.0^our_k))*(term1-term2-term3-term4));
our_k = our_k + 1.0;
print(our_PI);
}
until our_PI = should_be_PI;
while getkey() = "";
}
And can we please get +=, -=, etc. operators?
There's a command called setprintdecimals or something like that (I don't quite remember). And there are +=, -=, *=, /= operators (as well as ++ and --). Have you tried it?
SETPRINTDECIMALS( 15 );
Or use the USING function
And the operators are there, listed in the users guide as well.
Both issues covered. Thank you verrrrrrry much :D
By the way Sebe .. try:
pi = 4 * atan(1)
all the best, :)
Graham
Thank you graham but the BBP formula is an excelent exercise when learning a new languag because you need to use loops, floating point variables, math operators etc.
This is not meant to be a serious programm :D
But again: thanks, 4*atan(1) is much faster and also as precise for float or double.
Ah! .. just practising eh? :) :) .. you're welcome ..
all the best,
Graham
I actually had this question just the other day. I guess it's true when they say in class, never be afraid to ask a question because if you have that question someone else does too! I wonder if this is just a limit when using the console or is it also needed for window based programs as well? Or perhaps it is a limit of PRINT? In other words do we need to use USING in a Windows program?
In a Windows program under Aurora use the WriteText method of the CWindow class. Format the text using USING or NumToStr
Paul.
Thanks!