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

Last reviewed: September 11, 1997
Article ID: Q71810
4.01 4.10 5.00 5.10 | 4.10 5.00 5.10
MS-DOS              | OS/2
kbtool kbbuglist kbfixlist kbcode

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 reference words: 4.01 4.10 5.00 5.10 buglist4.01 buglist4.10
buglist5.00 buglist5.10 fixlist1.00
KBCategory: kbtool kbbuglist kbfixlist kbcode
KBSubcategory: FLIss
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 11, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.