* Gnat/Windows float point Q @ 2003-04-08 21:00 tmoran 2003-04-09 6:47 ` Eric G. Miller 0 siblings, 1 reply; 11+ messages in thread From: tmoran @ 2003-04-08 21:00 UTC (permalink / raw) What does it mean when float'image(x) = " 47.720649 0.E+05" ? ??? Is x a NAN or something? It causes a Constraint_Error in the "return x" statement in: subtype units is float range 0.0 .. 1.0; function clip(x: float) return units is begin if x < 0.0 then return 0.0; elsif x > 1.0 then return 1.0; else return x; end if; end clip; ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 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 0 siblings, 1 reply; 11+ messages in thread From: Eric G. Miller @ 2003-04-09 6:47 UTC (permalink / raw) In <1MGka.57623$ug3.113346@rwcrnsc51.ops.asp.att.net>, tmora wrote: > What does it mean when float'image(x) = " 47.720649 0.E+05" ? > ??? > > Is x a NAN or something? It causes a Constraint_Error in > the "return x" statement in: > > subtype units is float range 0.0 .. 1.0; > function clip(x: float) return units is > begin > if x < 0.0 then return 0.0; > elsif x > 1.0 then return 1.0; > else return x; > end if; > end clip; Check X'Valid if the data comes from some route like Unchecked_Conversion. The following demonstrates the conversion error on some systems.. with Ada.Text_Io; use Ada.Text_Io; with Ada.Unchecked_Conversion; procedure Unitarians is subtype Units is Float range 0.0 .. 1.0; function Clip(X: Float) return Units is begin if X'Valid = False then raise Constraint_Error; end if; if X < 0.0 then return 0.0; elsif X > 1.0 then return 1.0; else return X; end if; end Clip; type Byte4 is mod 2**32; function To_Float is new Ada.Unchecked_Conversion (Byte4, Float); U : Units; F : Float; UI : Byte4 := 16#FFFF_FFFF#; begin Put_Line ("UI = " & Byte4'Image (UI)); F := To_Float (UI); Put_Line ("F is valid? --> " & Boolean'Image(F'Valid)); U := Clip (F); Put_Line ("U = " & Units'Image(U)); end Unitarians; -- echo ">gra.fcw@2ztr< eryyvZ .T pveR" | rot13 | reverse ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 2003-04-09 6:47 ` Eric G. Miller @ 2003-04-09 8:30 ` tmoran 2003-04-09 21:11 ` Randy Brukardt 0 siblings, 1 reply; 11+ messages in thread From: tmoran @ 2003-04-09 8:30 UTC (permalink / raw) >> What does it mean when float'image(x) = " 47.720649 0.E+05" ? > Check X'Valid if the data comes from some route like Unchecked_Conversion. In this case X comes from Ada.Numerics.Complex_Types.Abs(Y) and Y came from Z**2, so it might well overflow. Float'Machine_Overflows is False, so I can't expect an exception, but is an overflowed value on Gnat/Windows something that is always False in a compare, and generates garbage for float'image? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 2003-04-09 8:30 ` tmoran @ 2003-04-09 21:11 ` Randy Brukardt 2003-04-10 6:23 ` tmoran 0 siblings, 1 reply; 11+ messages in thread From: Randy Brukardt @ 2003-04-09 21:11 UTC (permalink / raw) tmoran@acm.org wrote in message ... >>> What does it mean when float'image(x) = " 47.720649 0.E+05" ? >> Check X'Valid if the data comes from some route like Unchecked_Conversion. >In this case X comes from Ada.Numerics.Complex_Types.Abs(Y) >and Y came from Z**2, so it might well overflow. Float'Machine_Overflows >is False, so I can't expect an exception, but is an overflowed value >on Gnat/Windows something that is always False in a compare, and >generates garbage for float'image? I'd expect the result of such an operation to be either +infinity or -infinity. Those compare as you expect, and probably raise Constraint_Error when stored (if they didn't do that, the compiler would be violating the rule about math always returning the correct result or raising an exception). Randy. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 2003-04-09 21:11 ` Randy Brukardt @ 2003-04-10 6:23 ` tmoran 2003-04-10 18:39 ` Randy Brukardt 2003-04-11 19:11 ` Simon Wright 0 siblings, 2 replies; 11+ messages in thread From: tmoran @ 2003-04-10 6:23 UTC (permalink / raw) > I'd expect the result of such an operation to be either +infinity > or -infinity. Those compare as you expect, and probably raise > Constraint_Error when stored (if they didn't do that, the compiler would > be violating the rule about math always returning the correct result or > raising an exception). 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? with ada.numerics.complex_types, ada.text_io; procedure oflow is use ada.numerics.complex_types; x : complex := (4.7E+17, -1.6E+17); y : float; begin for i in 1 .. 5 loop y := abs(x); ada.text_io.put_line("abs(x) = y =" & float'image(y) & " y < 0.0 " & boolean'image(y < 0.0) & " y >= 0.0 " & boolean'image(y >= 0.0)); ada.text_io.put_line(float'image(re(x)) & float'image(im(x))); ada.text_io.put_line(float'image(re(x)) & ":" & float'image(im(x))); ada.text_io.new_line; x := x**2; end loop; end oflow; 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 abs(x) = y =1.95300E+05 y < 0.0 FALSE y >= 0.0 FALSE +Inf*******1.50400E+05 +Inf*******:1.50401E+05 abs(x) = y =+Inf******* y < 0.0 FALSE y >= 0.0 FALSE 3.36210E-49321.50401E+05 9.52681E+139:1.50402E+05 abs(x) = y =9.52681E+05 y < 0.0 FALSE y >= 0.0 FALSE 0.E+051.50402E+05 3.64520E-4951:1.50403E+05 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 2003-04-10 6:23 ` tmoran @ 2003-04-10 18:39 ` Randy Brukardt 2003-04-10 21:58 ` tmoran 2003-04-11 19:11 ` Simon Wright 1 sibling, 1 reply; 11+ messages in thread From: Randy Brukardt @ 2003-04-10 18:39 UTC (permalink / raw) tmoran@acm.org wrote in message ... >> I'd expect the result of such an operation to be either +infinity >> or -infinity. Those compare as you expect, and probably raise >> Constraint_Error when stored (if they didn't do that, the compiler would >> be violating the rule about math always returning the correct result or >> raising an exception). > > 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? Randy. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 2003-04-10 18:39 ` Randy Brukardt @ 2003-04-10 21:58 ` tmoran 2003-04-11 0:52 ` David C. Hoos, Sr. 0 siblings, 1 reply; 11+ messages in thread From: tmoran @ 2003-04-10 21:58 UTC (permalink / raw) >> 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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 2003-04-10 21:58 ` tmoran @ 2003-04-11 0:52 ` David C. Hoos, Sr. 2003-04-11 1:37 ` tmoran 0 siblings, 1 reply; 11+ messages in thread From: David C. Hoos, Sr. @ 2003-04-11 0:52 UTC (permalink / raw) To: comp.lang.ada mail to news gateway Could this paragraph from the GNAT Reference Manual have any bearing on this problem? 9.31 GNAT.Float_Control (`g-flocon.ads') Provides an interface for resetting the floating-point processor into the mode required for correct semantic operation in Ada. Some third party library calls may cause this mode to be modified, and the Reset procedure in this package can be used to reestablish the required mode. ----- Original Message ----- From: <tmoran@acm.org> Newsgroups: comp.lang.ada To: <comp.lang.ada@ada.eu.org> Sent: April 10, 2003 4:58 PM Subject: Re: Gnat/Windows float point Q > >> 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 > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 2003-04-11 0:52 ` David C. Hoos, Sr. @ 2003-04-11 1:37 ` tmoran 2003-04-11 4:24 ` Eric G. Miller 0 siblings, 1 reply; 11+ messages in thread From: tmoran @ 2003-04-11 1:37 UTC (permalink / raw) > Could this paragraph from the GNAT Reference Manual have any bearing on > this problem? > > 9.31 GNAT.Float_Control (`g-flocon.ads') I added a "with" and inserted as the first line after "begin" GNAT.Float_Control.Reset; It made no difference. I'm using Gnat 3.15p on Windows. Perhaps newer versions work differently? BTW, I note that "-gnato -O2" generates somewhat different results - still screwy in the same ways, but different. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 2003-04-11 1:37 ` tmoran @ 2003-04-11 4:24 ` Eric G. Miller 0 siblings, 0 replies; 11+ messages in thread From: Eric G. Miller @ 2003-04-11 4:24 UTC (permalink / raw) In article <U%ola.405441$3D1.219740@sccrnsc01>, tmoran@acm.org wrote: >> Could this paragraph from the GNAT Reference Manual have any bearing on >> this problem? >> >> 9.31 GNAT.Float_Control (`g-flocon.ads') > I added a "with" and inserted as the first line after "begin" > GNAT.Float_Control.Reset; > It made no difference. I'm using Gnat 3.15p on Windows. Perhaps > newer versions work differently? BTW, I note that "-gnato -O2" > generates somewhat different results - still screwy in the same > ways, but different. I tried playing around with your example, but instantiated the generic complex type with both long and normal floats. It seemed to make a difference as the generic versions caused an exception on abs() (though Im() and Re() both worked returning infinities!). Mind you, this is with gcc-3.2, which I guess is somewhat different from the 3.15p release... (I tried all the various -gnatV switches, to no effect). Besides the T'Valid flag, how do you check specifically for or set infinity or NaN or denormal floating point numbers? -- echo ">gra.fcw@2ztr< eryyvZ .T pveR" | rot13 | reverse ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Gnat/Windows float point Q 2003-04-10 6:23 ` tmoran 2003-04-10 18:39 ` Randy Brukardt @ 2003-04-11 19:11 ` Simon Wright 1 sibling, 0 replies; 11+ messages in thread From: Simon Wright @ 2003-04-11 19:11 UTC (permalink / raw) tmoran@acm.org writes: > > I'd expect the result of such an operation to be either +infinity > > or -infinity. Those compare as you expect, and probably raise > > Constraint_Error when stored (if they didn't do that, the compiler would > > be violating the rule about math always returning the correct result or > > raising an exception). > > 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? > > with ada.numerics.complex_types, > ada.text_io; > procedure oflow is > use ada.numerics.complex_types; > x : complex := (4.7E+17, -1.6E+17); > y : float; > begin > for i in 1 .. 5 loop > y := abs(x); > ada.text_io.put_line("abs(x) = y =" & float'image(y) > & " y < 0.0 " & boolean'image(y < 0.0) > & " y >= 0.0 " & boolean'image(y >= 0.0)); > ada.text_io.put_line(float'image(re(x)) & float'image(im(x))); > ada.text_io.put_line(float'image(re(x)) & ":" & float'image(im(x))); > ada.text_io.new_line; > x := x**2; > end loop; > end oflow; > > 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 > > abs(x) = y =1.95300E+05 y < 0.0 FALSE y >= 0.0 FALSE > +Inf*******1.50400E+05 > +Inf*******:1.50401E+05 > > abs(x) = y =+Inf******* y < 0.0 FALSE y >= 0.0 FALSE > 3.36210E-49321.50401E+05 > 9.52681E+139:1.50402E+05 > > abs(x) = y =9.52681E+05 y < 0.0 FALSE y >= 0.0 FALSE > 0.E+051.50402E+05 > 3.64520E-4951:1.50403E+05 With GNAT 3.16a (compiled here for Mandrake 8.2), -gnato -O2, this gives 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 abs(x) = y =NaN******** y < 0.0 FALSE y >= 0.0 FALSE +Inf*******NaN******** +Inf*******:NaN******** abs(x) = y =NaN******** y < 0.0 FALSE y >= 0.0 FALSE NaN********NaN******** NaN********:NaN******** abs(x) = y =NaN******** y < 0.0 FALSE y >= 0.0 FALSE NaN********NaN******** NaN********:NaN******** (at least with NaN it's correct that the comparisons are false both ways). With gcc-3.3-20030201 the result is 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 abs(x) = y =0.E+05 y < 0.0 FALSE y >= 0.0 FALSE +Inf*******0.E+05 Execution terminated by unhandled exception Exception name: CONSTRAINT_ERROR Message: s-imgrea.adb:235 explicit raise Call stack traceback locations: 0x804a581 0x805813d 0x80587bc 0x8057d6f 0x804a29d 0x8049e47 (traceback: shows oflow.adb:14) ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2003-04-11 19:11 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox