comp.lang.ada
 help / color / mirror / Atom feed
* Valid on QNaN generates exception, compiler bug?
@ 2002-01-31  4:04 Steve Doiel
  0 siblings, 0 replies; 7+ messages in thread
From: Steve Doiel @ 2002-01-31  4:04 UTC (permalink / raw)


  In ObjectAda 7.2 (WinNT x86) I have found that if I assign a value of
16#FFC0_0000# (QNaN) to a 32 bit floating point value using unchecked
conversion, then I try to check the value using 'VALID, I get a
Constraint_Error, numeric overflow exception.

  Is this a compiler bug?

  To paraphrase

  FUNCTION Conv IS
    NEW Ada.Unchecked_Conversion( Unsigned_32, float );

 ...
  float_value : Float;
  u32_value : Unsigned_Float;
...
  u32_value := 16#FFC0_0000#;
  float_value := Conv( u32_value );
  IF float_value'VALID THEN           -- The exception occurs on this line
    Text_Io.Put_Line( "Value is valid" );
  ELSE
    Text_Io.Put_Line( "Value is not valid" );
  END IF;

BTW: Gnat 3.13p with -gnato does not raise an exception.

Thanks,
SteveD








^ permalink raw reply	[flat|nested] 7+ messages in thread

* Valid on QNaN generates exception, compiler bug?
@ 2002-01-31  4:04 Steve Doiel
  2002-02-01 14:12 ` Stephen Leake
  0 siblings, 1 reply; 7+ messages in thread
From: Steve Doiel @ 2002-01-31  4:04 UTC (permalink / raw)


  In ObjectAda 7.2 (WinNT x86) I have found that if I assign a value of
16#FFC0_0000# (QNaN) to a 32 bit floating point value using unchecked
conversion, then I try to check the value using 'VALID, I get a
Constraint_Error, numeric overflow exception.

  Is this a compiler bug?

  To paraphrase

  FUNCTION Conv IS
    NEW Ada.Unchecked_Conversion( Unsigned_32, float );

 ...
  float_value : Float;
  u32_value : Unsigned_Float;
...
  u32_value := 16#FFC0_0000#;
  float_value := Conv( u32_value );
  IF float_value'VALID THEN           -- The exception occurs on this line
    Text_Io.Put_Line( "Value is valid" );
  ELSE
    Text_Io.Put_Line( "Value is not valid" );
  END IF;

BTW: Gnat 3.13p with -gnato does not raise an exception.

Thanks,
SteveD






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Valid on QNaN generates exception, compiler bug?
  2002-01-31  4:04 Steve Doiel
@ 2002-02-01 14:12 ` Stephen Leake
  2002-02-01 14:51   ` Steve Doiel
  2002-02-01 16:16   ` Jeffrey Carter
  0 siblings, 2 replies; 7+ messages in thread
From: Stephen Leake @ 2002-02-01 14:12 UTC (permalink / raw)


"Steve Doiel" <nospam_steved94@attbi.com> writes:

>   In ObjectAda 7.2 (WinNT x86) I have found that if I assign a value of
> 16#FFC0_0000# (QNaN) to a 32 bit floating point value using unchecked
> conversion, then I try to check the value using 'VALID, I get a
> Constraint_Error, numeric overflow exception.
> 
>   Is this a compiler bug?

No. "NaN" stands for "Not a Number". float_value'Valid checks to see
if 'float_value' holds a valid floating point number. It does not, so
Constraint_Error is raised.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Valid on QNaN generates exception, compiler bug?
  2002-02-01 14:12 ` Stephen Leake
@ 2002-02-01 14:51   ` Steve Doiel
  2002-02-01 21:11     ` Robert Dewar
  2002-02-01 16:16   ` Jeffrey Carter
  1 sibling, 1 reply; 7+ messages in thread
From: Steve Doiel @ 2002-02-01 14:51 UTC (permalink / raw)



"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:u1yg5z3xo.fsf@gsfc.nasa.gov...
> "Steve Doiel" <nospam_steved94@attbi.com> writes:
>
> >   In ObjectAda 7.2 (WinNT x86) I have found that if I assign a value of
> > 16#FFC0_0000# (QNaN) to a 32 bit floating point value using unchecked
> > conversion, then I try to check the value using 'VALID, I get a
> > Constraint_Error, numeric overflow exception.
> >
> >   Is this a compiler bug?
>
> No. "NaN" stands for "Not a Number". float_value'Valid checks to see
> if 'float_value' holds a valid floating point number. It does not, so
> Constraint_Error is raised.
>
Interesting.  I expected float_value'Valid to return false, not raise an
exception.

SteveD

> --
> -- Stephe





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Valid on QNaN generates exception, compiler bug?
  2002-02-01 14:12 ` Stephen Leake
  2002-02-01 14:51   ` Steve Doiel
@ 2002-02-01 16:16   ` Jeffrey Carter
  1 sibling, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2002-02-01 16:16 UTC (permalink / raw)


Stephen Leake wrote:
> 
> "Steve Doiel" <nospam_steved94@attbi.com> writes:
> 
> >   In ObjectAda 7.2 (WinNT x86) I have found that if I assign a value of
> > 16#FFC0_0000# (QNaN) to a 32 bit floating point value using unchecked
> > conversion, then I try to check the value using 'VALID, I get a
> > Constraint_Error, numeric overflow exception.
> >
> >   Is this a compiler bug?
> 
> No. "NaN" stands for "Not a Number". float_value'Valid checks to see
> if 'float_value' holds a valid floating point number. It does not, so
> Constraint_Error is raised.

ARM 13.9.2 says "X'Valid is not considered to be a read of X; hence, it
is not an error to check the validity of invalid data."

The whole point of 'Valid is that it doesn't raise an exception
regardless of the bit pattern stored in the object; otherwise it doesn't
add anything to the language.

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Valid on QNaN generates exception, compiler bug?
  2002-02-01 14:51   ` Steve Doiel
@ 2002-02-01 21:11     ` Robert Dewar
  2002-02-01 22:13       ` Steve Doiel
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Dewar @ 2002-02-01 21:11 UTC (permalink / raw)


"Steve Doiel" <nospam_steved94@attbi.com> wrote in message news:<cYx68.6829$IZ4.21489@rwcrnsc54>...
> Interesting.  I expected float_value'Valid to return 
> false, not raise an
> exception.

And of course your expectation was entirely correct. This
is a clear bug (some earlier version of GNAT had this bug,
and for a while we actually installed an implicit exception
handler to catch the bogus exception and return False, but
now GNAT does explicit code to test for and catch NaN's
and infinities. The problem is that a signalling NaN may
raise an exception just by loading it.

But the prefix of 'Valid is very special. As we read in
13.9.2, the ONLY way you can use an invalid value like
a NaN is in this context:

12   (20) X'Valid is not considered to be a read of X; 
     hence, it is not an
     error to check the validity of invalid data.

There is no basis whatsoever for raising a Constraint_Error
here, the program is correct, and the 'Valid attribute
should yield False. Report the bug to the relevant vendor.

You definitely do NOT need to guard all 'Valid attributes
with an exception handler (which is what the previous 
incorrect response would have implied).



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Valid on QNaN generates exception, compiler bug?
  2002-02-01 21:11     ` Robert Dewar
@ 2002-02-01 22:13       ` Steve Doiel
  0 siblings, 0 replies; 7+ messages in thread
From: Steve Doiel @ 2002-02-01 22:13 UTC (permalink / raw)


Thank you Robert.

I was hoping for a response from either you or Tuck (one I can trust).

SteveD

"Robert Dewar" <dewar@gnat.com> wrote in message
news:5ee5b646.0202011311.393ce8d9@posting.google.com...
> "Steve Doiel" <nospam_steved94@attbi.com> wrote in message
news:<cYx68.6829$IZ4.21489@rwcrnsc54>...
> > Interesting.  I expected float_value'Valid to return
> > false, not raise an
> > exception.
>
> And of course your expectation was entirely correct. This
> is a clear bug (some earlier version of GNAT had this bug,
> and for a while we actually installed an implicit exception
> handler to catch the bogus exception and return False, but
> now GNAT does explicit code to test for and catch NaN's
> and infinities. The problem is that a signalling NaN may
> raise an exception just by loading it.
>
> But the prefix of 'Valid is very special. As we read in
> 13.9.2, the ONLY way you can use an invalid value like
> a NaN is in this context:
>
> 12   (20) X'Valid is not considered to be a read of X;
>      hence, it is not an
>      error to check the validity of invalid data.
>
> There is no basis whatsoever for raising a Constraint_Error
> here, the program is correct, and the 'Valid attribute
> should yield False. Report the bug to the relevant vendor.
>
> You definitely do NOT need to guard all 'Valid attributes
> with an exception handler (which is what the previous
> incorrect response would have implied).





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-02-01 22:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-31  4:04 Valid on QNaN generates exception, compiler bug? Steve Doiel
  -- strict thread matches above, loose matches on Subject: below --
2002-01-31  4:04 Steve Doiel
2002-02-01 14:12 ` Stephen Leake
2002-02-01 14:51   ` Steve Doiel
2002-02-01 21:11     ` Robert Dewar
2002-02-01 22:13       ` Steve Doiel
2002-02-01 16:16   ` Jeffrey Carter

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