* Forcing exceptions on NANs with GNAT?
@ 2008-11-20 11:09 Markus Schoepflin
2008-11-20 13:35 ` Jean-Pierre Rosen
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Markus Schoepflin @ 2008-11-20 11:09 UTC (permalink / raw)
Platform: Linux
Compiler: GCC/GNAT 3.4.3
Hello,
is it possible to influence the behaviour of GNAT regarding the handling of
NANs? (Most importantly in the special case of division by zero.)
We need to get exceptions whenever a NAN is generated, is this possible
somehow? (For example by setting Machine_Overflow to True and recompiling
the compiler itself.)
Regards,
Markus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Forcing exceptions on NANs with GNAT?
2008-11-20 11:09 Forcing exceptions on NANs with GNAT? Markus Schoepflin
@ 2008-11-20 13:35 ` Jean-Pierre Rosen
2008-11-20 13:46 ` Dmitry A. Kazakov
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Jean-Pierre Rosen @ 2008-11-20 13:35 UTC (permalink / raw)
Markus Schoepflin a �crit :
> is it possible to influence the behaviour of GNAT regarding the handling
> of NANs? (Most importantly in the special case of division by zero.)
>
Note that regular division by 0 does not generate NaN, only 0/0 does.
(For your original question, I'm afraid the answer is "No").
--
---------------------------------------------------------
J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Forcing exceptions on NANs with GNAT?
2008-11-20 11:09 Forcing exceptions on NANs with GNAT? Markus Schoepflin
2008-11-20 13:35 ` Jean-Pierre Rosen
@ 2008-11-20 13:46 ` Dmitry A. Kazakov
2008-11-21 19:55 ` sjw
2008-11-20 16:19 ` Adam Beneschan
` (2 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Dmitry A. Kazakov @ 2008-11-20 13:46 UTC (permalink / raw)
On Thu, 20 Nov 2008 12:09:41 +0100, Markus Schoepflin wrote:
> is it possible to influence the behaviour of GNAT regarding the handling of
> NANs? (Most importantly in the special case of division by zero.)
>
> We need to get exceptions whenever a NAN is generated, is this possible
> somehow? (For example by setting Machine_Overflow to True and recompiling
> the compiler itself.)
You can scrap IEEE stuff in favor of Ada semantics by declaring your own
floating-point [sub]type with a range specified. The compiler will be
forced to check values:
type Safe_Float is digits 6 range -10.0E10..+10.0E10;
or
subtype Safe_Float is Float range Float'Range;
then
X : Safe_Float := 1.0;
Y : Safe_Float := 0.0;
begin
Y := X / Y;
exception
when Error : others => -- Should print "range check failed"
Put_Line (Exception_Message (Error));
end;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Forcing exceptions on NANs with GNAT?
2008-11-20 11:09 Forcing exceptions on NANs with GNAT? Markus Schoepflin
2008-11-20 13:35 ` Jean-Pierre Rosen
2008-11-20 13:46 ` Dmitry A. Kazakov
@ 2008-11-20 16:19 ` Adam Beneschan
2008-11-21 5:01 ` Jerry
2008-11-21 9:33 ` Markus Schoepflin
4 siblings, 0 replies; 7+ messages in thread
From: Adam Beneschan @ 2008-11-20 16:19 UTC (permalink / raw)
On Nov 20, 3:09 am, Markus Schoepflin <nos...@no.spam> wrote:
> Platform: Linux
> Compiler: GCC/GNAT 3.4.3
>
> Hello,
>
> is it possible to influence the behaviour of GNAT regarding the handling of
> NANs? (Most importantly in the special case of division by zero.)
>
> We need to get exceptions whenever a NAN is generated, is this possible
> somehow? (For example by setting Machine_Overflow to True and recompiling
> the compiler itself.)
I really don't know that much about GNAT, but do those operations
cause SIGFPE signals to be generated, and if so, can they be caught by
an interrupt handler (see C.3)? And can that handler raise an
exception that is propagated to the program (task) that performed the
operation?
-- Adam
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Forcing exceptions on NANs with GNAT?
2008-11-20 11:09 Forcing exceptions on NANs with GNAT? Markus Schoepflin
` (2 preceding siblings ...)
2008-11-20 16:19 ` Adam Beneschan
@ 2008-11-21 5:01 ` Jerry
2008-11-21 9:33 ` Markus Schoepflin
4 siblings, 0 replies; 7+ messages in thread
From: Jerry @ 2008-11-21 5:01 UTC (permalink / raw)
On Nov 20, 4:09 am, Markus Schoepflin <nos...@no.spam> wrote:
> Platform: Linux
> Compiler: GCC/GNAT 3.4.3
>
> Hello,
>
> is it possible to influence the behaviour of GNAT regarding the handling of
> NANs? (Most importantly in the special case of division by zero.)
>
> We need to get exceptions whenever a NAN is generated, is this possible
> somehow? (For example by setting Machine_Overflow to True and recompiling
> the compiler itself.)
>
> Regards,
> Markus
There was a discussion about NaNs a while back. Not sure how much of
it is useful to you, but here's the link:
http://groups.google.com/group/comp.lang.ada/browse_thread/thread/772ddcb41cd06d5b/746f9f7e98a8d2f9?hl=en#746f9f7e98a8d2f9
Jerry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Forcing exceptions on NANs with GNAT?
2008-11-20 11:09 Forcing exceptions on NANs with GNAT? Markus Schoepflin
` (3 preceding siblings ...)
2008-11-21 5:01 ` Jerry
@ 2008-11-21 9:33 ` Markus Schoepflin
4 siblings, 0 replies; 7+ messages in thread
From: Markus Schoepflin @ 2008-11-21 9:33 UTC (permalink / raw)
Markus Schoepflin wrote:
> is it possible to influence the behaviour of GNAT regarding the handling
> of NANs? (Most importantly in the special case of division by zero.)
[...]
Thanks all for the answers.
The suggestion from Dmitry (create a subtype with the same range as float)
works fine for my purposes, GNAT then raises range check errors for both
division by zero and overflows.
Markus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Forcing exceptions on NANs with GNAT?
2008-11-20 13:46 ` Dmitry A. Kazakov
@ 2008-11-21 19:55 ` sjw
0 siblings, 0 replies; 7+ messages in thread
From: sjw @ 2008-11-21 19:55 UTC (permalink / raw)
On Nov 20, 1:46 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> subtype Safe_Float is Float range Float'Range;
Thanks for that, Dmitry; when I had to do the same thing at the office
I said 'range Float'First .. First'Last'. Yours is clearly the Right
Way to do this.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-11-21 19:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-20 11:09 Forcing exceptions on NANs with GNAT? Markus Schoepflin
2008-11-20 13:35 ` Jean-Pierre Rosen
2008-11-20 13:46 ` Dmitry A. Kazakov
2008-11-21 19:55 ` sjw
2008-11-20 16:19 ` Adam Beneschan
2008-11-21 5:01 ` Jerry
2008-11-21 9:33 ` Markus Schoepflin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox