IonicWind Software

Aurora Compiler => Coding Help - Aurora 101 => Topic started by: Sebe on January 11, 2007, 05:21:44 PM

Title: DOUBLE in print()?
Post by: Sebe on January 11, 2007, 05:21:44 PM
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?
Title: Re: DOUBLE in print()?
Post by: Parker on January 11, 2007, 05:28:38 PM
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?
Title: Re: DOUBLE in print()?
Post by: Ionic Wind Support Team on January 11, 2007, 05:53:34 PM
SETPRINTDECIMALS( 15 );

Or use the USING function
Title: Re: DOUBLE in print()?
Post by: Ionic Wind Support Team on January 11, 2007, 06:03:04 PM
And the operators are there, listed in the users guide as well.
Title: Re: DOUBLE in print()?
Post by: Sebe on January 11, 2007, 06:16:51 PM
Both issues covered. Thank you verrrrrrry much  :D
Title: Re: DOUBLE in print()?
Post by: GWS on January 12, 2007, 01:52:22 AM
By the way Sebe .. try:


pi = 4 * atan(1)


all the best, :)

Graham
Title: Re: DOUBLE in print()?
Post by: Sebe on January 12, 2007, 05:24:10 AM
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.
Title: Re: DOUBLE in print()?
Post by: GWS on January 12, 2007, 06:49:55 AM
Ah! .. just practising eh?  :) :)  .. you're welcome ..

all the best,

Graham
Title: Re: DOUBLE in print()?
Post by: GPA on January 13, 2007, 12:39:52 PM
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?
Title: Re: DOUBLE in print()?
Post by: Ionic Wind Support Team on January 13, 2007, 01:54:31 PM
In a Windows program under Aurora use the WriteText method of the CWindow class.  Format the text using USING or NumToStr

Paul.
Title: Re: DOUBLE in print()?
Post by: GPA on January 13, 2007, 02:06:57 PM
Thanks!