10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

EXPRESSIONS Expressions and Run-Time Checks 15.5<br />

15.4 FP-strict Expressions<br />

If the type of an expression is float or double, then there is a question as to what<br />

value set (§4.2.3) the value of the expression is drawn from. This is governed by<br />

the rules of value set conversion (§5.1.13); these rules in turn depend on whether<br />

or not the expression is FP-strict.<br />

Every compile-time constant expression (§15.28) is FP-strict. If an expression<br />

is not a compile-time constant expression, then consider all the class declarations,<br />

interface declarations, and method declarations that contain the expression. If any<br />

such declaration bears the strictfp modifier, then the expression is FP-strict.<br />

If a class, interface, or method, X, is declared strictfp, then X and any class,<br />

interface, method, constructor, instance initializer, static initializer or variable initializer<br />

within X is said to be FP-strict. Note that an annotation (§9.7) element<br />

value (§9.6) is always FP-strict, because it is always a compile-time constant<br />

(§15.28).<br />

It follows that an expression is not FP-strict if and only if it is not a compiletime<br />

constant expression and it does not appear within any declaration that has the<br />

strictfp modifier.<br />

Within an FP-strict expression, all intermediate values must be elements of<br />

the float value set or the double value set, implying that the results of all FP-strict<br />

expressions must be those predicted by IEEE 754 arithmetic on operands represented<br />

using single and double formats. Within an expression that is not FP-strict,<br />

some leeway is granted for an implementation to use an extended exponent range<br />

to represent intermediate results; the net effect, roughly speaking, is that a calculation<br />

might produce “the correct answer” in situations where exclusive use of the<br />

float value set or double value set might result in overflow or underflow.<br />

DRAFT<br />

15.5 Expressions and Run-Time Checks<br />

If the type of an expression is a primitive type, then the value of the expression is<br />

of that same primitive type. But if the type of an expression is a reference type,<br />

then the class of the referenced object, or even whether the value is a reference to<br />

an object rather than null, is not necessarily known at compile time. <strong>The</strong>re are a<br />

few places in the <strong>Java</strong> programming language where the actual class of a referenced<br />

object affects program execution in a manner that cannot be deduced from<br />

the type of the expression. <strong>The</strong>y are as follows:<br />

• Method invocation (§15.12). <strong>The</strong> particular method used for an invocation<br />

o.m(...) is chosen based on the methods that are part of the class or interface<br />

411

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!