1 /* Copyright (c) 2016 Yaakov Selkowitz <yselkowi@redhat.com> */
2 /*
3 FUNCTION
4         <<clog10>>, <<clog10f>>---complex base-10 logarithm
5 
6 INDEX
7         clog10
8 INDEX
9         clog10f
10 
11 SYNOPSIS
12        #define _DEFAULT_SOURCE
13        #include <complex.h>
14        double complex clog10(double complex <[z]>);
15        float complex clog10f(float complex <[z]>);
16 
17 
18 DESCRIPTION
19         These functions compute the complex base-10 logarithm of <[z]>.
20         <<clog10>> is equivalent to <<clog>>(<[z]>)/<<log>>(10).
21 
22         <<clog10f>> is identical to <<clog10>>, except that it performs
23         its calculations on <<floats complex>>.
24 
25 RETURNS
26         The clog10 functions return the complex base-10 logarithm value.
27 
28 PORTABILITY
29         <<clog10>> and <<clog10f>> are GNU extensions.
30 
31 */
32 
33 #define _DEFAULT_SOURCE
34 #include <complex.h>
35 #include <math.h>
36 
37 double complex
clog10(double complex z)38 clog10(double complex z)
39 {
40 	double complex w;
41 	double p, rr;
42 
43 	rr = cabs(z);
44 	p = log10(rr);
45 	rr = atan2(cimag(z), creal(z)) * M_IVLN10;
46 	w = p + rr * (double complex) I;
47 	return w;
48 }
49