xref: /dflybsd-src/contrib/openbsd_libm/src/s_cproj.c (revision 4382f29d99a100bd77a81697c2f699c11f6a472a)
1*05a0b428SJohn Marino /*	$OpenBSD: s_cproj.c,v 1.7 2013/07/03 04:46:36 espie Exp $	*/
2*05a0b428SJohn Marino /*
3*05a0b428SJohn Marino  * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
4*05a0b428SJohn Marino  *
5*05a0b428SJohn Marino  * Permission to use, copy, modify, and distribute this software for any
6*05a0b428SJohn Marino  * purpose with or without fee is hereby granted, provided that the above
7*05a0b428SJohn Marino  * copyright notice and this permission notice appear in all copies.
8*05a0b428SJohn Marino  *
9*05a0b428SJohn Marino  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*05a0b428SJohn Marino  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*05a0b428SJohn Marino  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*05a0b428SJohn Marino  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*05a0b428SJohn Marino  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*05a0b428SJohn Marino  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*05a0b428SJohn Marino  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*05a0b428SJohn Marino  */
17*05a0b428SJohn Marino 
18*05a0b428SJohn Marino #include <complex.h>
19*05a0b428SJohn Marino #include <float.h>
20*05a0b428SJohn Marino #include <math.h>
21*05a0b428SJohn Marino 
22*05a0b428SJohn Marino double complex
cproj(double complex z)23*05a0b428SJohn Marino cproj(double complex z)
24*05a0b428SJohn Marino {
25*05a0b428SJohn Marino 	double complex res;
26*05a0b428SJohn Marino 
27*05a0b428SJohn Marino 	if (isinf(__real__ z) || isinf(__imag__ z)) {
28*05a0b428SJohn Marino 		__real__ res = INFINITY;
29*05a0b428SJohn Marino 		__imag__ res = copysign(0.0, __imag__ z);
30*05a0b428SJohn Marino 	} else {
31*05a0b428SJohn Marino 		res = z;
32*05a0b428SJohn Marino 	}
33*05a0b428SJohn Marino 
34*05a0b428SJohn Marino 	return res;
35*05a0b428SJohn Marino }
36*05a0b428SJohn Marino 
37*05a0b428SJohn Marino #if	LDBL_MANT_DIG == DBL_MANT_DIG
38*05a0b428SJohn Marino __strong_alias(cprojl, cproj);
39*05a0b428SJohn Marino #endif	/* LDBL_MANT_DIG == DBL_MANT_DIG */
40