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,64012d256cd76a8d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-10 14:59:00 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc01.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Gnat/Windows float point Q References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 12.234.13.56 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc01 1050011930 12.234.13.56 (Thu, 10 Apr 2003 21:58:50 GMT) NNTP-Posting-Date: Thu, 10 Apr 2003 21:58:50 GMT Organization: AT&T Broadband Date: Thu, 10 Apr 2003 21:58:50 GMT Xref: archiver1.google.com comp.lang.ada:36066 Date: 2003-04-10T21:58:50+00:00 List-Id: >> Is this a legitimate output, in terms of exceptions (none), comparisons >>(the last three are False in both directions) and float'image (missing >>leading blanks and worse), from this program? > >Hard to say; I don't understand the rules of Complex math that well. But >I do find the results of the comparisons to be pretty weird. Have you >tried this on a different compiler? Neither of my other compilers has Ada.Numerics.Complex_Types. However, the complex arithmetic in this program is trivial, so I dropped that and made q&d Float functions. Gnat still screws up as before, so it's a Float, not a Complex, problem. The other two compilers raise exceptions instead of generating garbage. 1 with Ada.Exceptions, 2 ada.numerics.elementary_functions, 3 ada.text_io; 4 procedure oflow2 is 5 use ada.numerics.elementary_functions; 6 type complex is record 7 re, im : float; 8 end record; 9 function "**"(left:complex; right:positive) return complex is 10 result : complex := left; 11 begin 12 for i in 2 .. right loop 13 result := (re => left.re * result.re - left.im * result.im, 14 im => left.re * result.im + left.im * result.re); 15 end loop; 16 return result; 17 end "**"; 18 function "abs"(x : complex) return float is 19 begin 20 return ada.numerics.elementary_functions.sqrt(x.re**2 + x.im**2); 21 end "abs"; 22 function re(x:complex) return float is 23 begin return x.re;end re; 24 function im(x:complex) return float is 25 begin return x.im;end im; 26 x : complex := (4.7E+17, -1.6E+17); 27 y : float; 28 begin 29 for i in 1 .. 5 loop 30 y := abs(x); 31 ada.text_io.put_line("abs(x) = y =" & float'image(y) 32 & " y < 0.0 " & boolean'image(y < 0.0) 33 & " y >= 0.0 " & boolean'image(y >= 0.0)); 34 ada.text_io.put_line(float'image(re(x)) & float'image(im(x))); 35 ada.text_io.put_line(float'image(re(x)) & ":" & float'image(im(x))); 36 ada.text_io.new_line; 37 x := x**2; 38 end loop; 39 exception 40 when oops:others=> 41 ada.text_io.put_line(ada.exceptions.exception_information(oops)); 42 end oflow2; ----------------------- ObjectAda abs(x) = y = 4.96488E+17 y < 0.0 FALSE y >= 0.0 TRUE 4.70000E+17-1.60000E+17 4.70000E+17:-1.60000E+17 CONSTRAINT_ERROR (numeric overflow) Exception traceback: 20 oflow2.abs oflow2.adb 30 oflow2 oflow2.adb Exception handled at: 40 oflow2 oflow2.adb ----------------------- Janus abs(x) = y = 4.96488E+17 y < 0.0 FALSE y >= 0.0 TRUE 4.70000E+17-1.60000E+17 4.70000E+17:-1.60000E+17 abs(x) = y = 2.46500E+35 y < 0.0 FALSE y >= 0.0 TRUE 1.95300E+35-1.50400E+35 1.95300E+35:-1.50400E+35 CONSTRAINT_ERROR Floating Point Overflow Detected On Line Number 14 In OFLOW2.** Called from line number 37 In OFLOW2 ----------------------- Gnat abs(x) = y = 4.96488E+17 y < 0.0 FALSE y >= 0.0 TRUE 4.70000E+17-1.60000E+17 4.70000E+17:-1.60000E+17 abs(x) = y = +Inf******* y < 0.0 FALSE y >= 0.0 TRUE 1.95300E+35-1.50400E+35 1.95300E+35:-1.50400E+35 abs(x) = y = +Inf******* y < 0.0 FALSE y >= 0.0 TRUE +Inf*******-Inf******* +Inf*******:-Inf******* abs(x) = y =0.E+05 y < 0.0 FALSE y >= 0.0 FALSE 1.19442E-4946-Inf******* 0.E+05:-Inf******* abs(x) = y =0.E+05 y < 0.0 FALSE y >= 0.0 FALSE 4.84066E-4942Inf******* 0.E+05:0.E+05