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=0.6 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, HK_RANDOM_FROM autolearn=no 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!news3.google.com!news.glorb.com!cycny01.gnilink.net!spamkiller.gnilink.net!gnilink.net!trnddc08.POSTED!20ae255c!not-for-mail Newsgroups: comp.lang.ada From: Justin Gombos Subject: Re: When floating point result intervals span the boundary - what value is selected? References: User-Agent: slrn/0.9.8.1 (Linux) Message-ID: Date: Sat, 04 Mar 2006 16:46:32 GMT NNTP-Posting-Host: 129.44.77.228 X-Complaints-To: abuse@verizon.net X-Trace: trnddc08 1141490792 129.44.77.228 (Sat, 04 Mar 2006 11:46:32 EST) NNTP-Posting-Date: Sat, 04 Mar 2006 11:46:32 EST Xref: g2news1.google.com comp.lang.ada:3266 Date: 2006-03-04T16:46:32+00:00 List-Id: On 2006-03-03, Jeffrey R. Carter wrote: > Justin Gombos wrote: > >> Oversized : Sine_Type := Sine_Type'Last + Sine_Type'Small; > > This is odd; 'Small is defined only for fixed-point types (ARM > K). Maybe this is compiler specific. You should probably use > 'Model_Small. > > Anyway, since 'Small gives 2.58494E-26 and you probably have 6 > digits of accuracy, 1.0 + 'Small = 1.0. Remember that "+" is defined > for the base type. 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. >> Well_Oversized : constant Float := Float(Sine_Type'Last) + >> Float(Sine_Type'Small * 500000.0); > > Similarly here, 5.0E5 * 2.58494E-26 ~ 1.3E-20, and 1.0 + 1.3E-20 = > 1.0 with 6 digits of accuracy. What exactly is going on in this case? The calculations must produce a result that is greater than 1.0, at least initially. Is the runtime logic rounding toward zero when the difference is within accuracy constraints? Does an Ada compiler have the option to throw a constraint error? 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. -- PM instructions: do a C4esar Ciph3r on my address; retain punctuation.