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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,75f197493b7ab882 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!feeder.news-service.com!transit4.hitnews.eu!transit5.hitnews.eu!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Forcing exceptions on NANs with GNAT? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Thu, 20 Nov 2008 14:46:12 +0100 Message-ID: NNTP-Posting-Date: 20 Nov 2008 14:46:12 CET NNTP-Posting-Host: 833c39b2.newsspool2.arcor-online.net X-Trace: DXC=m<=4fK\NDZ:^8FBo0_81f>A9EHlD;3Yc24Fo<]lROoR1^YC2XCjHcb9`d7CP3Joi5;DNcfSJ;bb[5FCTGGVUmh?4LK[5LiR>kg2;YmeOh2`Af5 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:2710 Date: 2008-11-20T14:46:12+01:00 List-Id: On Thu, 20 Nov 2008 12:09:41 +0100, Markus Schoepflin wrote: > is it possible to influence the behaviour of GNAT regarding the handling of > NANs? (Most importantly in the special case of division by zero.) > > We need to get exceptions whenever a NAN is generated, is this possible > somehow? (For example by setting Machine_Overflow to True and recompiling > the compiler itself.) You can scrap IEEE stuff in favor of Ada semantics by declaring your own floating-point [sub]type with a range specified. The compiler will be forced to check values: type Safe_Float is digits 6 range -10.0E10..+10.0E10; or subtype Safe_Float is Float range Float'Range; then X : Safe_Float := 1.0; Y : Safe_Float := 0.0; begin Y := X / Y; exception when Error : others => -- Should print "range check failed" Put_Line (Exception_Message (Error)); end; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de