On Apr 30, 2:53=A0pm, Adam Beneschan <a...@[EMAIL PROTECTED]
> wrote:
> On Apr 30, 1:36 pm, Jerry <lancebo...@[EMAIL PROTECTED]
> wrote:
>
> > Check this out:
>
> > function Is_NaN(x : Long_Float) return Boolean is
> > begin
> > =A0 =A0 return x /=3D x;
> > end Is_NaN;
>
> Maybe that will work, but I wouldn't count on it. =A0First of all, you
> don't know that the compiler will actually do anything. =A0It may get
> clever and decide that this is trivially False, and thus generate code
> that doesn't even look at x. =A0Second, if it generates a "floating-
> point comparison" instruction, you may not get the behavior you think
> you're getting. =A0My Pentium manual, for instance, says of the FCOM*
> (Compare Real) instructions: "If either operand is a NaN or is in an
> undefined format, ... the invalid-operation exception is raised, and
> the condition bits are set to 'unordered'". =A0Which means that (on that
> processor) the comparison attempt will probably fault, and if it
> doesn't because the fault is masked, the condition-code bits will be
> set to an "unordered" relation that your compiler may not be
> expecting, which means that it may not be translated to "inequality"
> the way you think it will.
>
> > A couple of minutes on Wikipedia saves the day.
Fromhttp://en.wikipedia.=
org/wiki/NaN#NaN_encodings:
>
> > "A NaN does not compare equal to any floating-point number or NaN,
> > even if the latter has an identical representation. One can therefore
> > test whether a variable has a NaN value by comparing it to itself."
>
> But if you read further, you'll find that signaling NaNs "should raise
> an invalid exception". =A0(Why the Pentium FCOM instructions appear to
> raise exceptions for quiet NaN's as well as signed NaN's, I don't
> know.)
>
> Anyway, Wikipedia describes the IEC 559/IEEE 754 standard, but as
> we've already discussed, (1) Ada doesn't fully sup****t this standard
> and (2) NaN's aren't valid values in Ada, so you can't reliably use
> the IEC/IEEE standard to predict what will happen if you do this in
> Ada. =A0You're welcome to try it, of course, but don't be surprised or
> disappointed if it doesn't work.
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0--
Adam=
Adam,
Your points are well made. For "normal" use my little hack should be
considered suspect. For my trivial use of getting this pesky binding
example code out of my hair, I think it should be OK.
Just for completeness, I suppose, I'll add (as I alluded to in my
original post), that this:
dum1 :=3D 0.0;
dum2 :=3D 0.0;
Put_Line(Long_Float'image(dum1 / dum2));
outputs this:
NaN*****************
Certainly not 754 compliance, but perhaps a bit of "awareness."
Jerry


|