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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8d7393f07c06c5e9 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!y11g2000yqm.googlegroups.com!not-for-mail From: Phil Thornley Newsgroups: comp.lang.ada Subject: Re: Another question about fixed point types. Date: Sun, 29 Aug 2010 02:02:21 -0700 (PDT) Organization: http://groups.google.com Message-ID: <62f49eaf-ed47-47c7-a13a-96ca5750b4e8@y11g2000yqm.googlegroups.com> References: <4c7991c8$0$2375$4d3efbfe@news.sover.net> NNTP-Posting-Host: 80.177.171.182 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1283072541 27926 127.0.0.1 (29 Aug 2010 09:02:21 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 29 Aug 2010 09:02:21 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y11g2000yqm.googlegroups.com; posting-host=80.177.171.182; posting-account=Fz1-yAoAAACc1SDCr-Py2qBj8xQ-qC2q User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:13793 Date: 2010-08-29T02:02:21-07:00 List-Id: On 28 Aug, 23:45, "Peter C. Chapin" wrote: > Hello! > > Consider this type definition: > > =A0 =A0type Julian_Day is delta 0.001 range 2_415_385.5 .. 2_489_665.0; > > Now consider this function that is intended to return the (approximate) > interval between two Julian days in seconds: > > =A0 =A0function Interval_Between > =A0 =A0 =A0 (Left : Julian_Day; Right : Julian_Day) return Duration is > =A0 =A0 =A0 Result : Duration; > =A0 =A0begin > =A0 =A0 =A0 if Left > Right then > =A0 =A0 =A0 =A0 =A0Result :=3D 86_400.0 * (Left - Right); > =A0 =A0 =A0 else > =A0 =A0 =A0 =A0 =A0Result :=3D 86_400.0 * (Right - Left); > =A0 =A0 =A0 end if; > =A0 =A0 =A0 return Result; > =A0 =A0end Interval_Between; > > The difference 'Left - Right' is definitely not in the range of > Julian_Day. It is likely to be a small value and could even be zero. I > understand that the computation of 'Left - Right' will be done in > Julian_Day's base type but I'm unclear what that means to me. > > It is my understanding that the compiler is allowed to choose a base > type that can only deal with the small-ish range of values between the > limits of Julian_Day. That range does not include zero. However, the > code above compiles and runs fine using GNAT GPL 2010. My test program > includes a case where Left and Right are the same so the difference is > zero. Is this code reliable or am I just seeing the effect of GNAT's > particular, implementation-specific choices? As Yannick points out, the base type will be symettric around zero. (That extra negative value is allowed so that 2's complement machines don't have work to exclude it.) With that definition, the largest value that 'Small is allowed to take is 2**-10, and the upper bound is between 2**21 and 2**22, so the minimum number of bits for the base type will be 33 (which may or may not be significant to you). Assuming that the compiler is allocating 64 bits for the type, it can choose any 'Small such that the actual range of the base type includes at least the specified range, so it could be anywhere between 2**-10, with a range -(2**53) .. (2**63 - 1)*2**-10 and 2**-41 with a range -(2**22) .. (2**63 - 1)*2**-41 (and if this is SPARK, there's no base type assertion for fixed point types...) Cheers, Phil