FIX: FP Emulator Converts REAL to INTEGER IncorrectlyLast reviewed: September 16, 1997Article ID: Q102692 |
1.00
MS-DOS
kbtool kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSWhen an application developed in Microsoft FORTRAN PowerStation runs on a computer that does not have a math coprocessor installed, the code may convert a REAL variable or expression to an INTEGER variable incorrectly, resulting in incorrect results.
CAUSEWhen an application immediately converts the results of a REAL calculation to an INTEGER value, the code does not remove the results from the coprocessor emulator stack. The numeric conversion routine __ftol (float to long) uses this extended coprocessor-stack-based value instead of the truncated contents stored in the variable. The __ftol function incorrectly rounds down the extended-precision result.
RESOLUTIONTo work around this problem, use the NINT (round to nearest integer) intrinsic function to explicitly convert the expression or variable to an INTEGER. The /Ox optimization compiler option switch may resolve this error. Among other optimizations, the /Ox switch calculates constant expressions at compile time. These calculations may correctly convert the REAL number to an INTEGER while the run-time calculation produces the incorrectly rounded result.
STATUSMicrosoft has confirmed this to be a problem in PowerStation versions 1.0 and 1.0a for MS-DOS. This problem has been resolved with FORTRAN PowerStation maintenance release version 1.0a for MS-DOS. FORTRAN Powerstation version 1.0 can be differentiated from the maintenance release version 1.0a by invoking the linker. Typing "link32 | more" from the \f32\BIN directory will show version 2.8 for FORTRAN Powerstation version 1.0, and it will show 1.0f for the maintenance release version 1.0a.
MORE INFORMATIONThe FORTRAN PowerStation floating-point emulator is a virtual dynamic- link library (DLL) in the Phar Lap MS-DOS extender. To duplicate this problem on a computer with a math coprocessor installed, type the following at the MS-DOS command prompt:
SET TNT=-FPEMThis statement causes the MS-DOS extender to ignore the math coprocessor and use the emulator code for all math operations. The following code example prints the word "Failed" when it runs with the floating-point emulator:
Sample Code 1C Compiler options needed: none
x = 3.0 z = -3. ** x i = z if (i .ne. -27) then print *, 'Failed' else print *, 'OK' end if endThe following code example demonstrates using the NINT intrinsic function to avoid this error. This code prints the word "OK" even when a math coprocessor is not available.
Sample Code 2C Compiler options needed: none
x = 3.0 z = -3. ** x i = nint(z) if (i .ne. -27) then print *, 'Failed' else print *, 'OK' end if end |
Additional reference words: 1.00 Phar Lap DOSXMSF.EXE
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |