1function C = atan2 (A, B)
2%ATAN2 four quadrant inverse tangent.
3% C = atan2 (X,Y) is the 4 quadrant arctangent of the entries in X and Y.
4%
5% See also GrB/tan, GrB/tanh, GrB/atan, GrB/atanh.
6
7% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
8% SPDX-License-Identifier: GPL-3.0-or-later
9
10% FUTURE: atan2(A,B) for two matrices A and B is slower than it could be.
11% See comments in gb_union_op.
12
13if (isobject (A))
14    A = A.opaque ;
15end
16
17if (isobject (B))
18    B = B.opaque ;
19end
20
21atype = gbtype (A) ;
22btype = gbtype (B) ;
23
24if (contains (atype, 'complex') || contains (btype, 'complex'))
25    error ('inputs must be real') ;
26end
27
28if (~gb_isfloat (atype))
29    A = gbnew (A, 'double') ;
30end
31
32if (~gb_isfloat (btype))
33    B = gbnew (B, 'double') ;
34end
35
36% atan2(A,B) gives the set union of the pattern of A and B
37
38if (gb_isscalar (A))
39    if (gb_isscalar (B))
40        % both A and B are scalars
41        C = GrB (gbemult ('atan2', A, B)) ;
42    else
43        % A is a scalar, B is a matrix
44        C = GrB (gbapply2 ('atan2', A, B)) ;
45    end
46else
47    if (gb_isscalar (B))
48        % A is a matrix, B is a scalar
49        C = GrB (gbapply2 ('atan2', A, B)) ;
50    else
51        % both A and B are matrices.  C is the set union of A and B.
52        C = GrB (gb_union_op ('atan2', A, B)) ;
53    end
54end
55
56