!standard 04.09 (38) 95-10-21 AI95-00100/01
!class ramification 95-10-12
!status work item 95-10-21
!status received 95-10-12
!priority Medium
!difficulty Medium
!subject Truncation required if Machine_Rounds false?
!summary 95-10-12
!question 95-10-12
!response 95-10-12
!appendix 95-10-21
!section 4.9(38)
!subject Truncation required if Machine_Rounds false?
!reference RM95-4.9(38), RM95-A.5.3(11)
!from Jim Ledger 95-10-09
<>
!discussion
The following portion of 4.9(38) can be interpreted to mean that, for a real
static expression that is not part of a larger static expression, if
Machine_Rounds is false for the expected type, the implementation *must*
truncate the value to the nearest machine number:
For a real static expression that is not part of a larger static
expression, and whose expected type is not a descendant of a formal
scalar type, THE IMPLEMENTATION SHALL ROUND OR TRUNCATE THE VALUE
(ACCORDING TO THE MACHINE_ROUNDS ATTRIBUTE OF THE EXPECTED TYPE) to
the nearest machine number of the expected type..."
However, A.5.3(11) says that T'Machine_Rounds is true if rounding is performed
on inexact results of every predefined operation yielding a result of type T,
and is false otherwise. The implication here is that if Machine_Rounds is
false, the implementation *may* but need not truncate the value.
Is the intent of 4.9(38) to *require* truncation for values of static
expressions if Machine_Rounds is false?
Furthermore, I presume (based on e-mail from Tucker Taft in another forum)
that 4.9(38) is intended to apply to fixed point expected types as well as
floating point, even though the concept of "machine numbers" is not defined
for fixed point types. That is, one can substitute "integral multiple of
the small" for "machine number" in 4.9(38) to get the corresponding rule
for fixed point types.
Is truncation (to a multiple of small) *required* if the expected type is
ordinary fixed point and Machine_Rounds is false? What about decimal fixed
point?
The issue for fixed point types is clouded by AARM 4.9(38.d), which implies
that truncation is mandated for static conversion to a fixed point type or
division by integer. I don't see why truncation (regardless of the value of
Machine_Rounds) should be required in all cases, and only for these two
operations. When this paragraph says "...must do truncation..." should it
have said "...must do truncation or rounding...?"
Jim Ledger
ACVC Team
jim@sis.saic.com
****************************************************************
!section 4.9(38)
!subject Truncation required if Machine_Rounds false?
!reference RM95-4.9(38), RM95-A.5.3(11)
!reference 95-5320.a Jim Ledger 95-10-10
!from Ted Baker95-10-11
<>
!discussion
| The issue for fixed point types is clouded by AARM 4.9(38.d), which implies
| that truncation is mandated for static conversion to a fixed point type or
| division by integer. I don't see why truncation (regardless of the value of
| Machine_Rounds) should be required in all cases, and only for these two
| operations. When this paragraph says "...must do truncation..." should it
| have said "...must do truncation or rounding...?"
There is one important reason for requiring truncation for
fixed-point arithmetic. The type Duration is fixed-point.
Real-time programs sometimes need to do potentially inexact
computations with Duration, such as division to convert between a
rate and a period, or multiplication of a period times an
interation count. With truncation, the error introduced by such
computations can be analyzed precisely, and compensation can be
made for cumulative errors. On the other hand, with rounding, it
does not just require more complex computations, but the direction
of single-bit rounding is not predictable (could round up or
down).
The issue is especially important for static expressions, because
of the case of task periods (or other time intervals) that are
specified by constants that cannot be represented exactly in
binary, like 0.001. We need to know what Duration(0.001) means.
--Ted Baker
****************************************************************
!section 4.9(38)
!subject Truncation required if Machine_Rounds false?
!reference RM95-4.9(38), RM95-A.5.3(11)
!reference 95-5320.a Jim Ledger 95-10-10
!reference as: 95-5323.a Ted Baker 95-10-11
!from Robert Dewar 95-10-11
!reference as: 95-5330.a Robert Dewar 95-10-12>>
!discussion
I am surprised that people are seriously considering the possibility of
requiring truncation for (non-decimal) fixed-point. If the RM says this,
it is an unintentional consequence that the ARG should fix. The intention
is that fixed-point semantics in Ada 95 be essentially identical to those
in Ada 83, expect for relaxing some accuracy requirements. We certainly
do NOT want to *add* accuracy requirements. The idea of existing Ada 83
implementations having to go to lots of effort to adjust their existing
implementation of ordinary fixed-point is an unacceptable one. Fixed-point
is simply not important enough to be worth a major incompatible change
(incompatible in the implementation sense, rather than the formal semantic
sense).
****************************************************************
!section 4.9(38)
!subject Truncation required if Machine_Rounds false?
!reference RM95-4.9(38), RM95-A.5.3(11)
!reference 95-5320.a Jim Ledger 95-10-10
!from Jim Ledger 95-10-12
!reference 95-5337.a Jim Ledger 95-10-13>>
!discussion
> There is one important reason for requiring truncation for
> fixed-point arithmetic. The type Duration is fixed-point.
> Real-time programs sometimes need to do potentially inexact
> computations with Duration, such as division to convert between a
> rate and a period, or multiplication of a period times an
> interation count. With truncation, the error introduced by such
> computations can be analyzed precisely, and compensation can be
> made for cumulative errors. On the other hand, with rounding, it
> does not just require more complex computations, but the direction
> of single-bit rounding is not predictable (could round up or
> down).
>
> The issue is especially important for static expressions, because
> of the case of task periods (or other time intervals) that are
> specified by constants that cannot be represented exactly in
> binary, like 0.001. We need to know what Duration(0.001) means.
>
> --Ted Baker
That all sounds reasonable, but does 4.9(38) actually require such
truncation? If so, is it only required if Machine_Rounds is false?
Is it required for decimal as well as ordinary fixed point types?
Is it required for floating point types as well (when Machine_Rounds
is false)?
Jim Ledger
ACVC Team
jim@sis.saic.com
****************************************************************
!section 4.9(38)
!subject Truncation required if Machine_Rounds false?
!reference RM95-4.9(38), RM95-A.5.3(11)
!reference 95-5320.a Jim Ledger 95-10-10
!reference as: 95-5323.a Ted Baker 95-10-11
!reference 95-5330.a Robert Dewar 95-10-12
!from Ted Baker 95-10-13
!reference 95-5338.a Ted Baker 95-10-13>>
!discussion
| I am surprised that people are seriously considering the possibility of
| requiring truncation for (non-decimal) fixed-point. If the RM says this,
| it is an unintentional consequence that the ARG should fix.
You should not be surprised, and it is intentional, since we had a
rather lengthy discussion of it at a WG9 meeting in Boston.
--Ted Baker
****************************************************************