When you look at your pocket calculator and it is from the 'scientific' type you will find a key for π (pi). π is a constant whose value is the ratio of any circle's circumference to its diameter. Pi is needed to do some geometric calculations.
Pi is an irrational number, which means that its value cannot be expressed exactly as a fraction of m/n (where m and n are integers). Because pi written as decimal is a never ending number, it's 'tail' can also be used to create an endless count of numbers. Some systems use pi to create pseudo random numbers used for games or in cryptography.
The same can be said from sqrt(2) and any sqrt((m+1)/m).
DB is missing a constant for π (pi) but if you are programming geometric formulas in programs, or you are using cryptographic algorithms pi can be a handy thing to use.
There are two ways to approach the problem of getting a representation of pi, you can use a constant
#constant pi# 3.1415926535897932384626433832795
or a calculation
pi# = 22/7 :` Result=3.1428571428571428571428571428571 accuracy 100.04% / error: 0.04%
Using the constant will be good enough for most geometric calculations in a computer, because the mathematical accuracy of a processor is limited and even if you use more precise representations of pi the result will not become more exact.
As an example this simple program shows what DBP does
#constant pi 3.1415926535897932384626433832795
mypi# = 22./7.
` as strings
`------------
pis$=str$(pi)
mypis$=str$(mypi#)
` Output
`--------
print "PI(constant) = 3.1415926535897932384626433832795"
print
`Resulting 'numbers'
print "nummerical representation"
print
print pi
print mypi#
print
`Resulting Strings
print "string representation"
print
print "pi ="+pis$
print "22/7="+mypis$
sync
suspend for key
end
Result
as you can see converting the constant pi to a string already changes its value after the 7th decimal position. Which is caused by the internal representation of real numbers. The same happens to the 22/7 from Archimedes.
There are severalt methods to approach mathematically more accurate results.
As example
for pi you could start to code a program that will calculate a approximation. One of the simpler ways is to start with a square and to calculate the length of its borders. Then use a pentagram, then a hexagon … and so on becoming more accurate with each corner you add to the calculations.
But then how, do you store such a result in a number or a string? A string would be handy because you could easily access any position of the string.
Does anyone has an idea?