* S'Is_nan or S'Is_inf? @ 2010-07-15 21:00 Warren 2010-07-15 21:30 ` Rod Chapman ` (3 more replies) 0 siblings, 4 replies; 16+ messages in thread From: Warren @ 2010-07-15 21:00 UTC (permalink / raw) Is there any is not-a-number or is-infinity test support in Ada05+ (for floats)? Is there any being planned? Just shooting from the hip, it would seem to be a standard thing that should be included these days. Obviously you'd also need Booleans to tell you if they are supported or not, on your given platform. Warren ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-15 21:00 S'Is_nan or S'Is_inf? Warren @ 2010-07-15 21:30 ` Rod Chapman 2010-07-15 22:03 ` Simon Wright 2010-07-15 21:42 ` J-P. Rosen ` (2 subsequent siblings) 3 siblings, 1 reply; 16+ messages in thread From: Rod Chapman @ 2010-07-15 21:30 UTC (permalink / raw) On Jul 15, 10:00 pm, Warren <ve3...@gmail.com> wrote: > Is there any is not-a-number or is-infinity test support in > Ada05+ (for floats)? Is there any being planned? What is S'Valid supposed to return for an S which is a floating-point NaN??? - Rod ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-15 21:30 ` Rod Chapman @ 2010-07-15 22:03 ` Simon Wright 0 siblings, 0 replies; 16+ messages in thread From: Simon Wright @ 2010-07-15 22:03 UTC (permalink / raw) Rod Chapman <roderick.chapman@googlemail.com> writes: > On Jul 15, 10:00 pm, Warren <ve3...@gmail.com> wrote: >> Is there any is not-a-number or is-infinity test support in >> Ada05+ (for floats)? Is there any being planned? > > What is S'Valid supposed to return for an S which is > a floating-point NaN??? I thought it was supposed to produce False, but all the AARM seems to say (13.9.2) is that the value needs to be normal and have a valid representation for 'Valid to return True. It also lists the circumstances under which invalid data can be created: they don't look to me as though they include NaN : constant Float := 0.0 / 0.0; GNAT certainly reports 'Valid as False for +/-Inf & NaN. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-15 21:00 S'Is_nan or S'Is_inf? Warren 2010-07-15 21:30 ` Rod Chapman @ 2010-07-15 21:42 ` J-P. Rosen 2010-07-15 22:07 ` Simon Wright 2010-07-19 23:15 ` Randy Brukardt 3 siblings, 0 replies; 16+ messages in thread From: J-P. Rosen @ 2010-07-15 21:42 UTC (permalink / raw) Warren a �crit : > Is there any is not-a-number or is-infinity test support in > Ada05+ (for floats)? Is there any being planned? > If X /= X, then X is a NaN (see http://en.wikipedia.org/wiki/NaN) Not sure if there is such a simple test for infinities... -- --------------------------------------------------------- J-P. Rosen (rosen@adalog.fr) Visit Adalog's web site at http://www.adalog.fr ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-15 21:00 S'Is_nan or S'Is_inf? Warren 2010-07-15 21:30 ` Rod Chapman 2010-07-15 21:42 ` J-P. Rosen @ 2010-07-15 22:07 ` Simon Wright 2010-07-16 8:42 ` Dmitry A. Kazakov 2010-07-19 23:15 ` Randy Brukardt 3 siblings, 1 reply; 16+ messages in thread From: Simon Wright @ 2010-07-15 22:07 UTC (permalink / raw) Warren <ve3wwg@gmail.com> writes: > Is there any is not-a-number or is-infinity test support in Ada05+ > (for floats)? Is there any being planned? With GNAT, using a subtype subtype Checked_Float is Float range Float'Range; will give you a Constraint_Error for NaN or +/-Inf. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-15 22:07 ` Simon Wright @ 2010-07-16 8:42 ` Dmitry A. Kazakov 2010-07-16 17:06 ` Warren 2010-07-16 22:35 ` Warren 0 siblings, 2 replies; 16+ messages in thread From: Dmitry A. Kazakov @ 2010-07-16 8:42 UTC (permalink / raw) On Thu, 15 Jul 2010 23:07:51 +0100, Simon Wright wrote: > Warren <ve3wwg@gmail.com> writes: > >> Is there any is not-a-number or is-infinity test support in Ada05+ >> (for floats)? Is there any being planned? with Ada.Text_IO; use Ada.Text_IO; procedure IEEE is -- Only if Float is IEEE! Zero : Float := 0.0; Inf : Float := 1.0 / Zero; NaN : Float := 0.0 / Zero; begin Put_Line ("Valid " & Boolean'Image (Inf'Valid)); Put_Line ("In range " & Boolean'Image (Inf <= Float'Last)); Put_Line ("Self NaN " & Boolean'Image (NaN = NaN)); end IEEE; On an IEEE machine it could print 3x FALSE. > With GNAT, using a subtype > > subtype Checked_Float is Float range Float'Range; > > will give you a Constraint_Error for NaN or +/-Inf. Yes, one of the reasons not to use built-in types is that the floating point ones most likely are IEEE with all nasty consequences. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-16 8:42 ` Dmitry A. Kazakov @ 2010-07-16 17:06 ` Warren 2010-07-16 19:39 ` Dmitry A. Kazakov 2010-07-16 22:35 ` Warren 1 sibling, 1 reply; 16+ messages in thread From: Warren @ 2010-07-16 17:06 UTC (permalink / raw) Dmitry A. Kazakov expounded in news:1tbp3geoa5yna$.171cmlfdrbm98$.dlg@ 40tude.net: > with Ada.Text_IO; use Ada.Text_IO; > procedure IEEE is -- Only if Float is IEEE! > Zero : Float := 0.0; > Inf : Float := 1.0 / Zero; > NaN : Float := 0.0 / Zero; > begin > Put_Line ("Valid " & Boolean'Image (Inf'Valid)); > Put_Line ("In range " & Boolean'Image (Inf <= Float'Last)); > Put_Line ("Self NaN " & Boolean'Image (NaN = NaN)); > end IEEE; > > On an IEEE machine it could print 3x FALSE. On a non IEEE machine, is there going to be an exception raised when dividing by zero? Warren ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-16 17:06 ` Warren @ 2010-07-16 19:39 ` Dmitry A. Kazakov 0 siblings, 0 replies; 16+ messages in thread From: Dmitry A. Kazakov @ 2010-07-16 19:39 UTC (permalink / raw) On Fri, 16 Jul 2010 17:06:38 +0000 (UTC), Warren wrote: > Dmitry A. Kazakov expounded in news:1tbp3geoa5yna$.171cmlfdrbm98$.dlg@ > 40tude.net: > >> with Ada.Text_IO; use Ada.Text_IO; >> procedure IEEE is -- Only if Float is IEEE! >> Zero : Float := 0.0; >> Inf : Float := 1.0 / Zero; >> NaN : Float := 0.0 / Zero; >> begin >> Put_Line ("Valid " & Boolean'Image (Inf'Valid)); >> Put_Line ("In range " & Boolean'Image (Inf <= Float'Last)); >> Put_Line ("Self NaN " & Boolean'Image (NaN = NaN)); >> end IEEE; >> >> On an IEEE machine it could print 3x FALSE. > > On a non IEEE machine, is there going to be an exception > raised when dividing by zero? I would say yes. But theoretically if a non-IEEE machine has special representations of x/0, as IEEE does, then the compiler vendor is permitted not to raise Constraint_Error. Language lawyers? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-16 8:42 ` Dmitry A. Kazakov 2010-07-16 17:06 ` Warren @ 2010-07-16 22:35 ` Warren 2010-07-17 6:24 ` Simon Wright 2010-07-17 7:40 ` Dmitry A. Kazakov 1 sibling, 2 replies; 16+ messages in thread From: Warren @ 2010-07-16 22:35 UTC (permalink / raw) Dmitry A. Kazakov expounded in news:1tbp3geoa5yna$.171cmlfdrbm98$.dlg@40tude.net: > with Ada.Text_IO; use Ada.Text_IO; > procedure IEEE is -- Only if Float is IEEE! > Zero : Float := 0.0; > Inf : Float := 1.0 / Zero; > NaN : Float := 0.0 / Zero; > begin > Put_Line ("Valid " & Boolean'Image (Inf'Valid)); > Put_Line ("In range " & Boolean'Image (Inf <= Float'Last)); > Put_Line ("Self NaN " & Boolean'Image (NaN = NaN)); > end IEEE; > > On an IEEE machine it could print 3x FALSE. To detect NaN then, this seems to work: function Is_Nan(F : Float) return Boolean is begin if not F'Valid then return not ( Is_Infinity(F) or Is_Neg_Infinity(F) ); else return False; end if; end Is_Nan; where Is_Infinity(F) etc. is implemented as suggested. Essentially if not valid, but not one of the infinities(+ or -), then it must be NaN. This works with Gnat on Cygwin. I'll need to test it on other platforms, but hopefully most if not all IEEE platforms will support this. Warren ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-16 22:35 ` Warren @ 2010-07-17 6:24 ` Simon Wright 2010-07-19 17:04 ` Warren 2010-07-17 7:40 ` Dmitry A. Kazakov 1 sibling, 1 reply; 16+ messages in thread From: Simon Wright @ 2010-07-17 6:24 UTC (permalink / raw) Warren <ve3wwg@gmail.com> writes: > To detect NaN then, this seems to work: See above, where Jean-Pierre said > If X /= X, then X is a NaN (see http://en.wikipedia.org/wiki/NaN) ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-17 6:24 ` Simon Wright @ 2010-07-19 17:04 ` Warren 0 siblings, 0 replies; 16+ messages in thread From: Warren @ 2010-07-19 17:04 UTC (permalink / raw) Simon Wright expounded in news:m2tynytykr.fsf@pushface.org: > Warren <ve3wwg@gmail.com> writes: > >> To detect NaN then, this seems to work: > > See above, where Jean-Pierre said > >> If X /= X, then X is a NaN (see http://en.wikipedia.org/wiki/NaN) Thanks. I later had a head slapping moment on the weekend where I had figured that out. ;-) Warren ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-16 22:35 ` Warren 2010-07-17 6:24 ` Simon Wright @ 2010-07-17 7:40 ` Dmitry A. Kazakov 2010-07-19 17:18 ` Warren 1 sibling, 1 reply; 16+ messages in thread From: Dmitry A. Kazakov @ 2010-07-17 7:40 UTC (permalink / raw) On Fri, 16 Jul 2010 22:35:14 +0000 (UTC), Warren wrote: > I'll need > to test it on other platforms, but hopefully most if not all > IEEE platforms will support this. IEEE representations have more than +Inf, -Inf and NaN. There are other objects: +0, -0, denormalized numbers (see attribute 'Denorm). Some have dubious semantics: with Ada.Text_IO; use Ada.Text_IO; procedure IEEE_Zeros is Zero : Float := 0.0; N0 : Float := 0.0 / (-1.0 / Zero); begin Put_Line ("-0 =" & Float'Image (N0) & " 0 = " & Float'Image (Zero)); Put_Line ("-0 = 0 " & Boolean'Image (N0 = Zero)); Put_Line ("-0 < 0 " & Boolean'Image (N0 < Zero)); end IEEE_Zeros; Negative zero is zero but not equal to, etc. What are you trying to achieve? Because in automation we have the rule never ever let IEEE cripples slip through. Don't read them, don't write them, don't compute them. The solution Simon suggested is basically everything Ada programmer should know about IEEE 754! (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-17 7:40 ` Dmitry A. Kazakov @ 2010-07-19 17:18 ` Warren 0 siblings, 0 replies; 16+ messages in thread From: Warren @ 2010-07-19 17:18 UTC (permalink / raw) Dmitry A. Kazakov expounded in news:5xj0ja9xywto$.3ncqua6onpoa.dlg@40tude.net: > On Fri, 16 Jul 2010 22:35:14 +0000 (UTC), Warren wrote: > IEEE representations have more than +Inf, -Inf and NaN. There are > other objects: +0, -0, denormalized numbers (see attribute 'Denorm). > Some have dubious semantics: Ya, I know about those. As indicated in my other reply, I did eventually figure out that if F /= F, then it is NaN (for some reason, I didn't see this at first). > What are you trying to achieve? Because in automation we have the rule > never ever let IEEE cripples slip through. Don't read them, don't > write them, don't compute them. In my Basic interpreter, I'll raise an error if you try to use these IEEE values in an argument to a function or try to compute something with an operator (here NOT 'Valid is sufficient). However, if the expression result is one of these, I do allow it to be assigned to a [basic] variable. So then the user needs a (basic) function to test if the variable V is +/- infinity or NaN. So in basic, ISNAN(X) returns 1 if NaN, else zero, for example. In the C version of the interpreter, I relied upon C functions for these tests. Ada clearly does not need these C functions, which is bliss for the Ada rewrite. Thanks for everyone's help. Warren ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-15 21:00 S'Is_nan or S'Is_inf? Warren ` (2 preceding siblings ...) 2010-07-15 22:07 ` Simon Wright @ 2010-07-19 23:15 ` Randy Brukardt 2010-07-20 14:12 ` Warren 3 siblings, 1 reply; 16+ messages in thread From: Randy Brukardt @ 2010-07-19 23:15 UTC (permalink / raw) "Warren" <ve3wwg@gmail.com> wrote in message news:Xns9DB6AD1651560WarrensBlatherings@81.169.183.62... > Is there any is not-a-number or is-infinity test support in > Ada05+ (for floats)? Is there any being planned? We considered it for Ada 2005 (see AI95-0315-1). It was abandoned because of the large impact on implementations and the weak demand (hardly any user requests). John Barnes mentions this in the Ada 2005 Rational: http://www.adaic.com/standards/05rat/html/Rat-9-3-3.html It wasn't resurrected for Ada 2012, so there won't be any change here. BTW, GNAT seems to pass through a lot of IEEE stuff, thus you can write examples using that. Other Ada compilers (at least as of 2003-4 timeframe) vary widely in what is exposed (Janus/Ada only supports IEEE denormal numbers; everything else raises Constraint_Error before it is stored). Randy. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-19 23:15 ` Randy Brukardt @ 2010-07-20 14:12 ` Warren 2010-07-20 16:20 ` Dmitry A. Kazakov 0 siblings, 1 reply; 16+ messages in thread From: Warren @ 2010-07-20 14:12 UTC (permalink / raw) Randy Brukardt expounded in news:i22m9q$cd4$1@munin.nbi.dk: > "Warren" <ve3wwg@gmail.com> wrote in message > news:Xns9DB6AD1651560WarrensBlatherings@81.169.183.62... >> Is there any is not-a-number or is-infinity test support in >> Ada05+ (for floats)? Is there any being planned? > > We considered it for Ada 2005 (see AI95-0315-1). It was abandoned > because of the large impact on implementations and the weak demand > (hardly any user requests). > > John Barnes mentions this in the Ada 2005 Rational: > http://www.adaic.com/standards/05rat/html/Rat-9-3-3.html > > It wasn't resurrected for Ada 2012, so there won't be any change here. > > BTW, GNAT seems to pass through a lot of IEEE stuff, thus you can > write examples using that. Other Ada compilers (at least as of 2003-4 > timeframe) vary widely in what is exposed (Janus/Ada only supports > IEEE denormal numbers; everything else raises Constraint_Error before > it is stored). > > Randy. Very interesting. My project is fairly dependant on gnat (at the moment at least), so things should work ok. I'm not personally a fan of these special IEEE values, but they crop up in 3rd party libraries like the GSL etc. or in the reading of binary values from a file. Warren ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: S'Is_nan or S'Is_inf? 2010-07-20 14:12 ` Warren @ 2010-07-20 16:20 ` Dmitry A. Kazakov 0 siblings, 0 replies; 16+ messages in thread From: Dmitry A. Kazakov @ 2010-07-20 16:20 UTC (permalink / raw) On Tue, 20 Jul 2010 14:12:01 +0000 (UTC), Warren wrote: > I'm not personally > a fan of these special IEEE values, but they crop up in 3rd party > libraries like the GSL etc. or in the reading of binary values from > a file. This was a motivation behind http://www.dmitry-kazakov.de/ada/components.htm#IEEE_754 Inputs and outputs in IEEE 754 representations can be converted to and from Ada floating-point types in a portable way. Within the program you forget about IEEE. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2010-07-20 16:20 UTC | newest] Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-07-15 21:00 S'Is_nan or S'Is_inf? Warren 2010-07-15 21:30 ` Rod Chapman 2010-07-15 22:03 ` Simon Wright 2010-07-15 21:42 ` J-P. Rosen 2010-07-15 22:07 ` Simon Wright 2010-07-16 8:42 ` Dmitry A. Kazakov 2010-07-16 17:06 ` Warren 2010-07-16 19:39 ` Dmitry A. Kazakov 2010-07-16 22:35 ` Warren 2010-07-17 6:24 ` Simon Wright 2010-07-19 17:04 ` Warren 2010-07-17 7:40 ` Dmitry A. Kazakov 2010-07-19 17:18 ` Warren 2010-07-19 23:15 ` Randy Brukardt 2010-07-20 14:12 ` Warren 2010-07-20 16:20 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox