The information in this article applies to:
SUMMARY
(Note that Microsoft QuickBasic for MS-DOS, versions 3.0 and earlier have no long integer format or CLNG function) MORE INFORMATIONThis type of integer rounding complies with the following IEEE standard: "If the difference between the unrounded operand and the rounded result is exactly one half, the rounded result is even" (Section 5.5 of the "IEEE Standard for Binary Floating-Point Arithmetic")The purpose of this behavior is to prevent an average upward (or downward) bias as various calculations are rounded. If the number is always rounded up, there would be an upward bias in calculations. Rounding to the nearest even number averages out; therefore, no rounding bias occurs. The compilers listed above store and manipulate numbers using IEEE format. This exclusive use of IEEE format for real numbers is necessary to enable compiled Basic to CALL routines written in FORTRAN, Pascal, and C, all of which use IEEE format. QB.EXE (noncoprocessor) version 3.0 and QuickBasic for MS-DOS, versions 1.0, 1.01, 1.02, 2.0, and 2.01 all store numbers in Microsoft Binary Floating Point format (also known as MBF). Note that QB87.EXE, the coprocessor version of QuickBasic for MS-DOS, version 3.0, uses IEEE format. QuickBasic for MS-DOS, versions 1.x, 2.0, and 2.01 do not support IEEE (or 8087, 80287, or 80387) coprocessors. Microsoft Binary format uses a standard different from that of IEEE for converting between floating point and integers. In particular, numbers with "5" as the least significant digit are always rounded up to the next integer. The result does not have to be an even number. Thus, the Microsoft Binary format has an upward rounding bias. Note that QuickBasic for MS-DOS, versions 3.0 and earlier cannot make interlanguage CALLs to FORTRAN, Pascal, or C. Listed below are two examples of the above rounding behavior. To execute these examples in VBDOS.EXE use the following steps:
Example 1The following is an example of always rounding expressions ending in .5 to an even number by integer assignment:
Example 2The following is an example of rounding of the CINT() function:
OUTPUT FROM: B.EXE 4.0 later | B.EXE 3.0, 2.01, 2.0
Additional query words: VBmsdos QuickBas
Keywords : |
Last Reviewed: December 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |