1 Reply Latest reply: Jun 9, 2009 4:02 PM by pej_jones RSS

    Error using MOD function with Intel Visual Fortran

    pej_jones

      I'm writing a Fortran program and am using the Intel Visual Fortran compiler. I noticed I was getting the wrong answer. I finally tracted it down to the MOD function. The command res = MOD(2e6,3.1) works and gives me the right answer but when I do a res = MOD(2e7,3.1) I get an answer of 0.31 instead of the 2.8 I was expecting. I have res defined as Real*16 so I don't see what the problem is. Has anyone else seen this? Does anyone know why the compiler is giving the wrong answer.

       

      This finally resolved my issue:

      The problem is the assignment of the constant (which is REAL*) to the REAL*16 variable. Fortran does not give the right hand precision on such an assignment. If you modify the constant definition to be longer precision:

       

      By using 3.1_16 or else compile with /4R8 or /4R16.(/real-size:64 and /real-size:128 are equivalent) then you will get the right answer.

       

      Pat