J3/98-126r1
Date: February 17, 1998
To: J3
From: Interval
Subject: R4.c: Per Operation Rounding Modes, specs and syntax
References: J3/97-260, J3/98-111r2, ANSI/IEEE 754-1985
===================================================================
Changes since the February 17 version:
1. The operators **< and **> have been removed from the requirements,
since the implementation of these is as much work as implementation
of standard functions, and standard functions have been omitted
(but not prohibited) to reduce the cost of conformance.
2. The concept of value of the result has been clarified, and the
example has been improved.
3. The operations are now linked to IEEE 754 modes on machines that
support such modes. This provides regularity with the I/O
specifications in J3/98-111r2.
4. A short list of questions (straw votes?) has been added.
===================================================================
This paper advocates the semantics of the per-operation rounding
modes proposed in J3/97-260. Here, we propose an alternate syntax.
Per operation rounding is one of the six features suggested in order
to support intervals as a user-defined type.
This feature is also useful in and of itself.
Some hardware exists that supports changing the rounding mode on an
instruction by instruction basis. Other hardware is unable to switch
rounding modes quickly. Both kinds of system can possibly generate
more efficient code with this source construct.
We recommend expressing downward and upward directed rounding
arithmetic operations by postfixing a "<" or a ">" to the default
operator. Thus, there will be the following new operators:
+< +>
-< ->
*< *>
/< />
Here, "<" means downward rounding, while ">" means upward rounding.
Specifically, if A and B are real values, than the value A +< B
shall be less than or equal to the exact mathematical value of the
sum of the values A and B, while the result of A +> B shall be
greater than or equal to the exact mathematical sum. Here "value"
means the internally stored value of a real constant or variable as
defined in section 4.3.1.2 of the January 1998 Fortran 2000 draft.
For example, suppose the internally stored value for A, on a binary
machine with three binary digits, is (0.110)_2 * 2**(-3) = 3/32,
while the internal representation for B is
(.101)_2 * 2**(-1) = 5/16. Then the internal representation for
A +< B shall be less than or equal to 13/32. The largest
three-digit binary number satisfying this requirement is
(.110)_2 * 2**(-1) = 3/8.
Similarly, A +> B shall be greater than or equal to the exact
mathematical result. If A and B are as in the previous example, then
the value A +> B shall be greater than or equal to 13/32, and the
smallest number satisfying this requirement in the three-digit
binary representation is (.111)_2 * 2**(-1) = 7/16.
Similarly, A -< B shall be less than or equal to the exact mathematical
difference A - B, A -> B shall be greater than or equal to the
exact mathematical difference A - B, A *< B shall be less than or
equal to the exact mathematical product of A and B, A *> B shall be
greater than or equal to the exact mathematical product of A and B,
A /< B shall be less than or equal to the exact mathematical quotient
A / B, and A /> B shall be greater than or equal to the exact
mathematical quotient A / B.
On machines that support directed rounding as defined in section 4
of the standard ANSI/IEEE 754-1985, that is, on machines for which
the Fortran 2000 intrinsic IEEE_SUPPORT_ROUNDING(X) returns .TRUE.,
where the type of X is the type to which A and B will be converted
before the operation, +< shall correspond to downwardly rounded
addition, +> shall correspond to upwardly rounded addition, -<
shall correspond to downwardly rounded subtraction, -> shall correspond
to upwardly rounded subtraction, *> shall correspond to downwardly
rounded multiplication, *< shall correspond to upwardly rounded
multiplication, /< shall correspond to downwardly rounded division,
and /> shall correspond to upwardly rounded division as defined in
section 4.2 of ANSI/IEEE 754-1985.
In addition to the above eight operators, there shall be four conversion
functions.
ROUND_DOWN(DATUM, KIND)
has, as result a datum of kind KIND that is less than or equal to
DATUM, while
ROUND_UP(DATUM, KIND)
has, as result, a datum of kind KIND that is greater than or equal
to DATUM.
The precedence and associativity of these operators is the same as
for the corresponding operators without specified rounding. For
example, A +< B +> C may be evaluated as A +< (B +> C) or as
(A +< B) +> C, but in an expression explicitly written as
(A +< B) +> C, the parentheses must be respected. In short, the
precedence and associativity of a decorated operator is identical
to that of its undecorated counterpart. There shall be no unary
+>, +<, ->, or -<. The rules for implicit conversion shall be the
same as for the undecorated operators.
===================================================================
Questions (possible straw votes)
1. Is this document adequate for specs? If not, then:
(a) Is the IEEE binding appropriate?
(b) Should a ROUND_ZERO and ROUND_NEAR also be included?
(c) Are the precedence and associativity rules clear enough? If
not, then what should be added or modified?
2. Is the proposed syntax adequate? If not, then
(a) Should other symbols be used?
===================================================================