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-30 07:13:41 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!213.200.246.247!not-for-mail From: Vinzent Hoefler Newsgroups: comp.lang.ada Subject: Re: Saturated Math Date: Fri, 30 May 2003 16:12:23 +0200 Organization: JeLlyFish software 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: 213.200.246.247 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: fu-berlin.de 1054304019 7083361 213.200.246.247 (16 [175126]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:38097 Date: 2003-05-30T16:12:23+02:00 List-Id: Robert A Duff wrote: >Vinzent Hoefler writes: > >> 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. ACK. I like understatements. ;) >> But with saturated integers it is possible to have more than a single >> result. So which result is supposed to be the correct one? >>=20 >> 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. Well, if saturated integer were a type in Ada it would have predefined operators. >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. Ok, this would be a clear rule, yes. But I still think this could be problematic, because the result of such operations perhaps weren't very intuitive. >One could also imagine that it doesn't matter: X+Y+Z might produce >"infinity" or might produce the right answer. *eek* No. We are talking about integers, so there is no infinity or some sort of magic value for that. It's just a limit that shouldn't be exceeded. I would need that for the hardware we are driving. You cannot get below or above a specific value (0 to 255 here, the DAC is just an 8-bit one). To compensate for the mechanical behaviour we sometimes have to drive that thing with a higher or lower value than it really should be (i.e. if we go from 127 to 160 we have to drive it to 163 so that the mechanical part really gets to its position "160"). But as someone can imagine I cannot drive it below 0 or above 255, so I have to saturate the "overdrive" values at that point, but of course then I still want to go into the other direction from there. So sticky or even wraparound semantics would be absolutely wrong and a constraint error isn't quite good neither. So yes, I would like the idea of saturated math but OTOH I see that this introduces too many problems if implemented as another integer type. >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. Now it's getting complex. What about: |type ... is saturated integer range ...; |type ... is sticky saturated integer range ...; Or perhaps the keywords should come before the range specification: |type ... is integer saturated range ...; |type ... is integer saturated sticky range ...; ;) > Others have said otherwise, and I wonder why. Because its more intuitive for their problem domain. It would be in mine. I have a lot of color value conversions that should stop at black or white but I still need the grey values inbetween even after some of these pixels have saturated. Vinzent. --=20 Parents strongly cautioned -- this posting is intended for mature audiences over 18. It may contain some material that many parents would not find suitable for children and may include intense violence, sexual situations, coarse language and suggestive dialogue.