comp.lang.ada
 help / color / mirror / Atom feed
* Re: Need exception despite Machine_Overflows is false
  1998-12-17  0:00 Need exception despite Machine_Overflows is false Pascal MALAISE
@ 1998-12-17  0:00 ` Matthew Heaney
  1998-12-18  0:00   ` dewarr
  1998-12-18  0:00 ` Stephen Leake
  1 sibling, 1 reply; 9+ messages in thread
From: Matthew Heaney @ 1998-12-17  0:00 UTC (permalink / raw)


Try the -gnato option.

Pascal MALAISE <malaise@magic.fr> writes:

> Using gnat 3.10p on Linux,
> I make several computations on long_float (s), then use a
> text_io.float_io
> to display the results => NaN*****
> 
> There is an overflow, Gnat uses the libc, long_float'Machine_Overflows
> is false...
> fair enough.
> 
> What can I do to get a constraint_error raised when there is an
> overflow?
> Don't tell me that I have to check, via an interface to C finite(), the
> result of
> each operation!
> 
> -- 
> Pascal MALAISE
> (priv) mailto:malaise@magic.fr
> (prof) mailto:malaise@fr.airsysatm.thomson-csf.com




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

* Need exception despite Machine_Overflows is false
@ 1998-12-17  0:00 Pascal MALAISE
  1998-12-17  0:00 ` Matthew Heaney
  1998-12-18  0:00 ` Stephen Leake
  0 siblings, 2 replies; 9+ messages in thread
From: Pascal MALAISE @ 1998-12-17  0:00 UTC (permalink / raw)


Using gnat 3.10p on Linux,
I make several computations on long_float (s), then use a
text_io.float_io
to display the results => NaN*****

There is an overflow, Gnat uses the libc, long_float'Machine_Overflows
is false...
fair enough.

What can I do to get a constraint_error raised when there is an
overflow?
Don't tell me that I have to check, via an interface to C finite(), the
result of
each operation!

-- 
Pascal MALAISE
(priv) mailto:malaise@magic.fr
(prof) mailto:malaise@fr.airsysatm.thomson-csf.com




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

* Re: Need exception despite Machine_Overflows is false
  1998-12-17  0:00 ` Matthew Heaney
@ 1998-12-18  0:00   ` dewarr
  1998-12-18  0:00     ` Matthew Heaney
  0 siblings, 1 reply; 9+ messages in thread
From: dewarr @ 1998-12-18  0:00 UTC (permalink / raw)


In article <m3pv9ipg1e.fsf@mheaney.ni.net>,
  Matthew Heaney <matthew_heaney@acm.org> wrote:
> Try the -gnato option.


As I am sure others will point out, this advice is
entirely wrong!

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Need exception despite Machine_Overflows is false
  1998-12-18  0:00   ` dewarr
@ 1998-12-18  0:00     ` Matthew Heaney
  1998-12-19  0:00       ` dewar
  0 siblings, 1 reply; 9+ messages in thread
From: Matthew Heaney @ 1998-12-18  0:00 UTC (permalink / raw)


dewarr@my-dejanews.com writes:

> In article <m3pv9ipg1e.fsf@mheaney.ni.net>,
>   Matthew Heaney <matthew_heaney@acm.org> wrote:
> > Try the -gnato option.
> 
> 
> As I am sure others will point out, this advice is
> entirely wrong!

`-gnato'
     Enable other checks, not normally enabled by default, including
     numeric overflow checking, and access before elaboration checks.

Ah, silly me, I assumed that "numeric overflow checking" meant check for
numeric overflow!





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

* Re: Need exception despite Machine_Overflows is false
  1998-12-17  0:00 Need exception despite Machine_Overflows is false Pascal MALAISE
  1998-12-17  0:00 ` Matthew Heaney
@ 1998-12-18  0:00 ` Stephen Leake
  1998-12-18  0:00   ` Pascal MALAISE
  1998-12-18  0:00   ` Matthew Heaney
  1 sibling, 2 replies; 9+ messages in thread
From: Stephen Leake @ 1998-12-18  0:00 UTC (permalink / raw)


Pascal MALAISE <malaise@magic.fr> writes:

> Using gnat 3.10p on Linux,
> I make several computations on long_float (s), then use a
> text_io.float_io
> to display the results => NaN*****
> 
> There is an overflow, Gnat uses the libc, long_float'Machine_Overflows
> is false...
> fair enough.
> 
> What can I do to get a constraint_error raised when there is an
> overflow?
> Don't tell me that I have to check, via an interface to C finite(), the
> result of
> each operation!

You could try adding a range constraint to your basic floating point type:

type Real is digits 9 range -1.0e307 .. +1.0e307;

As long as your limits are tighter than the machine limits, the
compiler will insert explicit checks. Of course, this will slow things
down, but I assume you could remove the limits after you find the bug.

This is one reason not to use the predefined Float type!

-- Stephe
> 
> -- 
> Pascal MALAISE
> (priv) mailto:malaise@magic.fr
> (prof) mailto:malaise@fr.airsysatm.thomson-csf.com




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

* Re: Need exception despite Machine_Overflows is false
  1998-12-18  0:00 ` Stephen Leake
  1998-12-18  0:00   ` Pascal MALAISE
@ 1998-12-18  0:00   ` Matthew Heaney
  1 sibling, 0 replies; 9+ messages in thread
From: Matthew Heaney @ 1998-12-18  0:00 UTC (permalink / raw)


Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:

> Pascal MALAISE <malaise@magic.fr> writes:
> 
> > Using gnat 3.10p on Linux,
> > I make several computations on long_float (s), then use a
> > text_io.float_io
> > to display the results => NaN*****
> > 
> > There is an overflow, Gnat uses the libc, long_float'Machine_Overflows
> > is false...
> > fair enough.
> > 
> > What can I do to get a constraint_error raised when there is an
> > overflow?
> > Don't tell me that I have to check, via an interface to C finite(), the
> > result of
> > each operation!
> 
> You could try adding a range constraint to your basic floating point type:
> 
> type Real is digits 9 range -1.0e307 .. +1.0e307;
> 
> As long as your limits are tighter than the machine limits, the
> compiler will insert explicit checks. Of course, this will slow things
> down, but I assume you could remove the limits after you find the bug.
> 
> This is one reason not to use the predefined Float type!

I think this statement is misleading.

The problem here has nothing to do with the "predefined Float type."
The "problem" is that an unconstrained type was used, when a constrained
type was desired.  You would have the same problems if you did:

  type My_Float is digits 6;

This declares an _unconstrained_ floating point subtype, meaning that no
constraint checks are performed.

Perhaps a better statement would be:

  This is one reason not to use unconstrained floating point subtypes!









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

* Re: Need exception despite Machine_Overflows is false
  1998-12-18  0:00 ` Stephen Leake
@ 1998-12-18  0:00   ` Pascal MALAISE
  1998-12-19  0:00     ` dewarr
  1998-12-18  0:00   ` Matthew Heaney
  1 sibling, 1 reply; 9+ messages in thread
From: Pascal MALAISE @ 1998-12-18  0:00 UTC (permalink / raw)


Stephen Leake wrote:

> You could try adding a range constraint to your basic floating point type:
> 
> type Real is digits 9 range -1.0e307 .. +1.0e307;
Fortunately I already had good "float" programming policy, I used:
subtype REAL is LONG_FLOAT;
Now, with: type REAL is digits 17 range -1.5E308 .. 1.5E308;
I just need to add some use clauses for the stuff to compile.

> As long as your limits are tighter than the machine limits, the
> compiler will insert explicit checks.
The detection is done now!

> Of course, this will slow things down, 
it is not significant

> but I assume you could remove the limits after you find the bug.
Oh, I was not looking for a bug.
The program makes pure mattrix multiplications and all I need is raising
then
handling the exception.
 
> This is one reason not to use the predefined Float type!
I knew some other reasons but not this one.

Thank's very much.

-- 
Pascal MALAISE
(priv) mailto:malaise@magic.fr
(prof) mailto:malaise@fr.airsysatm.thomson-csf.com




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

* Re: Need exception despite Machine_Overflows is false
  1998-12-18  0:00     ` Matthew Heaney
@ 1998-12-19  0:00       ` dewar
  0 siblings, 0 replies; 9+ messages in thread
From: dewar @ 1998-12-19  0:00 UTC (permalink / raw)


In article <m3hfutol0d.fsf@mheaney.ni.net>,
  Matthew Heaney <matthew_heaney@acm.org> wrote:
> `-gnato'
>      Enable other checks, not normally enabled by
> default, including
>      numeric overflow checking, and access before
> elaboration checks.
>
> Ah, silly me, I assumed that "numeric overflow checking"
> meant check for
> numeric overflow!


Well perhaps silly you for reading only the summary of the
switch and not the full documentation :-) The documentation
of the -gnato switch in the GNAT users guide says:

  -gnato

  Enables overflow checking for integer operations.
  This causes GNAT to generate slower and larger executable
  programs by adding code to check for both overflow and
  division by zero (resulting in raising Constraint_Error
  as required by Ada semantics).

  Note that the -gnato switch does not affect the code
  generated for any floating-point operations; it applies
  only to integer operations. For floating-point, GNAT has
  the Machine_Overflows attribute set to False and the
  normal mode of operation is to generate IEEE NaN and
  infinite values on overflow or invalid operations
  (such as dividing 0.0 by 0.0).

Clear enough I think! Note that the summary was correct, in
that if you have Machine_Overflows set to False, then an
out of range floating-point result is *not* an overflow in
the sense of the predefined overflow check in the language.
But in any case, when looking up the definition of
switches, always consult the full documentation, and not
just the quick summary!

This is a good opportunity to reiterate and once
again urge people to read the GNAT documentation if you are
using this compiler (and indeed the advice applies to any
other compiler I would assume!) There are lots of
interesting facilities available, and I am always surprised
(and a bit disappointed) to run into both students and
hobbyists using the public version of GNAT, and customers
using GNAT Professional with support who have not read the
manual and are unaware of many features that they might
find useful if they knew about them!

Robert Dewar
Ada Core Technologies

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Need exception despite Machine_Overflows is false
  1998-12-18  0:00   ` Pascal MALAISE
@ 1998-12-19  0:00     ` dewarr
  0 siblings, 0 replies; 9+ messages in thread
From: dewarr @ 1998-12-19  0:00 UTC (permalink / raw)


In article <367AA93A.3F8F1506@magic.fr>,
  Pascal MALAISE <malaise@magic.fr> wrote:
>
> > As long as your limits are tighter than the machine
> > limits, the
> > compiler will insert explicit checks.
> > >The detection is done now!
>
> > Of course, this will slow things down,
> > it is not significant

The slow down will vary from machine to machine, but it is
a very big effect with properly programmed code, probably
a factor of 3-4 slowdown at least.

If you do not see such a slowdown, it is likely that you
have programmed poorly with respect to cache. For example
a naive matrix multiplication of matrices larger than the
cache is of course completely disastrous from an efficiency
point of view, and there are well known algorithms for
doing this properly. The moral as usual with fpt is that
unless you *really* know what you are doing, you are better
off using existing library routines for such purposes.


> Oh, I was not looking for a bug.
> The program makes pure mattrix multiplications and all I
> need is raising
> then
> handling the exception.

You should not need to rely on exceptions for this purpose.
The IEEE standard does not require that exceptions be
implemented (they are optional), and properly written
numerical algorithms should not need to rely on getting
such exceptions.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

end of thread, other threads:[~1998-12-19  0:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-17  0:00 Need exception despite Machine_Overflows is false Pascal MALAISE
1998-12-17  0:00 ` Matthew Heaney
1998-12-18  0:00   ` dewarr
1998-12-18  0:00     ` Matthew Heaney
1998-12-19  0:00       ` dewar
1998-12-18  0:00 ` Stephen Leake
1998-12-18  0:00   ` Pascal MALAISE
1998-12-19  0:00     ` dewarr
1998-12-18  0:00   ` Matthew Heaney

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