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 X-Received: by 10.224.54.73 with SMTP id p9mr33887153qag.1.1373773901143; Sat, 13 Jul 2013 20:51:41 -0700 (PDT) X-Received: by 10.50.57.112 with SMTP id h16mr535256igq.5.1373773901096; Sat, 13 Jul 2013 20:51:41 -0700 (PDT) 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!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!t19no1441423qam.0!news-out.google.com!f7ni2314qai.0!nntp.google.com!t19no1534948qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 13 Jul 2013 20:51:40 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=97.117.199.112; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG NNTP-Posting-Host: 97.117.199.112 References: <74c64a2c-f062-4b59-aafb-40c0bac39203@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4a7cb9fc-840c-4ada-be8e-42313e09d737@googlegroups.com> Subject: Re: GNAT does not consistently raise an exception to log(0.0) From: Jerry Injection-Date: Sun, 14 Jul 2013 03:51:41 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 3729 Xref: news.eternal-september.org comp.lang.ada:16350 Date: 2013-07-13T20:51:40-07:00 List-Id: On Saturday, July 13, 2013 12:26:18 AM UTC-7, Dmitry A. Kazakov wrote: > On Fri, 12 Jul 2013 17:52:08 -0700 (PDT), Jerry wrote: > > > When the following program is built with any of theses compilers: > > > > GNATMAKE GPL 2013 (20130314) (downloaded from AdaCore) > > GNATMAKE GPL 2011 (20110419) (downloaded from AdaCore) > > GNATMAKE 4.8.0 (Simon Wright's build) > > > > like this: > > > > $ gnatmake -f bomb_log.adb -OX > > > > then if X = 0 (zero) the expected exception is raised and reported thusly: > > > > raised CONSTRAINT_ERROR : a-ngelfu.adb:744 explicit raise > > > > else if X > 0 no exception is raised. > > > > with Ada.Numerics.Long_Elementary_Functions; > > use Ada.Numerics.Long_Elementary_Functions; > > procedure Bomb_Log is > > x : Long_Float; > > begin > > x := log(0.0); > > end Bomb_Log; > > You should always be careful about bogus IEEE 754 semantics when using > numeric operations. I presume that your machine has Long_Float implemented > by machine's IEEE 754. log returns NaN or -Inf. It's Intel hardware. GNAT does not allow the request for log(0.0) to even get to the hardwdare because it special-cases it in a-ngelfu.adb:744: elsif X = 0.0 then raise Constraint_Error; >When you turn optimization > -O2 it slips through. I cannot tell how consistent is that with RM, I > presume it is. Maybe -O0 should not raise Constrant_Error. I am not a > language lawyer. > > Anyway, in order to enforce sane numeric semantics you do: > > with Ada.Numerics.Long_Elementary_Functions; > use Ada.Numerics.Long_Elementary_Functions; > procedure Bomb_Log is > subtype Proper_Float is Long_Float range Long_Float'Range; > x : Proper_Float; > begin > x := log(0.0); > end Bomb_Log; > > This should work as expected. I'll look into this, but it messes up a lot of other stuff like the nice stuff in Annex G.3, I suppose. Jerry > > > However, under the same conditions as above, the following program raises > > the exception always: > > > > with Ada.Numerics.Long_Elementary_Functions; > > use Ada.Numerics.Long_Elementary_Functions; > > with Ada.Text_IO; > > use Ada.Text_IO; > > procedure Bomb_Log is > > x : Long_Float; > > begin > > x := log(0.0); > > Put_Line(Long_Float'Image(x)); > > end Bomb_Log; > > I suppose that here you get the exception rather from Long_Float'Image, > when it stumbles on NaN or whatever garbage log returned. > > -- > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de