FIX: Incorrect Results When ISHFT, ISHL in ISHFT or ISHL CallLast reviewed: September 11, 1997Article ID: Q71810 |
4.01 4.10 5.00 5.10 | 4.10 5.00 5.10
MS-DOS | OS/2kbtool kbbuglist kbfixlist kbcode The information in this article applies to:
SYMPTOMSAn 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.
CAUSEThe application uses an ISHFT or ISHL logical shift intrinsic function as an argument to another ISHFT or ISHL logical shift intrinsic function.
RESOLUTIONTo 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.
STATUSMicrosoft 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 INFORMATIONThe following code example demonstrates this problem.
Sample Code #1C 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 CC 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 ENDThis application produces the following output:
input number to be shifted 2 # of bits to shift 4 input shifted over and back 0It is designed to produce the following output:
input number to be shifted 2 # of bits to shift 4 input shifted over and back 2Substituting 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 #2C 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 CC 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |