Q23389: Unexpected Result from CINT(.5) in QB87; IEEE Rounds to Even
Article: Q23389 Product(s): See article Version(s): 3.00 Operating System(s): MS-DOS Keyword(s): ENDUSER | B_BasicCom | mspl13_basic Last Modified: 21-FEB-1991 The coprocessor version of QuickBASIC version 3.00 (QB87.EXE) returns 0 (zero) in the following example (as do QuickBASIC versions 4.00, 4.00b, and 4.50; Microsoft BASIC Compiler versions 6.00 and 6.00b; and Microsoft BASIC Professional Development System (PDS) versions 7.00 and 7.10, which all use the IEEE floating-point format): PRINT CINT(1/2) PRINT CINT(.5) PRINT CINT(1.0/2.0) Three zeros (0) are printed. This differs from the non-coprocessor version of QuickBASIC version 3.00 (QB.EXE) and earlier versions, which instead prints three ones (1). Compare this with the fact that PRINT CINT(1.5) returns 2 in both the coprocessor and non-coprocessor versions of QuickBASIC version 3.00 (and in the other more recent products listed above). The observed rounding difference in the first case above is not caused by any bug. The IEEE standard dictates that rounding of x.5 occurs to the even integer nearest to x, for example, CINT(.5)=0, CINT(1.5)=2, CINT(2.5)=2, CINT(3.5)=4, CINT(4.5)=4, etc. The non-coprocessor version of QuickBASIC 3.00 (QB.EXE) supports a different floating-point format, the Microsoft Binary format (MBF), which rounds differently than the IEEE standard.
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.
Copyright Microsoft Corporation 1986-2002.