The Artima Developer Community
Sponsored Link

Inner Float
A float Reveals Its Inner Nature

Advertisement

The Inner Float applet, included below, lets you experiment with the IEEE 754 floating point format. This applet accompanies Chapter 14, "Floating Point Arithmetic," of Inside the Java 2 Virtual Machine.

For some reason, your browser won't let you view this way cool Java applet.

The Inner Float applet displays the value of a float in several formats. The top three lines show each of the three parts of a float--the sign, exponent, and mantissa-- individually in binary. The fourth line, labeled "binary," shows the entire 32-bit image of the float in binary (with all three pieces together). The fifth line, labeled "hex," shows the 32-bit image of the float in hex.

The last two lines show the value of the float in radix two and ten. Note that the radix two scientific notation format shows the mantissa and exponent in base ten. Before being displayed, the actual mantissa is multiplied by 224, which yields an integral number, and the unbiased exponent is decremented by 24. Both the integral mantissa and exponent are then easily converted to base ten and displayed.

A few key-press sequences that illustrate interesting characteristics of IEEE 754 floating point numbers are given below:

Too Big For Its Increments
Try this key-press sequence:

*=0
++
*=2, *=2, *=2, ... repeat until radix 2 == 8388608e1
++, ++, ...

Press the *=2 button repeatedly until the exponent of the radix two display is a one. When you then press the ++ button, note that the value of the float doesn't change. The float's value is too large to be affected by adding only one.

Too Small For Its Increments
Try this key-press sequence:

Min
++
--            note that you can't get back to Min

When you then press the ++ button, you loose precision because Min is so much smaller than one. When you then press the -- button, you get zero.

Equivalence of Radix 2 and Radix 10
Try this key-press sequence:

*=0
++
*=2, *=2, *=2, ... repeat until radix 2 == 8388608

Press the *=2 button repeatedly until the exponent of the radix two display is a zero (it will just be shown as "8388608" without an "e0"). At that point, the value displayed in radix 10 is 8.3361e+06, which is the same as the radix 2 number.

Underflow to Zero
Try this key-press sequence:

Min
/=2
*=2, *=2, ... note that you can't get back to Min again

When you press the /=2 button, the value of the float underflows to zero. When a floating point operation underflows to zero, all bits of precision are lost.

Underflow to Negative Zero
Try this key-press sequence:

Min
*=-1
/=2
*=2, *=2, ... note that you can't get back to (Min * -1) again

When you press the /=2 button, the value of the float underflows to negative zero. When a floating point operation underflows to negative zero, as when it underflows to positive zero, all bits of precision are lost.

Overflow to Infinity
Try this key-press sequence:

Max
*=2
/=2, /=2, ... note that  you can't get back to Max again

When you press the *=2 button, the value of the float overflows to infinity. When a floating point operation overflows to infinity, all bits of precision are lost.

Overflow to Negative Infinity
Try this key-press sequence:

Max
*=-1
*=2
/=2, /=2, ... note that you can't get back to (Max * -1) again 

When you press the *=2 button, the value of the float overflows to negative infinity. When a floating point operation overflows to negative infinity, as when it overflows to positive infinity, all bits of precision are lost.

Infinity Times Zero is NaN
Try this key-press sequence:

+Inf
*=0

Infinity Times -1 Changes Sign of Infinity
Try this key-press sequence:

+Inf
*=(-1)

Infinity Times 2 is Still Infinity
Try this key-press sequence:

+Inf
*=(2), *=(2), *=(2), ... repeat until you're convinced

For a float, infinity is as big as it gets.


Click here to view a page of links to the source code of the Inner Float applet.


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us