Floating-Point Types

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

*Floating-point numbers consists of a magnitude m (a value between 0 and 1), an exponent e (taken relative to a constant offset N), and a sign bit s (+1 or -1) to represent following value:

s   ·   m · 2 (e   -   N   +   1)
 

*The exponent e is an integer in the inclusive range of
Emin  =  -(2K-1-2) and Emax  =  2K-1-1.
 
*Java provides two predefined floating-point types with following values of N and K:


TypeBitsNKEminEmax

float32248-126127
double645311-10221023


 

*Both formats conform to the IEEE 754 standard which provides also representations for undefined floating point numbers (so called NaNs: ``not-a-number''), and for plus and minus infinity.
 
*Floating-point literals consists of a whole number, a decimal point, a fractional part, an exponent (an ``e'' or ``E'', followed by a whole number), and a type suffix (``f'' or ``F'' for float and ``d'' or ``D'' for double). Most parts are optional: At least one digit must be provided for the whole number or the fraction, and, to distinguish it from integer constants, either the decimal point, the exponent, or the type suffix is to be given. Examples:
0.0 .1 1.0 1.0f 2. 20.07 5e6 52.61e78d 1e-10
 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002