comp.lang.ada
 help / color / mirror / Atom feed
From: NCOHEN@IBM.COM ("Norman H. Cohen")
Subject: Fixed times Integer
Date: 30 Aug 90 15:10:20 GMT	[thread overview]
Message-ID: <9008301533.AA11448@ajpo.sei.cmu.edu> (raw)

Marc Graham questions the message indicating that NUMERIC_ERROR will
be raised at the point of the numeric literal 32768 in the following
program:

     procedure junk is

         type blarb is delta 0.1 range 0.0 .. 32769.0;
         thing : blarb;

     begin
         if thing * 32767 > thing * 32768 then
                 null;
         end if;
     end junk;

Technically, the exception is raised not by the multiplication, but by
the implicit conversion of the universal integer value 32,768 to type
Integer (which is 16 bits in Marc's implementation).  This is explicitly
justified by RM 3.5.4(10).  However, an implementation is allowed to be
more reasonable.  That same paragraph goes on to say, "However, an
implementation is not required to raise the exception NUMERIC_ERROR if
the operation is part of a larger expression whose result can be computed
correctly, as described in section 11.6."  (The full rule is given in
RM 11.6(5), which I will not quote here because all readings of that
paragraph generate more questions than they answer.)  In the example
above, there are values of THING for which the enclosing expression can
be successfully evaluated, so the compiler is not being as helpful as
it could be.  I wonder how it treats

   I: Integer := -32768;

(in which evaluation of the initial value technically consists of
conversion of the universal_integer value 32768 to type Integer
followed by invocation of the negation operator for type Integer).

             reply	other threads:[~1990-08-30 15:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-08-30 15:10 "Norman H. Cohen" [this message]
  -- strict thread matches above, loose matches on Subject: below --
1990-08-31 16:17 Fixed times Integer Marc.Graham
1990-08-29 15:54 Marc.Graham
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox