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-Thread: 103376,3bd77c432d79dfbc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z34g2000cwc.googlegroups.com!not-for-mail From: "Jeff Carter" Newsgroups: comp.lang.ada Subject: Re: When floating point result intervals span the boundary - what value is selected? Date: 5 Mar 2006 11:12:59 -0800 Organization: http://groups.google.com Message-ID: <1141585979.022216.245190@z34g2000cwc.googlegroups.com> References: NNTP-Posting-Host: 216.203.250.53 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1141585985 15820 127.0.0.1 (5 Mar 2006 19:13:05 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 5 Mar 2006 19:13:05 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: z34g2000cwc.googlegroups.com; posting-host=216.203.250.53; posting-account=CRM1hQ0AAADkQdMnGSPXFDwdgNRpoxjt Xref: g2news1.google.com comp.lang.ada:3271 Date: 2006-03-05T11:12:59-08:00 List-Id: Justin Gombos wrote: > > I repeated the experiment adding Sine_Type'Model_Small instead. If > Sine_Type'Last is the highest possible model number in the set, how is > it possible to add Sine_Type'Model_Small to that without throwing a > constraint error? While I expect the "+" operation to complete > because it's working with Sine_Type'Base, I expect the assignment of > that result to Oversized to fail. It must be converted back to a > model number prior to storage, and the resulting model number is out > of range. In Ada, exceptions are raised. Please do not use "throw" when discussing Ada exceptions. No. Floating-point operations only deal with a fixed number of bits in the mantissa. This gives at least the decimal number of digits given in the type declaration. When you add 2 numbers with different exponents, the smaller one is scaled to have the same exponent as the larger one before adding. When a small number like 1.0E-20 is scaled to match a much larger number like 1.0, the smaller number becomes zero. Thus, the result of the addition is 1.0. > What exactly is going on in this case? The calculations must produce > a result that is greater than 1.0, at least initially. No, they don't. > I know I'm missing something here, because I expect the following two > lines to have the exact same result: > > Oversized : Sine_Type := Sine_Type'Last + Sine_Type'Model_Number; > Oversized : Sine_Type := Sine_Type'Succ(Sine_Type'Last); > > The first line runs without error, and the second line throws a > constraint error. The first line adds zero to 1.0, giving 1.0, as described above. The second line yields the next model number of the base type > 1.0. This number exists, but is not in the range of the subtype, so Constraint_Error is raised. -- Jeff Carter jrcarter commercial-at adm [period | full stop] org