Archives
 
 
 
  Special
 
 
 
  About Us
 
 
 

Newsletter
Free E-mail Newsletter from BYTE.com

 
    
           
Visit the home page Browse the four-year online archive Download platform-neutral CPU/FPU benchmarks Find information for advertisers, authors, vendors, subscribers Request free information on products written about or advertised in BYTE Submit a press release, or scan recent announcements Talk with BYTE's staff and readers about products and technologies

ArticlesHow To Bruise an Integer


March 1995 / Core Technologies / The Truth Behind the Pentium Bug / How To Bruise an Integer

The ``bruised,'' or truncated, integers Vaughan Pratt describes are numbers that should be integers and may appear as integers when displayed on the screen but internally are represented as floating-point values that fall just shy of a whole number. To see how this happens, try the following experiment using the Calculator program in Windows 3.1. This works on any PC, not just a Pentium.

1. Open the Calculator and select scientific mode from the View menu. Select decimal mode by clicking the button marked DEC.

2. Enter the integer 3.

3. Switch to binary mode by clicking the button marked BIN. Notice that Calculator correctly displays 1 1, the binary equivalent of 3.

4. Switch back to decimal mode and clear the display.

5. Enter 4.1 minus 1.1. Notice what appears to be the correct answer, 3.

6. Switch to binary mode. Calculator incorrectly displays 10, which is the binary equivalent of 2, not 3.

7. Switch back to decimal mode. The display now reads 2, not 3.

What happened? The floating-point subtraction in step 5 appeared to yield the correct result, but internally the number 3 was stored as a floating-point value that didn't quite equal 3 (probably 2.9999999...). When this ``bruised integer'' was converted to binary, Calculator evidently rounded down instead of up, causing an error in the displayed result. Microsoft corrected this problem in a new version of Calculator posted on various on-line services in January. However, the main point here is that the Calculator program illustrates how integer bruising occurs.


Up to the Core Technologies section contentsGo to previous article: The Truth Behind the Pentium BugGo to next article: A Warped PerspectiveSearchSend a comment on this articleSubscribe to BYTE or BYTE on CD-ROM  
Flexible C++
Matthew Wilson
My approach to software engineering is far more pragmatic than it is theoretical--and no language better exemplifies this than C++.

more...

BYTE Digest

BYTE Digest editors every month analyze and evaluate the best articles from Information Week, EE Times, Dr. Dobb's Journal, Network Computing, Sys Admin, and dozens of other CMP publications—bringing you critical news and information about wireless communication, computer security, software development, embedded systems, and more!

Find out more

BYTE.com Store

BYTE CD-ROM
NOW, on one CD-ROM, you can instantly access more than 8 years of BYTE.
 
The Best of BYTE Volume 1: Programming Languages
The Best of BYTE
Volume 1: Programming Languages
In this issue of Best of BYTE, we bring together some of the leading programming language designers and implementors...

Copyright © 2005 CMP Media LLC, Privacy Policy, Your California Privacy rights, Terms of Service
Site comments: webmaster@byte.com
SDMG Web Sites: BYTE.com, C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, New Architect, SD Expo, SD Magazine, Sys Admin, The Perl Journal, UnixReview.com, Windows Developer Network