comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Gnat/Windows float point Q
Date: Thu, 10 Apr 2003 21:58:50 GMT
Date: 2003-04-10T21:58:50+00:00	[thread overview]
Message-ID: <uOlla.403747$3D1.217339@sccrnsc01> (raw)
In-Reply-To: v9behjca6ifi07@corp.supernews.com

>>  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



  reply	other threads:[~2003-04-10 21:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-08 21:00 Gnat/Windows float point Q tmoran
2003-04-09  6:47 ` Eric G. Miller
2003-04-09  8:30   ` tmoran
2003-04-09 21:11     ` Randy Brukardt
2003-04-10  6:23       ` tmoran
2003-04-10 18:39         ` Randy Brukardt
2003-04-10 21:58           ` tmoran [this message]
2003-04-11  0:52             ` David C. Hoos, Sr.
2003-04-11  1:37               ` tmoran
2003-04-11  4:24                 ` Eric G. Miller
2003-04-11 19:11         ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox