comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: New limited range type?
Date: Wed, 12 Nov 2003 10:34:53 -0500
Date: 2003-11-12T10:34:53-05:00	[thread overview]
Message-ID: <Y76dnVCSI5-Czi-i4p2dnA@comcast.com> (raw)
In-Reply-To: <1068649222.351052@master.nyc.kbcfp.com>

Hyman Rosen wrote:

> But in floating arithmetic, A + B - C may produce the numerically
> correct result even if A + B by itself would overflow. Would this
> need to be changed for saturating arithmetic? If A + B would saturate
> but A + B - C (in ordinary arithmetic) would not, should the result
> be required to be UPPER_LIMIT - C?

No.  This is a consequence of the principle in Ada that predefined 
operations return a value of the base type, and any constraint checks 
required for a subtype are done as part of the assignment operation.

If bounded types were added to the RM without modifying 4.5(8&10), then 
if A + B is within the range of the base type, the result of A + B - C 
would be REQUIRED to be the mathematically correct result or UPPER_LIMIT 
if (A + B - C) > UPPER_LIMIT.  If the mathematical result of A + B is 
outside the base range for the type then the permitted result set could 
contain additional values.

But assuming that type'Base'Last > 2 * Upper_Limit, then overflow would 
not be an issue (even if the value of C were less than zero).

Incidently this is an argument for adding saturating arithmetic to the 
language, as you can't do it right by overloading the math operations. 
In the case of a (language or implementation defined) attribute, you 
would have to write every calculation such as this as:

X := Some_Subtype'Limit(A + B - C);

Of course, that makes what is going on very clear...
-- 
                                           Robert I. Eachus

100% Ada, no bugs--the only way to create software.




  reply	other threads:[~2003-11-12 15:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-07 15:51 New limited range type? Martin Dowie
2003-11-07 15:57 ` Hyman Rosen
2003-11-07 16:20   ` Martin Dowie
2003-11-07 16:36     ` Stephane Richard
2003-11-07 16:59     ` Hyman Rosen
2003-11-07 18:18       ` Martin Dowie
2003-11-07 20:11         ` Larry Hazel
2003-11-07 22:40           ` Martin Dowie
2003-11-07 23:31             ` Larry Hazel
2003-11-12  8:22       ` Jean-Pierre Rosen
2003-11-12 15:00         ` Hyman Rosen
2003-11-12 15:34           ` Robert I. Eachus [this message]
2003-11-12 17:37             ` tmoran
2003-11-07 18:19   ` Mike Silva
2003-11-07 19:03   ` Marin David Condic
2003-11-07 18:05 ` Mike Silva
2003-11-08 21:58   ` Nick Roberts
2003-11-09 14:34     ` Martin Dowie
2003-11-11  5:13       ` Nick Roberts
2003-11-11 10:18         ` Martin Dowie
2003-11-11 10:35         ` Martin Dowie
2003-11-11 10:41           ` Lutz Donnerhacke
2003-11-11 12:37             ` Marin David Condic
2003-11-11 14:19             ` Martin Dowie
2003-11-11 12:34           ` Marin David Condic
replies disabled

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