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,8d7393f07c06c5e9,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!transit3.readnews.com!textspool1.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Sat, 28 Aug 2010 18:45:16 -0400 From: "Peter C. Chapin" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Another question about fixed point types. Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4c7991c8$0$2375$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: b0f45644.news.sover.net X-Trace: DXC=XHR;5C1eKSE]dI?8hh>1UOK6_LM2JZB_C7AN`KiBGR^C:WUUlR<856OL16BAhL91ZF:USE>1CD3:C X-Complaints-To: abuse@sover.net Xref: g2news1.google.com comp.lang.ada:13789 Date: 2010-08-28T18:45:16-04:00 List-Id: Hello! Consider this type definition: type 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: function Interval_Between (Left : Julian_Day; Right : Julian_Day) return Duration is Result : Duration; begin if Left > Right then Result := 86_400.0 * (Left - Right); else Result := 86_400.0 * (Right - Left); end if; return Result; end 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? Peter P.S. The code above is a simplification of the real code, but I believe it illustrates the question I have.