Fortran Floating Point Overflow Error
Contents |
view Printable view Export to Adobe Acrobat (PDF) Export to Microsoft Word Email this page Other pagesHome page Dashboard News Recent updates RSS feed builder Index Site map Labels Attachments index People Directory AccountLog in History History Common Fortran Error messages When
Floating Point Coprocessor Fault Fortran
you execute your program, you may encounter run-time errors that are difficult to trace. fortran floating point exception The three most common errors are segmentation violations, bus errors, and arithmetic exceptions. Segmentation violations A segmentation violation occurs when some part program received signal sigfpe floating point exception erroneous arithmetic operation of your code attempts to access a part of memory that is not defined by your program. A common cause of this problem is attempting to access an array with an invalid subscript. Arrays in Fortran must
Floating Point Error
have integer subscripts whose values are between 1 and the dimension of the array the subscript refers to. For example, if you declared an array as: real foo(10,5) and attempted to access element foo(32,3), a segmentation violation would occur because the value 32 is greater than the dimension of the array. Bus errors A bus error occurs if the data sets passed during a main/subprogram to subprogram interface are not of equal size. One possible cause of this problem is an unequal number of arguments in the argument list of a 'call' statement and the corresponding subroutine declaration as in: call foobar(x,y,z) <-- 3 arguments subroutine foobar(a,b,c,d) <-- 4 arguments! Another possible cause is an argument list in a call statement that does not contain the same variable types as the subroutine declaration. For example, the code below would result in a bus error because array 'foo' is declared as real, and array 'dummy' is declared as double precision. real foo(10,5) integer i, j call foobar(foo,i,j) <-- real,int,int | |==> these don't match! | subroutine foobar(dummy,idummy,jdummy) <-- double,int,int double precision dummy(10,5) integer idummy, jdummy Arithmetic/floating point exception An arithmetic or floating point exception (also labelled as "TRACE/BPT Error") occurs when the value of a variable exceeds its proper range in some way. This error commonly occurs when one attempts to divide by zero. Since an infinite value cannot be represented by the computer, an error occurs. For example, the code: integer i,j,k i = 1 j = 0 k = i/j will generate the error "Arithmetic Exception: Integer divide by 0" because an attempt to divide by zero (assign k to infinity) was made. An arithmetic exception can also occur if the value of a variable exceeds the largest
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions http://kb.mit.edu/confluence/display/istcontrib/Common+Fortran+Error+messages Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up fortran 90 (floating point error: overflow) http://stackoverflow.com/questions/15878604/fortran-90-floating-point-error-overflow up vote 0 down vote favorite i am dealing with the code below and i am recieving 'runtime error M6104:MATH floating point error:overflow'. i searched the error online and it is written the output values have high range than input values that i represent as input. I am using Microsoft Developer Studio and since my computer 64-bit when i debugged the program shut down. So, i couldn't see which lines create problems. If you examine the code and give me any clue about what is the problem, i will be extremely pleased. The code; ! computer code for lid-driven cavity parameter (n=100,m=100) real f(0:8,0:n,0:m) real rho(0:n,0:m) real w(0:8), cx(0:8),cy(0:8) real u(0:n,0:m), v(0:n,0:m) integer i real tminv(0:8,0:8),sm(0:8),tm(0:8,0:8),stmiv(0:8,0:8) real ev(0:8,0:8) open(2,file='uvfield') open(3,file='uvely') open(4,file='vvelx') open(8,file='timeu') open(10,file='tmat') w(:)=(/4./9.,1./9.,1./9.,1./9.,1./9.,1./36.,1./36.,1./36.,1./36./) cx(:)=(/0.,1.,0.,-1.,0.,1.,-1.,-1.,1./) cy(:)=(/0.,0.,1.,0.,-1.,1.,1.,-1.,-1./) tm(0,:)=(/1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0/) tm(1,:)=(/-4.,-1.,-1.,-1.,-1.,-2.0,-2.0,-2.0,-2.0/) tm(2,:)=(/-4.0,-2.,-2.,-2.,-2.,1.0,1.0,1.0,1.0/) tm(3,:)=(/0.0,1.0,0.0,-1.,0.0,1.0,-1.,-1.,1.0/) tm(4,:)=(/0.0,-2.,0.0,2.0,0.0,1.0,-1.,-1
information about specific bugs or numerical errors found and fixed in GEOS-Chem, please see our Numerical issues discovered in GEOS-Chem page. Contents 1 Floating-point is an approximation to the real number system 2 http://wiki.seas.harvard.edu/geos-chem/index.php/Floating_point_math_issues Safe floating-point division 3 Testing for equality 3.1 Exact-value testing 3.1.1 Integers 3.1.2 https://www.ibiblio.org/pub/languages/fortran/ch4-9.html Real numbers 3.1.3 Avoiding zero 3.2 Epsilon testing 3.2.1 Avoiding division by zero 3.2.2 Testing for values close to zero 3.2.3 Testing for values close to a non-zero number 4 Testing for non-representable values 4.1 NaN (Not-a-Number) 4.2 Infinity Floating-point is an approximation to the real number system The real number system may floating point be thought of as a number line with the following characteristics: Zero is the primary reference point From zero, the line extends infinitely in both directions towards + Infinity and -Infinity Between any two real numbers, there are an infinite number of other real numbers A pictorial representation of the real number system looks like this: -Infinity <---------- 0 ---A---B----> +Infinity where between points A and B fortran floating point there are an infinite number of real numbered-values. It is important to realize that floating-point mathematics (as implemented in all modern computer systems) is never exact but is only an approximation to the real number system. In most programming languages, floating-point real numbers are composed of groups of 4 or 8 bytes. This means that floating-point numbers are not infinitely precise, but have a maximum precision. As a consequence, floating-point math operations (especially multiplication and division) can often lead to different results than one would normally anticipate. Here are the common number types used in both IDL and Fortran: IDL Number Type Fortran equivalent ESMF equivalent Number of bytes Approx. range byte BYTE - 1 0 to 255 fix INTEGER*2 ESMF_KIND_I2 2 0 - 32767 long INTEGER*4 ESMF_KIND_I4 4 -214700000 to -214700000 float REAL*4 ESMF_KIND_R4 4 -1e-38 to 1e+38 double REAL*8 ESMF_KIND_R8 8 -1e-312 to 1e+312 A pictorial representation of the floating point mathematics system would look like this: -Min Representable Value < . . . . . . 0 . . A . B . . > +Max Representable Value Because each floating-point number type is composed of a finite number of bytes, we can only represent numbers
on 'FORTRAN pitfalls' discusses various programming practises that may amplify floating-point (and other) errors, and it is very important to avoid them. o Note that an interval/stochastic arithmetic package is not just a diagnostic tool for FP errors, a result without an error estimation is not very useful, as errors can never be eliminated completely in experimental data and computation. Carefully written programs -------------------------- This term was probably coined by Sterbenz (see bibliography below), and means programs that are numerically correct. this is not easy to achieve as the following example will show. Sterbenz discusses the implementation of a Fortran FUNCTION that returns the average of two REAL numbers, the specifications for the routine are: o The sign must be always correct. o The result should be as close as possible to (x+y)/2 and stay within a predefined bound. o min(x,y) <= average(x,y) <= max(x,y) o average(x,y) = average(y,x) o average(x,y) = 0 if and only if x = -y unless an underflow occurred. o average(-x,-y) = -average(x,y) o An overflow should never occur. o An underflow should never occur, unless the mathematical average is strictly less than the smallest representable real number. Even a simple task like this, requires considerable knowledge to program in a good way, there are 4 (at least) possible average formulas: 1) (x + y) / 2 2) x/2 + y/2 3) x + ((y - x) / 2) 4) y + ((x - y) / 2) Sterbenz have a very interesting discussion on choosing the most appropriate formulas, he also consider techniques like scaling up the input variables if they are small. Grossly oversimplifying, we have: Formula #1 may raise an overflow if x,y have the same sign #2 may degrade accuracy, but is safe from overflows #3,4 may raise an overflow if x,y have opposite signs We will use formulas #1,3,4 according to the signs of the input numbers: real function average (x, y) real x, y, zero, two, av1, av2, av3, av4 logical samesign parameter (zero = 0.0e+00, two = 2.0e+00) av1(x,y) = (x + y) / two av2(x,y) = (x / two) + (y / two) av3(x,y) = x + ((y - x) / two) av4(x,y) = y + ((x - y) / two) if (x .ge. zero) then if (y .ge. zero) then samesign = .true. else samesign = .false. endif else if (y .ge. zero) then samesign = .false. else samesign = .true. endif endif if (samesign) then if (y .ge. x) then average = av3(x,y) else average = av4(x,y) endif else average = av1(x,y) endif return end Programming using exceptio