more integer spaces  | | |
June 26th, 2003, 03:51 PM
|
#1 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: York, PA.
Posts: 1,569
|
I am trying to determine the value of Pi, just for the heck of it. The problem I am running into is the number of spaces that I can use. Code:
dim answer
answer = 22 / 7
msgbox (answer)
I tried writing it to a txt file but still get limited by a set amount of spaces. Is there a way to tell it to use X amout of spaces for the answer.
Here is what I have for writing to the txt file Code: dim answer
Function WriteLineToFile
Const ForReading = 1, ForWriting = 2
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\my documents\scripts\testfile.txt", ForWriting, True)
f.WriteLine answer
Set f = fso.OpenTextFile("c:\my documents\scripts\testfile.txt", ForReading)
WriteLineToFile = f.ReadAll
End Function
answer = 22 / 7
writelinetofile
any ideas on how I can do this? |
| |
June 27th, 2003, 01:40 AM
|
#2 (permalink)
| | Banned
Join Date: Oct 2001
Posts: 447
|
sure,
make a circle, measure the area.
determine PI.
a=PI*r**2.
OR
PI=a/r**2??? |
| |
June 27th, 2003, 06:59 PM
|
#3 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: York, PA.
Posts: 1,569
|
qball
what I am trying to do is have the above script run and determine Pi to the 100th place value.
When I run the script I get this for an answer
3.14285714285714
It repeats which we all know is not supposed to happen with Pi. |
| |
June 27th, 2003, 07:22 PM
|
#4 (permalink)
| | Thaumaturge Member
Join Date: Oct 2001 Location: West Haven, Utah
Posts: 15,330
|
That doesn't look right. Pi isn't 22/7, that's just an approximation.
This is pi (ok, just the beginning of pi): 3.14159265358979
But I don't know how to answer your question about getting it to display (or write to a file) to the 100th decimal. |
| |
June 28th, 2003, 01:45 AM
|
#5 (permalink)
| | Banned
Join Date: Oct 2001
Posts: 447
| Quote: |
what I am trying to do is have the above script run and determine Pi to the 100th place value.
| how do you think they built the pyramids?
oops, that was easier.
to determine any number to any degree, one must have place to put?
so you need 101+ memory locations? store each value, right?
pi has been defined to the nth degree.
think of it this way, or not.
9999999999999999999999999999999999999999999999999
is a huge number.
9999999999999999999999999999999999999999999999999
is a small string. |
| |
June 28th, 2003, 12:58 PM
|
#6 (permalink)
| | Ultimate Member
Join Date: Oct 2002 Location: Scotland, UK
Posts: 3,221
|
Pi is normally calculated by means of a series (normally the Chudnovskys brothers' method - can't remember how to spell it)
You need to watch out for rounding errors, and I would advise you to look hard at your floating-point handling code. The standard library functions aren't good enough for this, so do some research into fp arithmatic in binary form and how the computer works with it. Code: double calculate_pi(int terms) {
double calcpi = x =0;
for(i==n: i = 0:i++)
x = 4 * (-1) ^ i / (2 * i + 1);
calcpi += x ;
return calcpi; }
As you can see, this is constructed from a series. It is dependant on the number of terms to what accuracy. If you are indeed just using double, then you may want to truncate the number at each term to avoid rounding errors.
__________________
_____
NuKeS
|
| |
June 29th, 2003, 12:58 AM
|
#7 (permalink)
| | Banned
Join Date: Oct 2001
Posts: 447
| Quote: |
Pi is normally calculated by means of...
| so, nobody tried?
"make a circle, measure the area." |
| |
June 29th, 2003, 01:29 AM
|
#8 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: York, PA.
Posts: 1,569
|
It seems that everyone is stuck on Pi.
It can be any number I just need to know how to make more places for the numbers.
If I have any division problem that when calculated needs the answer to be to the 23 place value. How do I add those places values with out the script rounding off till then.
I only used Pi because that is one that I know will reach way out there, as far a digits.
So I am not so much worried about how to figure out Pi, but am more interested in finding out how to have an answer have an unlimited amount of digits. |
| |
June 29th, 2003, 01:36 AM
|
#9 (permalink)
| | Bringing Da Funk
Join Date: Feb 2003 Location: Da Bronx, NY
Posts: 3,985
| |
| |
June 29th, 2003, 10:53 PM
|
#10 (permalink)
| | Banned
Join Date: Oct 2001
Posts: 447
|
Gait_Keeper,
whoa! awesome links.
korgul,
good enough answer.
The only time I had to calc PI was only a simple programming exercise to 7/8/9 digits.
I have to believe most calcs of PI will ultimately store result in some sort of string var(maybe more than one var). as in:
String result = "":
//code to calc PI 1 digit at a time.
result += digit;
//test result not getting bigger than string, if bigger, use a string array
print result; |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |