Version 1.1 of ais/ai-00432.txt
!standard D.8 (24) 05-05-05 AI95-00432/01
!standard D.8 (26)
!class binding interpretation 05-04-18
!status Amendment 200Y 05-05-05
!status ARG Approved 10-0-0 05-04-18
!status work item 05-04-18
!status received 05-04-18
!priority Medium
!difficulty Easy
!subject Out of range values in Ada.Real_Time
!summary
If a value given to Ada.Real_Time.To_Duration or
Ada.Real_Time.To_Time_Span cannot be represented as a value of the
result type, Constraint_Error is raised.
!question
Ada.Real_Time defines functions To_Duration and To_Time_Span for
converting between Duration and Ada.Real_Time.Time_Span types.
It is likely that these two types do not represent the same range of
time intervals. (Duration is required to represent intervals up to
one day; Time_Span is required to represent intervals only up to one
hour.) However, the Standard says nothing whatsoever about what happens
when To_Time_Span is given a Duration argument that is out of range
for a Time_Span, or vice versa. Since Time_Span is not a numeric type,
that does not follow from other rules. What happens in this case?
(Constraint_Error is raised.)
!recommendation
(See summary.)
!wording
Change D.8(24) to say:
The function To_Duration converts the value TS to a value of type
Duration. Similarly, the function To_Time_Span converts the value D
to a value of type Time_Span. For To_Duration, the result is rounded
to the nearest value of type Duration (away from zero if exactly
halfway between two values). If the result is outside the range of
Duration, Constraint_Error is raised. For To_Time_Span, the value
of D is first rounded to the nearest integral multiple of Time_Unit,
away from zero if exactly halfway between two multiples. If the
rounded value is outside the range of Time_Span, Constraint_Error is
raised. Otherwise, the value is converted to the type Time_Span.
Change D.8(26) (as modified by AI-386) to say:
The functions Nanoseconds, Microseconds, and Milliseconds, Seconds,
and Minutes convert the input parameter to a value of the type
Time_Span. NS, US, MS, S, and M are interpreted as a number of
nanoseconds, microseconds, and milliseconds, seconds, and minutes
respectively. The input parameter is first converted to seconds and
rounded to the nearest integral multiple of Time_Unit, away from
zero if exactly halfway between two multiples. If the rounded value
is outside the range of Time_Span, Constraint_Error is raised.
Otherwise, the rounded value is converted to the type Time_Span.
!discussion
Note that Time_Span is not a numeric type, so we have to have these convoluted
rules rather than just saying that the value is out of range.
!corrigendum D.8(24)
Replace the paragraph:
The function To_Duration converts the value TS to a value of type Duration.
Similarly, the function To_Time_Span converts the value D to a value of type
Time_Span. For both operations, the result is rounded to the nearest exactly
representable value (away from zero if exactly halfway between two exactly
representable values).
by:
The function To_Duration converts the value TS to a value of type Duration.
Similarly, the function To_Time_Span converts the value D to a value of type
Time_Span. For To_Duration, the result is rounded
to the nearest value of type Duration (away from zero if exactly
halfway between two values). If the result is outside the range of
Duration, Constraint_Error is raised. For To_Time_Span, the value
of D is first rounded to the nearest integral multiple of Time_Unit,
away from zero if exactly halfway between two multiples. If the
rounded value is outside the range of Time_Span, Constraint_Error is
raised. Otherwise, the value is converted to the type Time_Span.
!corrigendum D.8(26)
Replace the paragraph:
The functions Nanoseconds, Microseconds, and Milliseconds convert the input
parameter to a value of the type Time_Span. NS, US, and MS are interpreted as a
number of nanoseconds, microseconds, and milliseconds respectively. The result
is rounded to the nearest exactly representable value (away from zero if
exactly halfway between two exactly representable values).
by:
The functions Nanoseconds, Microseconds, and Milliseconds, Seconds,
and Minutes convert the input parameter to a value of the type
Time_Span. NS, US, MS, S, and M are interpreted as a number of
nanoseconds, microseconds, and milliseconds, seconds, and minutes
respectively. The input parameter is first converted to seconds and
rounded to the nearest integral multiple of Time_Unit, away from
zero if exactly halfway between two multiples. If the rounded value
is outside the range of Time_Span, Constraint_Error is raised.
Otherwise, the rounded value is converted to the type Time_Span.
!ACATS Test
ACATS C-Test(s) should be created to insure that no exception is raised by
operations that are excluded from the bounded error.
!appendix
!topic Out-of-range conversions in Ada.Real_Time
!reference RM95 D.8
!from Adam Beneschan 04-12-23
!discussion
Ada.Real_Time defines functions To_Duration and To_Time_Span for
converting between Duration and Ada.Real_Time.Time_Span types.
It is likely that these two types do not represent the same range of
time intervals. (Duration is required to represent intervals up to
one day; Time_Span is required to represent intervals only up to one
hour.) However, the RM says nothing whatsoever about what happens
when To_Time_Span is given a Duration argument that is out of range
for a Time_Span, or vice versa. I believe this is an omission in the
RM. Since Time_Span is a private type and not a numeric type
(although it represents a number), I don't think that the correct
behavior in this case (e.g. raising Constraint_Error) follows from any
rule elsewhere in the RM, unless I've missed something.
****************************************************************
Questions? Ask the ACAA Technical Agent