FIX: Incorrect Results When ISHFT, ISHL in ISHFT or ISHL Call

ID: Q71810


The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 4.01, 4.1, 5.0, 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, 5.1


SYMPTOMS

An application produces incorrect results. Specifying the /Od compiler option switch and recompiling does not change the results. When you compile the application with Microsoft FORTRAN version 4.0, it produces correct results.


CAUSE

The application uses an ISHFT or ISHL logical shift intrinsic function as an argument to another ISHFT or ISHL logical shift intrinsic function.


RESOLUTION

To work around this problem, modify the source code to store the results of one logical shift operation in a temporary variable. Specify the variable as the argument to the other logical shift instruction.


STATUS

Microsoft has confirmed this to be a problem in FORTRAN versions 4.01, 4.1, 5.0, and 5.1. This problem was corrected in FORTRAN PowerStation, version 1.0.


MORE INFORMATION

The following code example demonstrates this problem.

Sample Code #1


C Compile options needed: None

      INTEGER IN, SHIFT, I
      IN = 2
      SHIFT = 4
      WRITE (*, *) 'input number to be shifted   ', IN
      WRITE (*, *) '# of bits to shift           ', SHIFT
C
C Shifting the number 00000010 (2 decimal) logically left by 4 bits
C then logically right by 4 bits should produce 00000010 (2 decimal).
C However, this code produces 00000000 (0 decimal).
C
      I = ISHFT(ISHFT(IN, SHIFT), -SHIFT)
      WRITE(*, *) 'input shifted over and back  ', I

      END 
This application produces the following output:

input number to be shifted           2
# of bits to shift                   4
input shifted over and back          0 
It is designed to produce the following output:

input number to be shifted           2
# of bits to shift                   4
input shifted over and back          2 
Substituting the ISHL logical shift intrinsic function for the ISHFT logical shift intrinsic function produces the same incorrect results.

To work around this problem, split the logical shift functions into two separate expressions. The following code example demonstrates this technique.

Sample Code #2


C Compile options needed: None

      INTEGER IN, SHIFT, I, TMP
      IN = 2
      SHIFT = 4
      WRITE (*, *) 'input number to be shifted   ', IN
      WRITE (*, *) '# of bits to shift           ', SHIFT
C
C Shifting 00000010 (2 decimal) logically left by 4 bits
C produces the value 00100000 (32 decimal).
C
      tmp = ISHFT(in, shift)
C
C Shifting 00100000 (32 decimal) logically right by 4 bits
C produces the value 00000010 (2 decimal).
C
      I = ISHFT(TMP, -SHIFT)
      WRITE (*, *) 'input shifted over and back  ', I

      END 

Additional query words: 4.01 4.10 5.00 5.10 buglist4.01 buglist4.10 buglist5.00 buglist5.10 fixlist1.00

Keywords :
Version : :4.01,4.1,5.0,5.1
Platform :
Issue type :


Last Reviewed: November 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.