]> gcc.gnu.org Git - gcc.git/commitdiff
re PR fortran/33197 (Fortran 2008: math functions)
authorTobias Burnus <burnus@net-b.de>
Sun, 26 Jul 2009 17:25:56 +0000 (19:25 +0200)
committerTobias Burnus <burnus@gcc.gnu.org>
Sun, 26 Jul 2009 17:25:56 +0000 (19:25 +0200)
2009-07-26  Tobias Burnus  <burnus@net-b.de>

        PR fortran/33197
        * intrinsic.c (make_generic): Remove assert as "atan" can be
        both ISYM_ATAN and ISYM_ATAN2.
        (add_functions): Add two-argument variant of ATAN.
        * intrinsic.h (gfc_check_atan_2): Add check for it.
        * intrinsic.texi (ATAN2): Correct and enhance description.
        (ATAN): Describe two-argument variant of ATAN.

2009-07-26  Tobias Burnus  <burnus@net-b.de>

        PR fortran/33197
        * gfortran.dg/atan2_1.f90: New test
        * gfortran.dg/atan2_2.f90: New test

From-SVN: r150100

gcc/fortran/ChangeLog
gcc/fortran/check.c
gcc/fortran/intrinsic.c
gcc/fortran/intrinsic.h
gcc/fortran/intrinsic.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/atan2_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/atan2_2.f90 [new file with mode: 0644]

index 363889f7195cc661afc91c177b43aaba2c60536d..ca320ca8e71470ea9038b81df27e70660d44643f 100644 (file)
@@ -1,3 +1,13 @@
+2009-07-26  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/33197
+       * intrinsic.c (make_generic): Remove assert as "atan" can be
+       both ISYM_ATAN and ISYM_ATAN2.
+       (add_functions): Add two-argument variant of ATAN.
+       * intrinsic.h (gfc_check_atan_2): Add check for it.
+       * intrinsic.texi (ATAN2): Correct and enhance description.
+       (ATAN): Describe two-argument variant of ATAN.
+
 2009-07-25  Tobias Burnus  <burnus@net-b.de>
            Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
index e19f8124f09577f7f490f6409f006caf19d57935..779af2038e9cba8159de7c7c63ac4243627c5488 100644 (file)
@@ -675,6 +675,19 @@ null_arg:
 }
 
 
+gfc_try
+gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
+{
+  /* gfc_notify_std would be a wast of time as the return value
+     is seemingly used only for the generic resolution.  The error
+     will be: Too many arguments.  */
+  if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
+    return FAILURE;
+
+  return gfc_check_atan2 (y, x);
+}
+
+
 gfc_try
 gfc_check_atan2 (gfc_expr *y, gfc_expr *x)
 {
index 0b2d1b8c8dbe12e87ff27530de24bf504773c447..d2cdb591888ca9c8d4ae55d29e7438b3bada11f8 100644 (file)
@@ -1008,8 +1008,6 @@ make_generic (const char *name, gfc_isym_id id, int standard ATTRIBUTE_UNUSED)
 
   while (g->name != NULL)
     {
-      gcc_assert (g->id == id);
-
       g->next = g + 1;
       g->specific = 1;
       g++;
@@ -1250,6 +1248,11 @@ add_functions (void)
             gfc_check_fn_d, gfc_simplify_atan, gfc_resolve_atan,
             x, BT_REAL, dd, REQUIRED);
 
+  /* Two-argument version of atan, equivalent to atan2.  */
+  add_sym_2 ("atan", GFC_ISYM_ATAN2, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL, dr, GFC_STD_F2008,
+            gfc_check_atan_2, gfc_simplify_atan2, gfc_resolve_atan2,
+            y, BT_REAL, dr, REQUIRED, x, BT_REAL, dr, REQUIRED);
+
   make_generic ("atan", GFC_ISYM_ATAN, GFC_STD_F77);
   
   add_sym_1 ("atanh", GFC_ISYM_ATANH, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL, dr,
index 1e2fbd7a0277b988174705314d75bcc32a59ad0d..a239ad6d35b1820fdcdbba6c06f37250e51b63e4 100644 (file)
@@ -37,6 +37,7 @@ gfc_try gfc_check_achar (gfc_expr *, gfc_expr *);
 gfc_try gfc_check_all_any (gfc_expr *, gfc_expr *);
 gfc_try gfc_check_allocated (gfc_expr *);
 gfc_try gfc_check_associated (gfc_expr *, gfc_expr *);
+gfc_try gfc_check_atan_2 (gfc_expr *, gfc_expr *);
 gfc_try gfc_check_atan2 (gfc_expr *, gfc_expr *);
 gfc_try gfc_check_besn (gfc_expr *, gfc_expr *);
 gfc_try gfc_check_btest (gfc_expr *, gfc_expr *);
index 2e6908f705bdc3fbbba7d012956cfcb00f71874d..2c993b9048a90ce37ac9f0e831a27da52d3d6a65 100644 (file)
@@ -1353,22 +1353,28 @@ end program test_associated
 @code{ATAN(X)} computes the arctangent of @var{X}.
 
 @item @emph{Standard}:
-Fortran 77 and later, for a complex argument Fortran 2008 or later
+Fortran 77 and later, for a complex argument and for two arguments
+Fortran 2008 or later
 
 @item @emph{Class}:
 Elemental function
 
 @item @emph{Syntax}:
 @code{RESULT = ATAN(X)}
+@code{RESULT = ATAN(Y, X)}
 
 @item @emph{Arguments}:
 @multitable @columnfractions .15 .70
-@item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX}.
+@item @var{X} @tab The type shall be @code{REAL} or @code{COMPLEX};
+if @var{Y} is present, @var{X} shall be REAL.
+@item @var{Y} shall be of the same type and kind as @var{X}.
 @end multitable
 
 @item @emph{Return value}:
 The return value is of the same type and kind as @var{X}.
-The real part of the result is in radians and lies in the range
+If @var{Y} is present, the result is identical to @code{ATAN2(Y,X)}.
+Otherwise, it the arcus tangent of @var{X}, where the real part of
+the result is in radians and lies in the range
 @math{-\pi/2 \leq \Re \atan(x) \leq \pi/2}.
 
 @item @emph{Example}:
@@ -1401,8 +1407,10 @@ Inverse function: @ref{TAN}
 
 @table @asis
 @item @emph{Description}:
-@code{ATAN2(Y, X)} computes the arctangent of the complex number
-@math{X + i Y}.
+@code{ATAN2(Y, X)} computes the principal value of the argument
+function of the complex number @math{X + i Y}. This function can
+be used to transform from carthesian into polar coordinates and
+allows to determine the angle in the correct quadrant.
 
 @item @emph{Standard}:
 Fortran 77 and later
index a8cea7576d33a5a9d87b03776cfc2aa9ab0fc2f6..f9bbf626f92613c1638d753d4775ee7f937dfdca 100644 (file)
@@ -1,3 +1,9 @@
+2009-07-26  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/33197
+       * gfortran.dg/atan2_1.f90: New test
+       * gfortran.dg/atan2_2.f90: New test
+
 2007-07-26  Simon Martin  <simartin@users.sourceforge.net>
 
        PR c++/40749
diff --git a/gcc/testsuite/gfortran.dg/atan2_1.f90 b/gcc/testsuite/gfortran.dg/atan2_1.f90
new file mode 100644 (file)
index 0000000..1f998a1
--- /dev/null
@@ -0,0 +1,36 @@
+! { dg-do run }
+!
+! PR fortran/33197
+!
+! Check for Fortran 2008's ATAN(Y,X) - which is equivalent
+! to Fortran 77's ATAN2(Y,X).
+!
+integer :: i
+real, parameter :: pi4 = 2*acos(0.0)
+real, parameter :: pi8 = 2*acos(0.0d0)
+do i = 1, 10
+  if(atan(1.0,  i/10.0)  -atan2(1.0,  i/10.)    /= 0.0)   call abort()
+  if(atan(1.0d0,i/10.0d0)-atan2(1.0d0,i/10.0d0) /= 0.0d0) call abort()
+end do
+
+! Atan(1,1) = Pi/4
+if (abs(atan(1.0,1.0)    -pi4/4.0)   > epsilon(pi4)) call abort()
+if (abs(atan(1.0d0,1.0d0)-pi8/4.0d0) > epsilon(pi8)) call abort()
+
+! Atan(-1,1) = -Pi/4
+if (abs(atan(-1.0,1.0)    +pi4/4.0)   > epsilon(pi4)) call abort()
+if (abs(atan(-1.0d0,1.0d0)+pi8/4.0d0) > epsilon(pi8)) call abort()
+
+! Atan(1,-1) = 3/4*Pi
+if (abs(atan(1.0,-1.0)    -3.0*pi4/4.0)     > epsilon(pi4)) call abort()
+if (abs(atan(1.0d0,-1.0d0)-3.0d0*pi8/4.0d0) > epsilon(pi8)) call abort()
+
+! Atan(-1,-1) = -3/4*Pi
+if (abs(atan(-1.0,-1.0)    +3.0*pi4/4.0)     > epsilon(pi4)) call abort()
+if (abs(atan(-1.0d0,-1.0d0)+3.0d0*pi8/4.0d0) > epsilon(pi8)) call abort()
+
+! Atan(3,-5) = 2.60117315331920908301906501867... = Pi - 3/2 atan(3/5)
+if (abs(atan(3.0,-5.0)    -2.60117315331920908301906501867) > epsilon(pi4)) call abort()
+if (abs(atan(3.0d0,-5.0d0)-2.60117315331920908301906501867d0) > epsilon(pi8)) call abort()
+
+end
diff --git a/gcc/testsuite/gfortran.dg/atan2_2.f90 b/gcc/testsuite/gfortran.dg/atan2_2.f90
new file mode 100644 (file)
index 0000000..407e83a
--- /dev/null
@@ -0,0 +1,30 @@
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+!
+! PR fortran/33197
+!
+! Check for Fortran 2008's ATAN(Y,X) - which is equivalent
+! to Fortran 77's ATAN2(Y,X).
+!
+real(4)    :: r4
+real(8)    :: r8
+complex(4) :: c4
+complex(8) :: c8
+
+r4 = atan2(r4,r4)
+r8 = atan2(r8,r8)
+
+r4 = atan(r4,r4) ! { dg-error "Too many arguments in call to 'atan'" }
+r8 = atan(r8,r8) ! { dg-error "Too many arguments in call to 'atan'" }
+
+r4 = atan2(r4,r8) ! { dg-error "same type and kind" }
+r4 = atan2(r8,r4) ! { dg-error "same type and kind" }
+
+r4 = atan2(c4,r8) ! { dg-error "must be REAL" }
+r4 = atan2(c8,r4) ! { dg-error "must be REAL" }
+r4 = atan2(r4,c8) ! { dg-error "same type and kind" }
+r4 = atan2(r8,c4) ! { dg-error "same type and kind" }
+
+r4 = atan2(c4,c8) ! { dg-error "must be REAL" }
+r4 = atan2(c8,c4) ! { dg-error "must be REAL" }
+end
This page took 0.093844 seconds and 5 git commands to generate.