- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, there,
when I was debugging the source file. I found that the intel visual fortran compiler for windows version 10.1cause error and stopwhen the denominator equals to zero. but fortran did not give a notice how this error is happened. I wrote a "write" sentence to output the value of the expression. it simply returns no output.
I think this is an often made error during coding programes. I am not sure if other users also encounter this problem.
Thank you.
Best Regards,
Jingfen Chen
when I was debugging the source file. I found that the intel visual fortran compiler for windows version 10.1cause error and stopwhen the denominator equals to zero. but fortran did not give a notice how this error is happened. I wrote a "write" sentence to output the value of the expression. it simply returns no output.
I think this is an often made error during coding programes. I am not sure if other users also encounter this problem.
Thank you.
Best Regards,
Jingfen Chen
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you show the code which fails ? (including the variable declarations)
Can you run a debug version of the executable? This would give you more information. Or turn on Generate Traceback for the release version.
You may also like to look at the compiler options - /fpe (floating point exceptions) for example
If your expression is a complicated one you may need to print individual variables or sub-expressions instead of the whole thing
real A,B,C.D,X,Y
A = B + C + X/Y - D
Normallyif we suspect that Y could at all be zero then we would write something like
if (abs(Y) > 0.0) then
A = B + C + X/Y - D
else
A = some appropriate valueOR return an error condition
endif
better still is to use a "tolerance"a "lowest acceptible value" : if (abs(Y) > TOL) then
This is generally know as defensive programming
Les
Can you run a debug version of the executable? This would give you more information. Or turn on Generate Traceback for the release version.
You may also like to look at the compiler options - /fpe (floating point exceptions) for example
If your expression is a complicated one you may need to print individual variables or sub-expressions instead of the whole thing
real A,B,C.D,X,Y
A = B + C + X/Y - D
Normallyif we suspect that Y could at all be zero then we would write something like
if (abs(Y) > 0.0) then
A = B + C + X/Y - D
else
A = some appropriate valueOR return an error condition
endif
better still is to use a "tolerance"a "lowest acceptible value" : if (abs(Y) > TOL) then
This is generally know as defensive programming
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The behavior that you observed is expected. It has nothing to do with any compiler bugs. By default, the compiler produces code that provides for standard actions to take when floating point exceptions occur. If you want to track down the sources of the exceptions and fix your code to avoid them from occurring, you have to communicate that wish to the compiler by selecting suitable options.
With this test program
ifort /traceback /fpe0 zd.f90
and running the compiled program produces
Infinity
If the default handling is suitable, you can use it, and your program will run to completion but may have produced many incorrect results along the way. If you enable trapping floating point exceptions, you have to fix the code to avoid such errors. How to do so depends on the nature of your program.
With this test program
[fortran]program trapzerodivcompiling with the command
real :: x=1.0,y=0.0,z
z=x/y
write(*,*)z
end program trapzerodiv[/fortran]
ifort /traceback /fpe0 zd.f90
and running the compiled program produces
[bash]forrtl: error (65): floating invalidIf, on the other hand, the option /fpe0 is not used, the default floating point exception processing produces an infinity:
Image PC Routine Line Source
zd.exe 00401046 _MAIN__ 3 zd.f90
zd.exe 0045F5A3 Unknown Unknown Unknown
zd.exe 00443D58 Unknown Unknown Unknown
kernel32.dll 7C817077 Unknown Unknown Unknown[/bash]
Infinity
If the default handling is suitable, you can use it, and your program will run to completion but may have produced many incorrect results along the way. If you enable trapping floating point exceptions, you have to fix the code to avoid such errors. How to do so depends on the nature of your program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Les,
thank you for your suggestion. I am a newbie in coding fortran. Your suggestion is quite good.
I will try this in my coding.
Thank you so much.
Jingfen
thank you for your suggestion. I am a newbie in coding fortran. Your suggestion is quite good.
I will try this in my coding.
Thank you so much.
Jingfen

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page