FIX: INTEGER*2 Multiply by Power of 2 Produces Wrong Results (63360)
The information in this article applies to:
- Microsoft FORTRAN compiler for OS/2 5.0
- Microsoft FORTRAN Compiler for MS-DOS 5.0
This article was previously published under Q63360 SYMPTOMS
An application that multiplies an INTEGER*2 variable by an integer
constant that is a power of 2 produces incorrect results.
Specifying the /4I4 compiler option switch does not have any effect
on the results. Compiling the code with the /4Yb option and running
the application does not provide any indication of a problem.
Compiling the code with the /Od option to disable optimizations and
running the application does not change the behavior.
CAUSE
The compiler generates incorrect code when the result of the
multiplication is larger than the range of an INTEGER*2 variable
(-32,768 to 32,767).
RESOLUTION
To address this problem, perform one of the following steps:
- Modify the source code to use the INT4 intrinsic function to
convert the INTEGER*2 variable to an INTEGER*4 variable in the
expression.
- Modify the source code to assign the INTEGER*2 variable to a
temporary INTEGER*4 variable. Use the temporary variable in the
expression.
- Modify the source code to assign the integer constant to a
temporary variable. Use the temporary variable in the
expression.
STATUS
Microsoft has confirmed this to be a problem in FORTRAN version 5.0
for MS-DOS and OS/2. This problem was corrected in FORTRAN version
5.1 for MS-DOS and OS/2.
Modification Type: | Major | Last Reviewed: | 10/17/2003 |
---|
Keywords: | kbbug kbfix KB63360 |
---|
|