I have started to make routines that hopefully will end in a small satellite tracking program to keep track of satellites with radiobeacons and open transponders in the radioamateur bands. Planning to do the needed routines for a ground track first.
When searching for formulas, I managed to get around all the confusion on internet, mixing the different "types" of miles. I even found online calulators out there stating they operated with kilometers and nautical miles, but inspecting the webpage source revealed that their scripts in fact used Statue Miles only!
Since the only length variable used in most of navigation formulas is the Earth Radius, it is easy to get set this straight. Earth Radius given in kilometers, produce results in kilometers. Earth Radius given in nautical miles to get results in nautical miles, and so on.
But I ran into problems when doing the routines for calulating directions (bearings). I think rounding problems are the main reason for this. And maybe the way IWB calculates the PI constant.
Most textbooks agree on the following constants:
Ratio of a circle's circumference to its diameter: PI = 3.1415926535897932384626433832795 .....
Factor to convert decimal degrees to radians: 0.01745329252
Factor to convert decimal degrees to radians: 57.29577951308
I made some test code to see what I can achieve with a precision of 18 decimals. (precision greater than 17 only produce zeros)
A screendump of the output is posted below. Also posted is the code I used for the test.
Some may ask if such insane precision really is needed. The answer is yes. Since the distances to these satellites are so great, I need great precision to get correct calulations for bearing and elevation angles.
So if anyone have ideas or suggestions on how to get around these problems, I'll be very grateful.
'
' trig_test.iwb
'
SETPRECISION 18
OPENCONSOLE
print
print " Degrees to Radians constant: ",Deg2Rad(1)
print
print " Radians to Degrees constant: ",Rad2deg(1)
print
print " PI: ",4*atan(1)
print:print
print "press any key to end"
WAITCON
CLOSECONSOLE
END
'
SUB Rad2deg(rad:FLOAT),float
'----------------------------------------------------------------------------------------
' Convert Degrees to Radians
' PI = 4 * atan(1)
' Returns Degrees in decimal format
'----------------------------------------------------------------------------------------
RETURN rad*180/(4*atan(1))
ENDSUB
'
SUB Deg2Rad(deg:FLOAT),float
'----------------------------------------------------------------------------------------
' Convert Degrees to Radians
' PI = 4 * atan(1)
' deg = Degrees in decimal format
' Returns Radians
'----------------------------------------------------------------------------------------
RETURN (deg*(4*atan(1)/180))
ENDSUB
Egil
I looked at the source code for the atan functions
They are all written in assembly and look like they are using the math coprocessor in the computer.
All I can suggest is using an approximation routine to calculate what you want.
Hope someone else can give you a better answer.
** Ah yes.. I see what you are saying.. it is in the trig function not yielding a proper result. I'm leaving this here anyway for those who would want to print large precision numbers **
The print statement is what is rounding it off. Using SETPRECISION makes no difference above 18.
The maximum value for type float is: 3.40282e+038
The maximum value for type double is: 1.79769e+308
The maximum value for type int is: 2147483647
The maximum value for type short int is: 32767
Try this...
'
' trig_test.iwb
'
SETPRECISION 18
OPENCONSOLE
print
print " Degrees to Radians constant: ",:mPrint(Deg2Rad(1),30)
print
print " Radians to Degrees constant: ",:mPrint(Rad2deg(1),30)
print
print " PI: ",:mPrint(4*atan(1),30)
print:print
print "press any key to end"
WAITCON
CLOSECONSOLE
END
SUB mPrint(num:DOUBLE,prec:BYTE)
Dim i:INT
Dim s:string
s=LTRIM$(str$(int(num)))+"."
num=num-int(num)
for i=1 to prec
num=num*10
s+=LTRIM$(STR$(int(num)))
num=num-int(num)
next i
print s
ENDSUB
'
SUB Rad2deg(rad:DOUBLE),DOUBLE
'----------------------------------------------------------------------------------------
' Convert Degrees to Radians
' PI = 4 * atan(1)
' Returns Degrees in decimal format
'----------------------------------------------------------------------------------------
RETURN rad*180/(4*atan(1))
ENDSUB
'
SUB Deg2Rad(deg:DOUBLE),DOUBLE
'----------------------------------------------------------------------------------------
' Convert Degrees to Radians
' PI = 4 * atan(1)
' deg = Degrees in decimal format
' Returns Radians
'----------------------------------------------------------------------------------------
RETURN (deg*(4*atan(1)/180))
ENDSUB
Later,
Clint
LarryMc,
How do you import a library like this one?
http://www.crbond.com/extended_precision.htm
Maybe Egil could use something like this.
Later,
Clint
Thanks to both of you!
This really gave me something to work on. I really appreciate it.
The most important value in the angular calculations is the PI constant, it is used for setting every variable in the formulas. So maybe I shall define it as a constant with as many desimals I can find in a textbook and drop the atan function.
When the calculated values are ready to be printed, I only need one decimal. So I was relieved to know that I can work internally with very high precision.
And Clint, thanks for the URL. Looks promising, so will study that webpage more thoroughly tomorrow. And the mPrint function really opened my eyes.
That math package is based on a dll.
To make the necessary lib file all you have to do is create it via Tools > Create Import Library from the IDE's Maiin Menu.
The difficult part will be to create the inc file with the proper declarations.
LarryMc,
How do you select all the text in a code window like
the one above? You posted it once, but I cannot find
it. I ever tried different searches.
Bill
Quote from: Bill-Bo on October 25, 2014, 05:38:48 PM
LarryMc,
How do you select all the text in a code window like
the one above? You posted it once, but I cannot find
it. I ever tried different searches.
Bill
put the cursor at the beginning of the 1st line in the code window
hold down the CTRL key
use the mouse to scroll down the code window
while still holding the CTRL key down click at the end of the last line in the code window
now everything should be selected
now hit CTRL-C to copy
It looks like there is too much rounding error in double precision numbers. Even using a constant doesn't help because I don't think everything is converted to double.
Double-precision examples
3ff0 0000 0000 0000 = 1
3ff0 0000 0000 0001 ≈ 1.0000000000000002, the smallest number > 1
3ff0 0000 0000 0002 ≈ 1.0000000000000004
Later,
Clint
LarryMc,
I tried your way on reply #2. The code
is not highlighted and the mouse does
not highlight. All that happens is a blue
rectangle outlines the whole reply. I can
only copy the code by using the mouse
only and clicking at the top of the code
window and drag down to the bottom of
the code, then copy.
Bill
Quote from: ckoehn on October 26, 2014, 05:34:32 AM
It looks like there is too much rounding error in double precision numbers. Even using a constant doesn't help because I don't think everything is converted to double.
That's what I suspect too. But I have been thinking of the way I used to do satellite calulations way before I had a computer. It was done using a slide rule, paper and pencil. Had to break the formulas into several parts to ease work though, but the final results were very accurate.
So tomorrow I'll try to rewrite the code, using that approach.
I'm trying to get a library ported over but I'm having some trouble. Wish someone would do a tutorial (where is Sapero :'() on the conversion.
LarryMc, can you tell me why I'm getting these errors when it tries to link?
I made a library with IWBasic and it installed it in the lib folder.
Then I modified the inc files that came with it (I have them below with the lib) and put $USE "NUMS.lib" at the top of the "NUMS.inc" file.
What am I doing wrong? Does it also need the DLL somewhere? When I tried to regsvr32 the dll it said it loaded but had no entry point.
Compiling...
TrigTest.iwb
No Errors
Linking...
IWBasic Linker v1.11 Copyright © 2011 Ionic Wind Software
Unresolved external __imp_nu_AllocVar
Error: C:\Users\Public\Documents\IWBasic\projects\My Projects\TrigTest\TrigTest.o - Unresolved extern __imp_nu_AllocVar
Error: C:\Users\Public\Documents\IWBasic\projects\My Projects\TrigTest\TrigTest.o - Unresolved extern __imp_nu_PutString_DS
Error: C:\Users\Public\Documents\IWBasic\projects\My Projects\TrigTest\TrigTest.o - Unresolved extern __imp_nu_ATan
Error: C:\Users\Public\Documents\IWBasic\projects\My Projects\TrigTest\TrigTest.o - Unresolved extern __imp_nu_Mul
Error: C:\Users\Public\Documents\IWBasic\projects\My Projects\TrigTest\TrigTest.o - Unresolved extern __imp_nu_GetAny_DS
Error: C:\Users\Public\Documents\IWBasic\projects\My Projects\TrigTest\TrigTest.o - Unresolved extern __imp_nu_UnAllocVar
Error(s) in linking C:\Users\Public\Documents\IWBasic\projects\My Projects\TrigTest\TrigTest.exe
Later,
Clint
OK.. found one problem. All the declares needed to be uppercase.. moving on... moving on...
Now I need to fix some of the way the functions are called...
Later,
Clint
OK, try this. It does have a nag screen but I wanted to try to see if I could convert a dll to a lib.
The bottom PI: is the one that is computed by the precision math library. Everything above it is going to be inaccurate. Look at the code.. you'll know what I mean. :)
LarryMc, how do you pass a string byval instead of byref on a declare import,? I have a few of those in there so some of the strings functions don't work.
Later,
Clint
Quote from: ckoehn on October 26, 2014, 04:43:48 PM
... how do you pass a string byval instead of byref on a declare import,?
When I've ran into that in the past I've had to declare the parameter as a UINT and then do the string like this
declare import mysub(mystring:uint,blah...)
string mystring ="aaaaaa"
mysub(&mystring, blah......)maybe that will work this time
Thanks LarryMc, will try that tomorrow.
Later,
Clint
What I see when starting the exe file looks very good, Clint.
Talked to my grandson last night. He meant that if I could use a atan2 function (taking two arguments), and using doubles, most of these problems will dissapear.
When inspecting your source code I find this statement: nu_ATan(a, b). Looks like that function works similar to the atan2 functions used in C/C++.
Have to study the NUMS documentation a little more...
Any number stored in double precision will be inaccurate, no matter how it gets there.
I have found an issue with this library with some of the functions not working, like nu_GetAny_Double(a). It will not place the return value in a double like it is suppose to for some reason. I am positive the declare is correct.
I haven't made any modifications to the string function calls yet. I need to pass a literal string like so.. nu_PutString_DS("1",a) .. so I'm not sure using a pointer will work like you pointed out LarryMc. Using "&" is basically sending a pointer to a location.
I apologize LarryMc. Your way and Pauls way (below) will work I think. It is a round about way of doing which is necessary because of the byval. :-[
LarryMc, I tried it your and Pauls way and it didn't work.. :(
Egil, check the code below..
'
' trig_test.iwb
'
$INCLUDE "windowssdk.inc"
$INCLUDE "NUMS.inc"
LONG npi
LONG a
LONG b
LONG c
LONG i
double pi = 3.1415926535897932384626433832795
double ang, mult
ang=1
mult=4
i = nu_SetPrecision(nu_SetPrec_Digits, 35) '<-- set precision
npi = nu_AllocVar(nu_DT_DecFloat)
a = nu_AllocVar(nu_DT_DecFloat)
b = nu_AllocVar(nu_DT_DecFloat)
c = nu_AllocVar(nu_DT_DecFloat)
nu_PutDouble(ang, a)
'nu_Put_String_DS("1",a)
nu_ATan(a, b)
nu_PutDouble(mult, a)
nu_Mul(a, b, npi)
SETPRECISION 30
OPENCONSOLE
CLS 'clears the nag screen
print
print " Deg to Rad accurate: ",:mPrint(Deg2Rad(1),40)
print
print " Rad to Deg accurate: ",:mPrint(Rad2deg(1),40)
print
print " PI: accurate ",Nu_GetAny_DS(npi)
print " PI: not accurate ",:mPrint(pi,40)
print
print "press any key to end"
WAITCON
CLOSECONSOLE
nu_UnAllocVar(npi)
nu_UnAllocVar(a)
nu_UnAllocVar(b)
nu_UnAllocVar(c)
END
SUB mPrint(num:DOUBLE,prec:BYTE)
Dim i:INT
Dim s:string
s=LTRIM$(str$(int(num)))+"."
num=num-int(num)
for i=1 to prec
num=num*10
s+=LTRIM$(STR$(int(num)))
num=num-int(num)
next i
print s
ENDSUB
'
SUB Rad2deg(rad:DOUBLE),DOUBLE
'----------------------------------------------------------------------------------------
' Convert Degrees to Radians
' PI = 4 * atan(1)
' Returns Degrees in decimal format
'----------------------------------------------------------------------------------------
double nrad = 180
nu_PutDouble(nrad, a) 'store 180 in a
nu_PutDouble(rad, b) 'store radian in b
nu_Mul(a, b, c) 'store rad * 180 in c
nu_Div(c, npi, a) 'store c/pi in a
print nu_GetAny_DS(a) '<--- this returns a good number as a string
print " not accurate: ",
nrad = VAL(nu_GetAny_DS(a)) '<--- this one is inaccurate because of double
RETURN nrad
ENDSUB
'
SUB Deg2Rad(deg:DOUBLE),DOUBLE
'----------------------------------------------------------------------------------------
' Convert Degrees to Radians
' PI = 4 * atan(1)
' deg = Degrees in decimal format
' Returns Radians
'----------------------------------------------------------------------------------------
double nrad = 180
nu_PutDouble(nrad, a) 'store 180 in a
nu_Div(npi, a, c) 'store pi/180 in c
nu_PutDouble(deg, b) 'store degree in b
nu_Mul(b, c, a) 'store deg * c in a
print nu_GetAny_DS(a) '<--- this returns a good number as a string
print " not accurate: ",
nrad = VAL(nu_GetAny_DS(a)) '<--- this one is inaccurate because of double
RETURN nrad
ENDSUB
Later,
Clint
LarryMc,
There was one thing I found on the forum but it was reguarding EBasic. I think it was Paul that said to do it this way..
TYPE BVSTRING
STRING s
ENDTYPE
And then in the call.. declare import, calltomake(sstr as BVSTRING BYVAL).
That did not work for IWBasic. It gave a "cannot convert string to structure" error.
Still digging..
Later,
Clint
Clint
change this
declare import, calltomake(sstr as BVSTRING BYVAL)
to this
declare import, calltomake(sstr as BVSTRING)
which is what was done in the post that covered using BVSTRING
Nothing seems to work in trying to get a string to pass by value.
I did find another function which passes by ref... nu_PutString_PAZ("1",a) ' a is an initialized precision variable
You can also pass a double without declaring a variable first.. nu_PutDouble(1,a) ' a is an initialized precision variable
I guess I need to let this go for awhile and get back to work..
Later,
Clint
I'm working on importing the GMP.dll when I'm not busy and should have the necessary function done toward the end of the week.
Having some difficulty with the GMPR functions included in the dll. The trig functions seem to work, but the gmpr_mul doesn't.
Copied the declares from a PowerBASIC forum and modified them.
Later,
Clint
I never did get the mpfr_mul to work. You don't really need it. I just transfered the results to mpf_mul and it works fine.
Other functions need to be "declared" yet but I currently don't have time to do that. If one is needed it is easy to add.
Copy the "gmp.dll" to either your system32 folder or SysWow64 folder.
Copy the "gmp.inc" to iwbdev include folder
Copy the "gmp.lib" to iwbdev libs folder
This requires "windowssdk.inc" which the "gmp.inc" has a "$INCLUDE "windowssdk.inc" in it.
'
' trig_test.iwb
'
$INCLUDE "gmp.inc"
MPF npi
MPFR a_tan
MPFR b
MPF x
MPF y
MPF z
IString outb[1000] 'buffer for output
MPFRinit2(a_tan, 150) : MPFRinit2(b, 150)
MPFinit2(npi, 150) : MPFinit2(x, 150) : MPFinit2(y, 150) : MPFinit2(z, 150)
MPFRsetstr(b, "1", 10, 0) 'place 1 in b
MPFRatan(a_tan,b,0) 'atan(1)
MPAsprintf(outb, "%0.60Fe", a_tan) 'store in outb to transfer to MPF since MPFR doesn't work
MPFsetstr(x, outb, 10) 'x now hold atan(1)
MPFsetstr(y, "4", 10) 'y hold 4
MPFmul(npi, x, y) 'mul atan(1)*4
OPENCONSOLE
print
print " Deg to Rad : ",:Print Deg2Rad(1)
print
print " Rad to Deg : ",:Print Rad2deg(1)
print
MPAsprintf(outb, "%0.50Fe", npi)
print " PI: ",:Print outb
print
print "press any key to end"
WAITCON
CLOSECONSOLE
MPFRclear(a_tan) : MPFRclear(b)
MPFclear(npi) : MPFclear(x) : MPFclear(y) : MPFclear(z)
END
SUB Rad2deg(rad:DOUBLE),STRING
'----------------------------------------------------------------------------------------
' Convert Degrees to Radians
' PI = 4 * atan(1)
' Returns Degrees in decimal format
'----------------------------------------------------------------------------------------
MPFsetstr(x, "180", 10) 'store 180 in x
MPFsetstr(y, LTRIM$(STR$(rad)), 10) 'store radian in y
MPFmul(z, x, y) 'store rad * 180 in z
MPFdiv(x, z, npi) 'store z/pi in x
MPAsprintf(outb, "%0.50Fe", x)
RETURN outb
ENDSUB
'
SUB Deg2Rad(deg:DOUBLE),STRING
'----------------------------------------------------------------------------------------
' Convert Degrees to Radians
' PI = 4 * atan(1)
' deg = Degrees in decimal format
' Returns Radians
'----------------------------------------------------------------------------------------
MPFsetstr(x, "180", 0) 'store 180 in x
MPFdiv(z, npi, x) 'store pi/180 in z
MPFsetstr(y, LTRIM$(STR$(deg)), 0) 'store degree in y
MPFmul(x, y, z) 'store z * y in x
MPAsprintf(outb, "%0.50Fe", x)
RETURN outb
ENDSUB
Later,
Clint
I really appreciate your work Clint!
Will be gone away for the rest of the week, but will bring my laptop, so hope to be able to try out your work. Expect to return monday evening.
Going to have some surgery on my spine, the last of three, and hopefully it will help me get rid of most of the painkillers I have to use to be able to function. (I call them "brainkillers"...)
Hopefully I'll be able to do some coding when staying there. Do not know yet if they'll put me in a room with Internet access. If not I'll be silent for almost a week...
Quote from: Egil on October 28, 2014, 02:20:11 PM
...Going to have some surgery on my spine...
Wish you the best and a speedy recovery.
Clint,
Compiled your example just know. Works like a dream, and fast.
Think I'll have to find the documentation of that library, and download it. Mybe there are other functions in there that my be of use for my plans...
When I started this work, I just thought of using it for satellites with low earth orbist, but with this resolution i really beleive I'm set for outer space... ;D
Quote from: LarryMc on October 28, 2014, 02:26:32 PM
Wish you the best and a speedy recovery.
Thanks Larry!
Hope things go well for you Egil, good luck.
Later,
Clint
I did the declares by copying an include from PowerBASIC forum and looking through this header file.
If you need help with some paticular function let me know.
Later,
Clint
Just to weigh in with my two cents. Here is a piece of code that provides 16 digits worth of precision.
Remember, when using the DOUBLE floating point format (QWORD in assembly), the best precision you can get is 16 digits. If your processor is capable of 128-bit SSE or 256-bit AVX computations in either the XMM or YMM registers, then you can get precision that is greater then the number of stars in the known universe. That's a big number.
You can write your own software routines to get the precision you want, but that would be time-consuming. However, IWBasic has lot's of capabilities and one is that you can include inline assembly statements in your code to get some of the precision you desire. Here's an example:
[font=consolas]REM ----------------------------------------------------------------------
REM Program to convert degrees to radians and radians to degrees
REM Using the FPU allows calculations to be performed to 20 digits
REM of accuracy before being saved as double precision floating
REM values that are limited to 16 digits of accuracy.
REM
REM NOTE: Double precision floating point values are 64-bits wide
REM and only have an accuracy of 16 digits. Therefore,
REM trying to get more accuracy is futile when operating in
REM 32-bit protected mode using the flat memory model. We
REM could employ the 126-bit or 256-bit XMM/YMM registers,
REM but the processor would have to be capable of SEE/AVX
REM operations and the programmer would have to use software
REM algorithms as SSE/AVX have no hardware support for
REM scalar floating point operations larger than QWORD.
REM
REM Degrees = radians x pi/180
REM Radians = degrees x 180/pi
REM -------------------------------------------------------------------------
DECLARE rad2deg(FLOAT x) REM Forward declare two inline
DECLARE deg2rad(FLOAT x) REM assembly procedures
DEF key_entered AS STRING REM STRING to hold selection character
DEF input_value AS FLOAT REM FLOAT variable to hold input value
OPENCONSOLE
REM First, let's select which conversion we want to make
PRINT "Press 1 to convert degrees to radians"
PRINT "Press 2 to convert radians to degrees"
PRINT "Any other key to QUIT"
INPUT "Select: ", key_entered
REM Okay, let's enter a proper value for our selection
SELECT key_entered
CASE "1" REM Convert degrees to radians
INPUT "Enter degrees (0.0 to 180.0): ", input_value
IF input_value >= 0.0 AND input_value <= 180.0
deg2rad(input_value)
ELSE
PRINT "Incorrect value!" REM Must be between 0 and 180
ENDIF
CASE "2" REM Convert radians to degrees
INPUT "Enter radians (0.0 to 1.0): ", input_value
IF input_value >= 0.0 AND input_value <= 1.0
rad2deg(input_value)
ELSE
PRINT "Incorrect value!" REM Must be between 0 and 1
ENDIF
ENDSELECT
DO: UNTIL INKEY$ <> ""
CLOSECONSOLE
END
_asm
section .data
deg_fmt db "Answer: %.16f degrees", 10, 0 ; C Runtime library
rad_fmt db "Answer: %.16f radians", 10, 0 ; printing formats
deg_per_pi dq 180.0 ; 180 degrees per pi radian
result dq 0.0 ; Placeholder for DPFP results
section .text
extern _printf ; Use C Runtime library function
; to print results--has capability
rad2deg: ; to print more precision to screen
push ebp
mov ebp, esp ; Create stack to get passed parameter
fldpi ; Put pi on FPU stack
fld qword [deg_per_pi] ; Put 180 on FPU stack
fdiv st1 ; Divide 180 by pi
fld dword [ebp+8] ; Load passed value onto FPU stack
fmul st1 ; Multiply value by 180/pi
fstp qword [result] ; Save answer and pop the FPU stack
push dword [result+4] ; Load first 32-bits onto the stack
push dword [result] ; Load next 32-bits onto the stack
push dword deg_fmt ; C Runtime printing format
call _printf ; Print results to the screen
add esp, 12 ; Remove parameters from stack
mov esp, ebp ; Take down the stack
pop ebp
ret ; Return to IWBasic code
deg2rad: ; Assembly procedure
push ebp ; Create stack to get at passed value
mov ebp, esp
fld qword [deg_per_pi] ; Put 180 onto FPU stack
fldpi ; Put 16-digit pi onto FPU stack
fdiv st1 ; Divide pi by 180 degrees
fld dword [ebp+8] ; Load passed value onto FPU stack
fmul st1 ; Multiply value by pi/180
fstp qword [result] ; Save answer and pop the FPU stack
push dword [result+4] ; Load first 32-bits onto the stack
push dword [result] ; Load next 32-bits onto the stack
push dword rad_fmt ; C Runtime printing format
call _printf ; Print results to 16-digit precision
add esp, 12 ; Remove parameters from stack
mov esp, ebp ; Take down the stack
pop ebp
ret ; Return to IWBasic code
_endasm
REM -----------------------------------------------------------------------[/font]
This may not be what you want, but I typically employ inline assembly to get any additional precision I need for scientific calculations when I develop aeronautical simulations or climate models.
Note that you can get two constant values using these procedures. First, if you select 1 to convert degrees to radians and then enter 180 degrees, the answer will give you pi (3.141592653589793238462). Second, if you select 2 to convert radians to degrees and then enter 1 pi, the answer will give you 57.2957795130823230 degrees. Both are useful constants.
Logman
Thanks Logman!
I'll study your example thoroughly.
My greatest problem at the moment is that I have not done any EB/IWB coding in three years. Only a couple of easy demos using CB. But it was funny starting with IWB again though.
And to all the others:
As you can see, I returned from the hospital this afternoon, and so far everything has been successful. Except that my main email account is blocked. According to live.no (Microsoft), someone has probably hacket it. Every time I start my email client, I get a message from Microsoft saying my account has been used for irregular activities the last couple of days....
Glad you hospital visit went well. ;D
Thanks Larry.
Still having some trouble sitting, but I found a wooden box, put it on the kitchen table and placed my laptop on top. That way I can use the pc standing... In a week or two, I'll be fine.
Did some experiments today, using both the values Logman calulated with his exampe as constants for PI and Radians, and ckoehn's methods, angle calulations give exactly the same answers as a shareware program I tried (Orbitron at http://www.stoff.pl/ (http://www.stoff.pl/)).
But using PI=4*atan(1), as I did in the code posted at the start of this thread, produce large errors.
So maybe the IWB source for atan need another check?
Hi,
As far as I can tell, calculating pi = 4 * atan(1) gives the expected answer 3.141592653589793.
This is the best precision you can expect when you only have 8 bytes at your disposal for a decimal number.
You get 16 significant figures - anything more will be spurious digits ::)
The value of pi to 100 digits is:
3.141592653589793238462643383279502884197169399375105820974944592307816406286
Some languages have what they refer to as an 'extended' data type, which is good for 19 significant figures by using 10 bytes, but I'm afraid 'double' is the best we can do.
all the best, :)
Graham