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-Language: ENGLISH,ASCII X-Google-Thread: 103376,734832b8ad479964 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-05 10:58:42 PST Path: newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!129.240.148.23!uio.no!ntnu.no!randhol+abuse From: randhol+abuse@pvv.org (Preben Randhol) Newsgroups: comp.lang.ada Subject: Re: Catching NaN .. not a number Date: Sat, 5 May 2001 17:58:42 +0000 (UTC) Organization: Norwegian university of science and technology Message-ID: References: <9d1eai$3nf$1@eol.dd.chalmers.se> NNTP-Posting-Host: kiuk0156.chembio.ntnu.no Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: tyfon.itea.ntnu.no 989085522 10973 129.241.83.82 (5 May 2001 17:58:42 GMT) X-Complaints-To: usenet@itea.ntnu.no NNTP-Posting-Date: Sat, 5 May 2001 17:58:42 +0000 (UTC) User-Agent: slrn/0.9.7.0 (Linux) Xref: newsfeed.google.com comp.lang.ada:7204 Date: 2001-05-05T17:58:42+00:00 List-Id: On 5 May 2001 17:46:58 GMT, Staffan Dittmer wrote: > Did some calcualtions during the night and > ended up with an output file full of NaN - due to > overflow when calculating a factorial. > > A bit surprised by this since I thought a Constraint Error > would be raised. > > So, how do I catch a NaN result ? Which compiler? When you say calculating factorial, do you use integer? If so and If you use GNAT you have to compile your program with this switch: `-gnato' Enables overflow checking for integer operations. This causes GNAT to generate slower and larger executable programs by adding code to check for both overflow and division by zero (resulting in raising `Constraint_Error' as required by Ada semantics). Note that the `-gnato' switch does not affect the code generated for any floating-point operations; it applies only to integer operations. For floating-point, GNAT has the `Machine_Overflows' attribute set to `False' and the normal mode of operation is to generate IEEE NaN and infinite values on overflow or invalid operations (such as dividing 0.0 by 0.0). -- Preben Randhol ------------------- http://www.pvv.org/~randhol/ -- �For me, Ada95 puts back the joy in programming.�