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-7-bit X-Google-Thread: 103376,f6be630961a327bf X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-09-09 19:22:28 PST Path: supernews.google.com!sn-xit-02!supernews.com!sn-inject-01!corp.supernews.com!not-for-mail From: Al Christians Newsgroups: comp.lang.ada Subject: Re: C++ to Ada95 -- bitten! Date: Sat, 09 Sep 2000 19:28:19 -0700 Organization: Trillium Resources Corporation Message-ID: <39BAF1C3.FECD497B@easystreet.com> References: <6oBu5.666$zo.17816@news1.mts.net> X-Complaints-To: newsabuse@supernews.com X-Mailer: Mozilla 4.75 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Xref: supernews.google.com comp.lang.ada:565 Date: 2000-09-09T19:28:19-07:00 List-Id: If you have a problem understanding what is going on, walk in smaller steps. I tend to overuse parentheses and split complications into separate statements. For example: Really_Small_Number := 2.7183 ** (-5340); g := (Really_Small_Number / f) + 21.5; That's probably not what you wanted. How about: G_Exponent := -5340.0/ f; g := 2.7183 ** G_Exponent + 21.5; If you break the expression up into separate statements, the statement number out of the crash yields more information. Sometimes my code is criticized for including redundant parentheses, but that's much better than spacing that suggests an order of operations to humans but doesn't mean anything to the compiler. Your: > g := 2.7183 ** (-5340)/f + 21.5; has (-5340)/f closely spaced as a clue that it happens before the exponentiation. Check the reference manual (4.5) for the facts. I'd always make it explicit, either g := ((2.7183 ** (-5340))/f) + 21.5; or g := (2.7183 ** (-5340/f)) + 21.5; I might omit the outermost set of parens, since everyone(?) knows(?) that addition happens last. It just depends on the situation and on who I guessed might eventually be reading my code. Al Nick J Chackowsky wrote: > > So just when I think I'm getting the idea of Ada95, along comes this > problem, demonstrated by an admittedly contrived program. Gnat 3.13p crashes > trying to compile this: > > with ada.float_text_io; > with ada.numerics; > with ada.numerics.elementary_functions; > use ada.numerics.elementary_functions; > procedure crash is > f, g : float; > begin > ada.float_text_io.get(f); > g := 2.7183 ** (-5340)/f + 21.5; > end crash; > > Now, I can eliminate the problem by changing the -5340 to -5340.0, but it > took me a *long* time to see that (in a student's code). I actually thought > I had a virus infecting the student's computer until I watched the "problem" > follow him from workstation to workstation! > > I guess my question is, what _category_ of error is this? I know to look > (now) for an integer in a floating-point calculation, but that doesn't tell > me what _else_ I should be looking for to avoid these "virus-like" crashes. > > -- > ===================================== > N J Chackowsky > Brandon, MB Canada