Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 4.1

FEATURE

The Problem with Floating-Point Numbers, Part II

Encoding real numbers into integer format

Issue: 4.1 (September/October 2005)
Author: William H. Murray and Chris H. Pappas
Author Bio: Murray and Pappas are department chairmen of the Electrical Engineering Technology and Computer Studies programs, respectively. They teach at Broome Community College which is a S.U.N.Y. system college in upstate New York. Murray and Pappas have written over 50 trade books on assembly language, C, C++, C#, Java, Windows and more.
Article Description: No description available.
Article Length (in bytes): 17,669
Starting Page Number: 24
Article Number: 4111
Related Link(s): None

Excerpt of article text...

In the last issue of REALbasic Developer, we discussed a number of problems related to passing real numbers across an "integer" data bus. In the first article, you learned that while generations of computers have allowed both integer and real number arithmetic, dealing with real numbers is not a simple issue. However, don't take our word for it; go back and review this first article and learn about the various problems programmers have had to deal with for decades.

Recall that by the mid-80's, the American National Standards Institute (ANSI) and the Institute for Electrical and Electronic Engineers (IEEE) released the ANSI/IEEE 754 floating-point standard addressing many of these conversion problems. They also provided the means of converting, or encoding, real numbers into an integer format that could be passed across the data bus and also a means of converting those encoded integer formats back to real numbers by a decoding process.

In the first article, we developed a REALbasic program that allows us to enter an encoded integer number (in short, long or temporary format) then convert it to a normal real number format. In this article, we're going to do the reverse. That is, we'll start with a real number, apply a conversion process and end up with an encoded real number in integer format. Once we understand the process, we'll develop a REALbasic program that will perform the conversion for us.

Dealing with Terms

In the last issue of REALbasic Developer, we discussed how single precision (32 bits) and double precision (64 bits) numbers could be converted and represented in a hexadecimal integer format. You also learned that many microprocessor chips, such as IBM 970 chip used in Mac G5's, have built in math coprocessors that speed up real number arithmetic.

You should also understand that many real numbers cannot be precisely and exactly specified in an encoded integer format. The real number 2.0 can be precisely specified in an encoded integer format. However, the real number resulting from dividing 10 by 3 (10/3) cannot be precisely represented in an integer format. That fact brings us to the discussion of some terms related to the whole encoding/decoding process.

...End of Excerpt. Please purchase the magazine to read the full article.