* Re: Ada generics, numerics, and conversions
@ 1993-07-16 16:44 Robert I. Eachus
0 siblings, 0 replies; 2+ messages in thread
From: Robert I. Eachus @ 1993-07-16 16:44 UTC (permalink / raw)
In article <1993Jul15.223407.3677@software.org> smithd@software.org (Doug Smith
) writes:
> I could not find a language note, or LRM reference for the
> following unusual behavior. Would anyone like to comment
> on whether this is a compiler problem, or a language
> feature :-)
(Code deleted...)
The results of executing the program are:
2147483647
** MAIN PROGRAM ABANDONED -- EXCEPTION "numeric_error" RAISED
> Interestingly enough, I could not find a justification for
> the exception being raised. Paragraph 4.6(7) says "...The
> conversion of a real value to an integer type rounds to the
> nearest integer..."
> Well, for my machine, 2147483647 is the nearest integer to
> 1.0/0.0000000000000000001. However, it seems inconsistent
> for the generic form to behave differently than the
> non-generic form. This can be a sign of an erroneous
> program, but I don't see it yet.
First of all, the nearest integer (small i) to
1.0/0.0000000000000000001 is 10000000000000000000, assuming
Float'MANTISSA >= 45. The nearest value of the type Standard.Integer
is irrelevant.
Second, 4.6(2) and 4.6(12) are explict about when
CONSTRAINT_ERROR must be raised on a type conversion which is out of
range. The permissions in 11.6(6) and 11.6(7) do not really apply,
but, especially given the recent ARG discussions on this issue, I
would hesitate to call any action absent a CONSTRAINT_ERROR or others
handler a bug.
Integer'IMAGE on the other hand is not required to raise an
exception for a value out of range. In particular 'IMAGE operates on
the base type, so Positive'IMAGE(-3) should print "-3" and
Integer'IMAGE(10000000000000000000) is allowed by 11.6 to print
" 10000000000000000000".
NUMERIC_ERROR can be raised almost anyplace you are dealing with
a value outside the range of the base type, so the second result is
acceptable. It is the first result which should be questioned, since
printing Integer'LAST is never right.
--
Robert I. Eachus
with Standard_Disclaimer;
use Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Ada generics, numerics, and conversions
@ 1993-07-16 20:21 Doug Smith
0 siblings, 0 replies; 2+ messages in thread
From: Doug Smith @ 1993-07-16 20:21 UTC (permalink / raw)
> In article <1993Jul15.224245.3907@software.org> smithd@software.org (Doug Smi
th) writes:
> > [example deleted]
> > The results of executing the program are:
> > 2147483647
> > ** MAIN PROGRAM ABANDONED -- EXCEPTION "numeric_error" RAISED
> >
> > [reference to 4.6(7)]
> >
> > Well, for my machine, 2147483647 is the nearest integer to
> > 1.0/0.0000000000000000001. However, it seems inconsistent
> > [...]
> From: pelakh@convex.com (Boris Pelakh)
> 2147483647 is nowhere near 1.0/0.0000000000000000001, its just integer'last
> for a 32 bit representation. I think your second assignment is doing the righ
t
> thing, ie raising numeric_error (to be constraint in 9x). Whereas your generi
c
> is losing it. Look at the assembly, see what it does ...
> From: eachus@spectre.mitre.org (Robert I. Eachus)
> First of all, the nearest integer (small i) to
> 1.0/0.0000000000000000001 is 10000000000000000000, assuming
> Float'MANTISSA >= 45. The nearest value of the type Standard.Integer
> is irrelevant.
Thank you. Yes I had misinterpreted the LRM to mean the nearest
Standard.Integer.
But Robert I. Eachus continues, and suggests that Constraint_Error
is the correct behavior according to the LRM:
> Second, 4.6(2) and 4.6(12) are explict about when
^3 in my annotated LRM
> CONSTRAINT_ERROR must be raised on a type conversion which is out of
> range. The permissions in 11.6(6) and 11.6(7) do not really apply,
> but, especially given the recent ARG discussions on this issue, I
> would hesitate to call any action absent a CONSTRAINT_ERROR or others
> handler a bug.
>
> [Interesting points about 'Image]
Unless there is some more response, the conclusion seems to be that
the compiler is incorrect if it does not raise Constraint_Error
in both cases. I suspected the first case was incorrect and
appreciate the clear explanations (which will also help when
submitting the bug report.)
Thank you.
Doug Smith
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1993-07-16 20:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-07-16 16:44 Ada generics, numerics, and conversions Robert I. Eachus
-- strict thread matches above, loose matches on Subject: below --
1993-07-16 20:21 Doug Smith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox