I have the following head scratcher, demonstrated in jshell 11.0.12 and 17.0.1 here
jshell> 13.9f
$1 ==> 13.9
jshell> 13.9
$2 ==> 13.9
jshell> (double) 13.9f
$3 ==> 13.899999618530273
The same thing occurs in a simple compiled class in both versions
strictfp public class Test {
public strictfp static void main(String[] args) {
System.out.format("%s%n", (double) 13.9f);
System.out.format("%s%n", 13.9f);
}
}
╰─➤ java Test
13.899999618530273
13.9
Although 17 warns that strictfp is no longer required
warning: [strictfp] as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required
The JLS says this in section 5.1.2
A widening primitive conversion does not lose information about the overall
magnitude of a numeric value in the following cases, where the numeric value is
preserved exactly:
• from an integral type to another integral type
• from byte, short, or char to a floating-point type
• from int to double
• from float to double
In 14 it contained the following after the bullet list
A widening primitive conversion from float to double that is not strictfp may
lose information about the overall magnitude of the converted value.
Based on my reading this is a bug in the implementation? The only reliable way I've found to perform this conversion is Double.parseDouble(Float.toString(13.9f)).