From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,583275b6950bf4e6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-28 17:23:31 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!uunet!ash.uu.net!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Saturated Math Date: 28 May 2003 20:23:29 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <3ECFF541.1010705@attbi.com> <3ED0B820.5050603@noplace.com> <3ED2096F.3020800@noplace.com> <3ED353BE.40605@noplace.com> <3ED4A323.3000909@noplace.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1054167809 18318 199.172.62.241 (29 May 2003 00:23:29 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 29 May 2003 00:23:29 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:37958 Date: 2003-05-28T20:23:29-04:00 List-Id: Vinzent Hoefler writes: > IIRC such constructs *may* raise an exception if the [intermediate] > result cannot be represented (in the base type, I think). So the > result is either the correct one or you get an exception. Right. > On "normal" Integers it may > a) raise an exception > b) gives the proper result > > So there's no real ambiguity (although I must admit, different > implementation might slightly differ in their behaviour). Slightly?! Seems like a huge difference to me. If I say: type T is range 1..100; X, Y: T := 100; Z := (X + Y) / 2; on some implementations I will get the right answer, and on others, I will get an exception (because it chose T'Base to be -128...127). I think this is a flaw in Ada (although most competing languages (i.e. languages that try to do efficient arithmetic) have even worse rules). > But with saturated integers it is possible to have more than a single > result. So which result is supposed to be the correct one? > > IMO this would introduce a *very* ambiguous ambiguity. That's a good point. However, note that X+Y+Z is parsed as (X+Y)+Z, and there's an extra permission in 4.5(13) to evaluate this as X+(Y+Z), but only for predefined operators. If you write a saturating arithmetic package, with overloaded "+", then X+Y+Z will always mean (X+Y)+Z. So one could imagine a rule that said X+Y+Z will always mean (X+Y)+Z for saturating operators, if saturating types were predefined. One could also imagine that it doesn't matter: X+Y+Z might produce "infinity" or might produce the right answer. It seems to me that a saturating arithmetic ought to "stick" at infinity. If you say "X + 1000", and that returns the max, then subtracting 1 from it should return the max, not max-1. Others have said otherwise, and I wonder why. - Bob