aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/options/ansi/generic/complex/carg.c
blob: 0447420342345c91eb21fa727056b0b9d85d502c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* $NetBSD: carg.c,v 1.1 2007/08/20 16:01:31 drochner Exp $ */

/*
 * Written by Matthias Drochner <drochner@NetBSD.org>.
 * Public domain.
 *
 * imported and modified include for newlib 2010/10/03 
 * Marco Atzeri <marco_atzeri@yahoo.it>
 */

/*
FUNCTION
        <<carg>>, <<cargf>>---argument (phase angle)

INDEX
        carg
INDEX
        cargf

ANSI_SYNOPSIS
       #include <complex.h>
       double carg(double complex <[z]>);
       float cargf(float complex <[z]>);


DESCRIPTION
        These functions compute the argument (also called phase angle) 
        of <[z]>, with a branch cut along the negative real axis.

        <<cargf>> is identical to <<carg>>, except that it performs
        its calculations on <<floats complex>>.

RETURNS
        @ifnottex
        The carg functions return the value of the argument in the 
        interval [-pi, +pi]
        @end ifnottex
        @tex
        The carg functions return the value of the argument in the 
        interval [$-\pi$, $+\pi$]
        @end tex

PORTABILITY
        <<carg>> and <<cargf>> are ISO C99

QUICKREF
        <<carg>> and <<cargf>> are ISO C99

*/

#include <complex.h>
#include <math.h>

double
carg(double complex z)
{

	return atan2( cimag(z) , creal(z) );
}