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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!border3.nntp.dca.giganews.com!backlog3.nntp.dca3.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 09 Aug 2014 17:57:24 -0500 Date: Sat, 09 Aug 2014 18:57:23 -0400 From: Peter Chapin User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Preconditions which anyway would be caught? References: <7vydnShDldsh6XvO4p2dnAA@giganews.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Message-ID: X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-f2VlG5xe1EnEdnzyxdTil3LT/D0LmfkHRX8Sg4Ur4CYiN0ka8yQdEeQojrPEYRabaOB79YfaIkLhIEH!GoNytbbVjhv9bhCrz9m7gVUjutsjIJC9Fjdfnmh0+nXT02q3/O+gc7Df2kjDXzk= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2426 Xref: news.eternal-september.org comp.lang.ada:21635 Date: 2014-08-09T18:57:23-04:00 List-Id: On 2014-08-09 17:04, Niklas Holsti wrote: > Just to be a pedant: shouldn't that have some decimals on the literals: > > function Inverse(X : Float) return Float > with Pre => (X /= 0.0) is > begin > return 1.0/X; > end; > > In addition, is it really true that all Float numbers /= 0.0 can be > inverted without error? What if X is a denormalized number which has > suffered gradual underflow... won't its inverse overflow, because there > is no concept of "gradual overflow" in IEEE floats? I wondered about that also, in fact. I just tried it with your corrections so it actually *does* compile. Without any precondition SPARK 2014 complains that overflow check might fail divide by zero check might fail With the precondition of X /= 0.0 SPARK says overflow check might fail However, this proves fine: function Inverse(X : Float) return Float with Pre => not(-1.0E-35 < X and X < +1.0E-35) is begin return 1.0/X; end; I didn't experiment to see how close to zero I could make the bounds in the precondition but clearly your concern is a valid one. Peter