3

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?

arshajii
  • 127,459
  • 24
  • 238
  • 287
nativist.bill.cutting
  • 1,292
  • 3
  • 11
  • 19

3 Answers3

3

Yes, it does. From the Oracle:

Hi Bill,

Thanks for your mail. I agree there is a contradiction between:

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

and:

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

Only the first sentence appeared in the First Edition of the JLS, prior to the introduction of strictfp. The second sentence appeared in the Second Edition of the JLS, as part of strictfp support, and the first sentence should have been modified at the same time. In the Java SE 8 Edition, I will clarify that only some widening primitive conversions do not lose magnitude information.

nativist.bill.cutting
  • 1,292
  • 3
  • 11
  • 19
2

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.

assylias
  • 321,522
  • 82
  • 660
  • 783
  • 2
    ... I am convinced this is wrong too, but b.c. now there are two references, I'm going to ask a linguist or English professor. Perhaps my understanding of English is off, but saying `Widening numeric conversions do not lose information about the overall magnitude of a numeric value.` ... and then saying except in this certain case, I think is logically wrong, but more importantly misleading if you for example, quit reading before you get to the last sentence. – nativist.bill.cutting Oct 01 '13 at 16:21
  • @nativist.bill.cutting I think that is is assumed that the reader understands that non strict fp operation can cause "errors" in general and that the first sentence only applies to "well formed" conversions (i.e. FP-strict). But I agree with you that the wording is poor. – assylias Oct 01 '13 at 16:59
1

It's more of a clarification. In the specific case of a float to double conversion, there is no guarantee of not losing information unless strictfp is designated

Michael Hoyle
  • 249
  • 2
  • 9
  • But that still contradicts the previous statement. – arshajii Oct 01 '13 at 13:34
  • If you're splitting hairs, yes. The fact that they are directly next to each other in documentation means they go together, and one is a clarification of a specific instance of the other. It's like saying all lawns are green in the summer. If it gets too hot, then there is a risk it won't be green unless it's properly taken care of. – Michael Hoyle Oct 01 '13 at 13:42