...
Ordinarily, all of the mantissa bits are used to express significant figures, in addition to a leading 1, which is implied and, as a result, left out. Floats, consequently, have 24 significant bits of precision ; and doubles have 53 significant bits of precision. Such numbers are called normalized numbers. All-floating point numbers are limited in this sense because they have fixed precision.
When the value to be represented is too small to encode normally, it is encoded in denormalized form, indicated by an exponent value of Float.MIN_EXPONENT - 1
or Double.MIN_EXPONENT - 1
. Denormalized floating-point numbers have an assumed 0 in the ones place and have a zero or more leading zeros in the represented portion of their mantissa. These leading zero bits no longer function as significant bits of precision; consequently, the total precision of denormalized floating-point numbers is less than that of normalized floating-point numbers. Note that even using normalized numbers where precision is required can pose a risk. See rule "NUM04-J. Do not use floating-point numbers if precise computation is required" for more information.
Using denormalized numbers can severely impair the precision of floating-point calculations; as a result. Consequently, denormalized numbers must not be used.
...
The following code tests whether a float
value is denormalized in strictfp mode, or for platforms that lack extended range support. Testing for denormalized numbers in the presence of extended range support is platform-dependent; see rule "NUM06-J. Use the strictfp modifier for floating point calculation consistency across platforms" for additional information.
...
Testing whether values of type double
are denormalized is exactly analogous.
Print Representation of Denormalized Numbers
...
The following program produces this the following output:
Code Block |
---|
class FloatingPointFormats { public static void main(String[] args) { float x = 0x1p-125f; double y = 0x1p-1020; System.out.format("normalized float with %%e : %e\n", x); System.out.format("normalized float with %%a : %a\n", x); x = 0x1p-140f; System.out.format("denormalized float with %%e : %e\n", x); System.out.format("denormalized float with %%a : %a\n", x); System.out.format("normalized double with %%e : %e\n", y); System.out.format("normalized double with %%a : %a\n", y); y = 0x1p-1050; System.out.format("denormalized double with %%e : %e\n", y); System.out.format("denormalized double with %%a : %a\n", y); } } |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a75bd4988564e454-59729863-4a9a41d9-9560943a-0e2768f8794df172a1876350"><ac:plain-text-body><![CDATA[ | [[IEEE 754 | AA. Bibliography#IEEE 754 2006]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8abdb8c62eb194ad-9ec6baf7-43304d54-ab1ea0be-1436a6de547d65f071976592"><ac:plain-text-body><![CDATA[ | [[Bryant 2003 | AA. Bibliography#Bryant 03]] | Computer Systems: A Programmer's Perspective. Section 2.4 Floating Point | ]]></ac:plain-text-body></ac:structured-macro> |
...