May 01, 2024, 03:08:52 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


DOUBLE in print()?

Started by Sebe, January 11, 2007, 05:21:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Sebe

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?

Parker

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?

Ionic Wind Support Team

January 11, 2007, 05:53:34 PM #2 Last Edit: January 11, 2007, 06:05:05 PM by Paul Turley
SETPRINTDECIMALS( 15 );

Or use the USING function
Ionic Wind Support Team

Ionic Wind Support Team

And the operators are there, listed in the users guide as well.
Ionic Wind Support Team

Sebe

Both issues covered. Thank you verrrrrrry much  :D

GWS

By the way Sebe .. try:


pi = 4 * atan(1)


all the best, :)

Graham
Tomorrow may be too late ..

Sebe

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.

GWS

Ah! .. just practising eh?  :) :)  .. you're welcome ..

all the best,

Graham
Tomorrow may be too late ..

GPA

January 13, 2007, 12:39:52 PM #8 Last Edit: January 13, 2007, 01:04:18 PM by GPA
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?

Ionic Wind Support Team

In a Windows program under Aurora use the WriteText method of the CWindow class.  Format the text using USING or NumToStr

Paul.
Ionic Wind Support Team

GPA