4 How to make Ada generate an exception on some floating points operations?

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