xref: /freebsd/lib/msun/src/s_cproj.c (revision 003fdafbea1a788195114c28bf6a56e195e3a954)
15e9470f1SDavid Schultz /*-
25e53a4f9SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
35e53a4f9SPedro F. Giffuni  *
45e9470f1SDavid Schultz  * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
55e9470f1SDavid Schultz  * All rights reserved.
65e9470f1SDavid Schultz  *
75e9470f1SDavid Schultz  * Redistribution and use in source and binary forms, with or without
85e9470f1SDavid Schultz  * modification, are permitted provided that the following conditions
95e9470f1SDavid Schultz  * are met:
105e9470f1SDavid Schultz  * 1. Redistributions of source code must retain the above copyright
115e9470f1SDavid Schultz  *    notice, this list of conditions and the following disclaimer.
125e9470f1SDavid Schultz  * 2. Redistributions in binary form must reproduce the above copyright
135e9470f1SDavid Schultz  *    notice, this list of conditions and the following disclaimer in the
145e9470f1SDavid Schultz  *    documentation and/or other materials provided with the distribution.
155e9470f1SDavid Schultz  *
165e9470f1SDavid Schultz  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
175e9470f1SDavid Schultz  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
185e9470f1SDavid Schultz  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
195e9470f1SDavid Schultz  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
205e9470f1SDavid Schultz  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
215e9470f1SDavid Schultz  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
225e9470f1SDavid Schultz  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
235e9470f1SDavid Schultz  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
245e9470f1SDavid Schultz  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
255e9470f1SDavid Schultz  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
265e9470f1SDavid Schultz  * SUCH DAMAGE.
275e9470f1SDavid Schultz  */
285e9470f1SDavid Schultz 
295e9470f1SDavid Schultz #include <sys/cdefs.h>
305e9470f1SDavid Schultz __FBSDID("$FreeBSD$");
315e9470f1SDavid Schultz 
325e9470f1SDavid Schultz #include <complex.h>
33*003fdafbSJustin Hibbits #include <float.h>
345e9470f1SDavid Schultz #include <math.h>
355e9470f1SDavid Schultz 
365e9470f1SDavid Schultz #include "math_private.h"
375e9470f1SDavid Schultz 
385e9470f1SDavid Schultz double complex
395e9470f1SDavid Schultz cproj(double complex z)
405e9470f1SDavid Schultz {
415e9470f1SDavid Schultz 
425e9470f1SDavid Schultz 	if (!isinf(creal(z)) && !isinf(cimag(z)))
435e9470f1SDavid Schultz 		return (z);
445e9470f1SDavid Schultz 	else
452cec876aSEd Schouten 		return (CMPLX(INFINITY, copysign(0.0, cimag(z))));
465e9470f1SDavid Schultz }
475e9470f1SDavid Schultz 
485e9470f1SDavid Schultz #if LDBL_MANT_DIG == 53
495e9470f1SDavid Schultz __weak_reference(cproj, cprojl);
505e9470f1SDavid Schultz #endif
51