FIX: Incorrect Results with PARAMETER in NINT (77341)



The information in this article applies to:

  • Microsoft FORTRAN Compiler for MS-DOS 5.0
  • Microsoft FORTRAN Compiler for MS-DOS 5.1
  • Microsoft FORTRAN compiler for OS/2 5.0
  • Microsoft FORTRAN compiler for OS/2 5.1

This article was previously published under Q77341

SYMPTOMS

Programs that contain a PARAMETER constant in an arithmatic expression within the NINT intrinsic function argument list may generate incorrect results during run time.

RESOLUTION

One way to work around this problem is to use a variable in the expression instead of a PARAMETER.

STATUS

Microsoft has confirmed this to be a problem in the products listed above. This problem was corrected in FORTRAN PowerStation.

MORE INFORMATION

The following code can be sued to reproduce the problem:

Sample code

        integer*4 iconst
        parameter (iconst = 1024)

        real sdata, ddata

        ddata = 200.0
        sdata = 0.001
c        iconst = 1024

c incorrect results generated here
      print *,  'NINT(ddata * iconst * sdata) * 2 = ',
     * NINT(ddata * iconst * sdata) * 2
      print *,  'NINT(ddata * iconst * 0.001) * 2 = ',
     * NINT(ddata * iconst * 0.001) * 2

      print *,  'NINT(200.0 * iconst * sdata) * 2 = ',
     * NINT(200.0 * iconst * sdata) * 2
      print *,  'NINT(200.0 * iconst * 0.001) * 2 = ',
     * NINT(200.0 * iconst * 0.001) * 2

      print *,  'NINT(ddata    * iconst * sdata) + 2 = ',
     * NINT(ddata * iconst * sdata) + 2
      print *,  'NINT(ddata    * iconst * 0.001) + 2 = ',
     * NINT(ddata * iconst * 0.001) + 2

        END
				
Output:
NINT(ddata * iconst * sdata) * 2 =       409  ! this value should be 410
NINT(ddata * iconst * 0.001) * 2 =       410
NINT(200.0 * iconst * sdata) * 2 =       410
NINT(200.0 * iconst * 0.001) * 2 =       410
NINT(ddata * iconst * sdata) + 2 =       207
NINT(ddata * iconst * 0.001) + 2 =       207
				

Modification Type:MajorLast Reviewed:12/1/2003
Keywords:KB77341