JDK-6476168 : (fmt) Inconsistency formatting subnormal doubles with hexadecimal conversion
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2006-09-28
  • Updated: 2017-05-16
  • Resolved: 2013-08-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b103Fixed
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
When formatting a subnormal double with hexadecimal conversion "a", it is normalized if the precision is specified and less then 14. However it should never be normalized according to the spec:

http://java.sun.com/javase/6/docs/api/java/util/Formatter.html:
'a'  '\u0061'  Requires the output to be formatted in hexadecimal exponential form.
If m is a double value with a subnormal representation then the significand is represented by the characters '0x0.' followed by the hexadecimal representation of the rest of the significand as a fraction. The exponent is represented by 'p-1022'

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The results are in comments.

System.out.printf("%a\n", 0x0.123p-1022 );     // 0x0.123p-1022
System.out.printf("%1.3a\n", 0x0.123p-1022 );  // 0x1.230p-1026
System.out.printf("%1.15a\n", 0x0.123p-1022 ); // 0x0.123000000000000p-1022



REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION Specification should be updated to match behavior: if the precision is given the value is rounded to number of hexdigits of precision and subnormal values are presented as normalized.
21-09-2011