Floating Point
Home Up QBASIC+Assembly Floating Point Maze Generation Modules Parsing EMS Game Writing

 

1.  What is it?
2.  Notation

In some ways, understanding the details of how floating-point works is like understanding the details of how your car's power train works. Just as most folks do just fine driving their car without knowing how the drive train functions, most programmers do just fine writing programs using floating-point without knowing how their computer manipulates the data. The details just don't seem that important.

Until there is a problem.

Getting Started

If you are just a bit curious about floating point or need to dig more deeply into it, I've written a small tutorial here and a short program to let you explore the format and get more familiar with it.  As always, all source code is provided.   Hopefully, you will find the pages and the programs useful.

FLOATEXP.ZIP
A number of programs are available here, included in a 58k ZIP file.  Included are programs to display floating point format details, algebraic expression parsing, variable name symbol table management using hashing, and rational number calculations (fractions.)   See the README.TXT file for detailed information.
FLOATEXE.ZIP
Just a DOS executable, placed inside the ZIP, if that is all you are interested in.

The above program is currently at version 5, which includes:

support for general expressions
the ability to use assignment statements to variable names, which can be used in later expressions
support for pre-defined special names of e and pi
use of the pre-defined special name, ans, to represent the result of the latest calculation
multiple expressions or statements allowed, separated by a semi-colon
support for exact, hexadecimal coded floating-point in expressions

Some of the included code I've included in FLOATEXP.ZIP requires a Quick BASIC compiler, such as QB 4.5.  But this ZIP file also includes a program used to display the floating point format of various values, FLOATQB.BAS, which will run just fine with QBASIC and without any of the compiler tools.  You can pick up your own free QBASIC program from Microsoft, if you are lacking it, by going to that section of my PC Tools page and picking up the download from there.

In addition, Microsoft has also prepared a web page on floating point and Quick BASIC.

Clarifying Floating Point
Floating-point mathematics confuses many programmers and this Microsoft tutorial is designed to help in recognizing some programming situations where floating-point errors may occur.
Comparing Floating Point Values
This page discusses how to make reliable equality tests between two floating-point variables or expressions.

I also recommend getting Intel's documentation on the x86 processor, which includes a long section on the details of floating point numbers. It will take some getting used to, if this is your first time. But there is a lot of information kept there.

Pentium 4 (IA-32) Technical Docs
Look under the Manuals section on this page.

Finally, for those seriously interested in learning more about floating point, beyond what is already included in the Intel manuals for example, this widely distributed paper is definitely worth reading or skimming.

 

Feel free to email me.

Last updated: Wednesday, July 06, 2005 12:50