Patchwork [Ada] Tan should never raise Constraint_Error

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 29, 2011, 10:58 a.m.
Message ID <20110829105839.GA27996@adacore.com>
Download mbox | patch
Permalink /patch/112019/
State New
Headers show

Comments

Arnaud Charlet - Aug. 29, 2011, 10:58 a.m.
The check that raises Constraint_Error for arguments
that equal the machine number nearest Pi / 2.0 must
be removed, as the tangent of this machine number is
well-defined and does not overflow.

-- Test case, should compile and execute quietly
with Ada.Numerics.Long_Long_Elementary_Functions;
use Ada.Numerics.Long_Long_Elementary_Functions;

procedure Testtan is

   subtype Double is Long_Long_Float;

   X : Double := Ada.Numerics.Pi / 2.0;
   Y : Double;

begin
   Y := Tan (X);
   if not Y'Valid then
      raise Program_Error;
   end if;

end Testtan;

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-29  Geert Bosch  <bosch@adacore.com>

	* a-ngelfu.adb (Tan): Do not raise Constraint_Error if the argument is
	the closest machine number to Pi / 2.0.

Patch

Index: a-ngelfu.adb
===================================================================
--- a-ngelfu.adb	(revision 178155)
+++ a-ngelfu.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -914,9 +914,6 @@ 
    begin
       if abs X < Sqrt_Epsilon then
          return X;
-
-      elsif abs X = Pi / 2.0 then
-         raise Constraint_Error;
       end if;
 
       return Float_Type'Base (Aux.Tan (Double (X)));