View previous topic :: View next topic |
Author |
Message |
Lolly
Joined: 10 Dec 2010 Posts: 2
|
Posted: Mon Dec 13, 2010 7:00 pm Post subject: Floating Point RUNTIME error in WIN32 - NOT in .NET |
|
|
Hi,
I am getting a floating point RUNTIME error while running a program on WIN32 platform. I do not get this error on .NET and program runs fine on .NET.
I know I am generating very small numbers and I suspect that the numbers < 10E-38 may be causing the blowup. It appears that .NET can handle as small as 10E-48.
Could the limitation of 32 bit on WIN32 platform be the problem here?
Is there a way for me to fix this problem in WIN32 without limiting the size of my generated numbers?
Thanks for any solutions here.
Lolly |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2621 Location: Sydney
|
Posted: Tue Dec 14, 2010 1:20 am Post subject: |
|
|
Try using REAL*8 and see if that solves the problem.
Or compile with /dreal, if you have declared variables using "REAL", or implicit declarations.
There might be a different error handling for real underflow, but I do not know for certain. |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2415 Location: Yateley, Hants, UK
|
Posted: Tue Dec 14, 2010 4:59 pm Post subject: |
|
|
You are implicitly assuming that .NET is exhibiting the correct behaviour.
FTN95.chm notes (under .NET programs / .NET programming / Arithmetic overflow/underflow) that "Floating point underflow, which (depending on the algorithm) may or may not represent a true error, can optionally be trapped." (in .NET. It is always trapped in Win32.) I suggest that if your code does not set it up to be trapped, it probably isn't! Hence, the Win32 version is probably giving you a better handle on the problem.
Single precision underflow does happen at about 10^-38, and if you are dealing with numbers that close to zero, you really ought to go for 64-bit reals, or even better, 80-bit reals (which are Win32 only). John Campbell's suggestions are the first steps in tracking your problem down. 64-bit reals will get you down to more like 10^-308, and 80-bit reals down to about 10^-4932 (see in FTN95.chm the section kind parameters for intrinsic types / real kinds).
I always found that one has to be VERY careful with real*4, and that real*8 is often too precise. Real*6 seems to me a suitable compromise for routine work. Real*10 is for the sort of work you seem to be doing.
Best regards
Eddie |
|
Back to top |
|
 |
Lolly
Joined: 10 Dec 2010 Posts: 2
|
Posted: Tue Dec 14, 2010 7:15 pm Post subject: |
|
|
Thank you very much for these suggestions and further insight. I will try your suggestions and definitly educate myself further. |
|
Back to top |
|
 |
|