Download pdf, 392k - Sonic.net

Transcript
6.9.6.2. Exponentiation
The Borneo Math class includes three exponentiation operators (one for each primitive floating point type) that call
appropriate versions of the pow method. The exponentiation operator is written “**” as in FORTRAN. Since the
leading character of “**” is “*”, the exponentiation operator has the same precedence as multiplication and is left
associative (not right associative as in customary in mathematical notation). Therefore 2.0 ** 3.0 ** 3.0
3
evaluates to 512.0 ((23)3) instead of 134217728.0 (23 ).
6.9.6.3. Quiet Comparison Operators
One of four mutually exclusive relationships can hold when comparing two IEEE floating point numbers, the first
may be greater than the second, they may be equal, the first may be less than the second, or the two numbers could
be unordered. The unordered relation occurs when at least one of the arguments is a NaN. Therefore, in IEEE
arithmetic, a < b ≠ !( a >= b) due to the unordered relation. The standard calls for quiet comparison operators that
include the unordered relation. When the usual comparison operators other than == and != act on a NaN, the
standard requests the invalid flag be set. The operators that mention unordered are quiet; they do set the invalid flag
on a NaN argument. Thus, while the logical value of the quiet operators is expressible with combinations of existing
operators, the lack of setting the invalid flag cannot be expressed using current Java floating point operators. 30
Table 17 — New quiet comparison operators.
Operator
<?
<=?
>?
>=?
Meaning
less than or unordered
less than, equal to, or unordered
greater than or unordered
greater than, equal to, or unordered
For example, “a >= b” following the IEEE 754 standard returns true if a is greater than b or if a is equal
to b and signals invalid if either operand is a NaN. In contrast, “a >=? b” returns true if a is greater than b, if a
is equal to b, or if a is unordered with respect to b. In addition, “>=?” does not signal invalid if any of its operands
are NaN. While the logical value of “>=?” can be composed from other comparisons and the invalid flag can be
discarded if raised, distinguishing such operators can allow better compilation since the total effect of “>=?” and
related operators can be gotten from one machine instruction on many platforms. Table 17 catalogs Borneo’s new
comparison operators. Figure 43 give a Borneo implementation of “>=?”. These operators are included in Borneo’s
Math class for all three floating point types.
An alternate proposal for the functionality of “>=?” is to use “!<” (not less than) instead [56]. In IEEE
floating point, “greater than, equal to, or unordered” has the same logical value as “not less than.” The first proposal
is clearer since the operators’ characters list when the relation returns true (“>=?”, true if greater than, equal to, or
unordered) as opposed to when the relation returns false (“!<”, false if less than). Additionally, the “>=?” syntax is
closer to the notation used in the standard document. While using questions marks in operators that act on NaN may
imply to some that NaN is undefined, programmers using such comparison operators should be familiar enough with
the details of the standard to differentiate undefined from unordered.
30
In JVM, the current instructions for comparing floating point numbers return a code of –1, 0, or 1 depending on
whether the first argument is less than, equal to, or greater than the second. Therefore, all floating point comparison
operators must use the same instructions; there are no existing quiet instructions nor can existing separate strict
equality instructions be redefined to not signal. Therefore, the Borneo Virtual Machine defines the current floating
point comparison instructions to signal on NaN and adds new comparison instructions that are quiet. This means
floating point equality in Borneo a program compiled down to BVM will use different opcodes than the program
compiled with Java to JVM.
65