Search code examples
javajls

JLS appears to contradict itself


Please review the Oracle Specification - Chapter 5.

This line:

A widening primitive conversion does not lose information about the overall magnitude of a numeric value.

is followed , just 2 lines below, by this line which says that magnitude information can be lost.

A widening primitive conversion from float to double that is not strictfp may lose information about the overall magnitude of the converted value.

This seems like an obvious contradiction; is this a mistake?


Solution

  • For what it's worth, the JVM specification is a little bit clearer in the wording in 2.11.4:

    Widening numeric conversions do not lose information about the overall magnitude of a numeric value. Indeed, conversions widening from int to long and int to double do not lose any information at all; the numeric value is preserved exactly. Conversions widening from float to double that are FP-strict (§2.8.2) also preserve the numeric value exactly; however, such conversions that are not FP-strict may lose information about the overall magnitude of the converted value.