Implement cproj{,f,l}().

This commit is contained in:
David Schultz 2008-08-07 15:07:48 +00:00
parent 419859bd08
commit 5e9470f1d5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=181377
7 changed files with 174 additions and 7 deletions

View file

@ -56,6 +56,10 @@ double complex conj(double complex) __pure2;
float complex conjf(float complex) __pure2;
long double complex
conjl(long double complex) __pure2;
float complex cprojf(float complex) __pure2;
double complex cproj(double complex) __pure2;
long double complex
cprojl(long double complex) __pure2;
double creal(double complex) __pure2;
float crealf(float complex) __pure2;
long double creall(long double complex) __pure2;

View file

@ -87,7 +87,8 @@ COMMON_SRCS+= s_copysignl.c s_fabsl.c s_llrintl.c s_lrintl.c s_modfl.c
COMMON_SRCS+= e_acosl.c e_asinl.c e_atan2l.c e_fmodl.c \
e_hypotl.c e_remainderl.c e_sqrtl.c \
invtrig.c k_cosl.c k_sinl.c k_tanl.c \
s_atanl.c s_ceill.c s_cosl.c s_csqrtl.c s_exp2l.c s_floorl.c s_fmal.c \
s_atanl.c s_ceill.c s_cosl.c s_cprojl.c s_csqrtl.c s_exp2l.c \
s_floorl.c s_fmal.c \
s_frexpl.c s_logbl.c s_nanl.c s_nextafterl.c s_nexttoward.c \
s_remquol.c s_rintl.c s_scalbnl.c \
s_sinl.c s_tanl.c s_truncl.c w_cabsl.c
@ -95,7 +96,7 @@ COMMON_SRCS+= e_acosl.c e_asinl.c e_atan2l.c e_fmodl.c \
# C99 complex functions
COMMON_SRCS+= s_cimag.c s_cimagf.c s_cimagl.c s_conj.c s_conjf.c s_conjl.c \
s_creal.c s_crealf.c s_creall.c
s_cproj.c s_cprojf.c s_creal.c s_crealf.c s_creall.c
# FreeBSD's C library supplies these functions:
#COMMON_SRCS+= s_fabs.c s_frexp.c s_isnan.c s_ldexp.c s_modf.c
@ -131,6 +132,7 @@ MLINKS+=atan2.3 atan2f.3 atan2.3 atan2l.3 \
MLINKS+=ceil.3 ceilf.3 ceil.3 ceill.3
MLINKS+=cimag.3 cimagf.3 cimag.3 cimagl.3 \
cimag.3 conj.3 cimag.3 conjf.3 cimag.3 conjl.3 \
cimag.3 cproj.3 cimag.3 cprojf.3 cimag.3 cprojl.3 \
cimag.3 creal.3 cimag.3 crealf.3 cimag.3 creall.3
MLINKS+=copysign.3 copysignf.3 copysign.3 copysignl.3
MLINKS+=cos.3 cosf.3 cos.3 cosl.3

View file

@ -214,4 +214,7 @@ FBSD_1.1 {
atan2l;
atanl;
cargl;
cproj;
cprojf;
cprojl;
};

View file

@ -24,12 +24,13 @@
.\"
.\" $FreeBSD$
.\"
.Dd August 7, 2004
.Dd August 7, 2008
.Dt CIMAG 3
.Os
.Sh NAME
.Nm cimag , cimagf , cimagl ,
.Nm conj , conjf , conjl ,
.Nm cproj , cprojf , cprojl ,
.Nm creal , crealf , creall
.Nd "functions to manipulate complex numbers"
.Sh LIBRARY
@ -48,6 +49,12 @@
.Fn conjf "float complex z"
.Ft "long double complex"
.Fn conjl "long double complex z"
.Ft "double complex"
.Fn cproj "double complex z"
.Ft "float complex"
.Fn cprojf "float complex z"
.Ft "long double complex"
.Fn cprojl "long double complex z"
.Ft double
.Fn creal "double complex z"
.Ft float
@ -63,6 +70,10 @@ denote the complex number
.Fa z .
.Pp
The
.Fn creal
functions return the real part
.Fa a ,
and the
.Fn cimag
functions return the imaginary part
.Fa b .
@ -75,13 +86,23 @@ functions return the complex conjugate
.Sm on
.Pp
The
.Fn creal
functions return the real part
.Fa a .
.Fn cproj
functions return the projection onto the Riemann sphere.
If
.Fa z
contains an infinite component, then the result is
.Fa \*(If \*(Pm 0 Ns * Ns Em i ,
where the (zero) imaginary part of the result has the same sign as
.Fa b .
Otherwise, the result is
.Fa z .
.Pp
These functions do not signal any floating point exceptions.
.Sh STANDARDS
The
.Fn cimag ,
.Fn conj
.Fn conj ,
.Fn cproj ,
and
.Fn creal
functions conform to
@ -94,3 +115,7 @@ and
.Fn creal
functions first appeared in
.Fx 5.3 .
The
.Fn cproj
functions appeared in
.Fx 8.0.

47
lib/msun/src/s_cproj.c Normal file
View file

@ -0,0 +1,47 @@
/*-
* Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <complex.h>
#include <math.h>
#include "math_private.h"
double complex
cproj(double complex z)
{
if (!isinf(creal(z)) && !isinf(cimag(z)))
return (z);
else
return (cpack(INFINITY, copysign(0.0, cimag(z))));
}
#if LDBL_MANT_DIG == 53
__weak_reference(cproj, cprojl);
#endif

43
lib/msun/src/s_cprojf.c Normal file
View file

@ -0,0 +1,43 @@
/*-
* Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <complex.h>
#include <math.h>
#include "math_private.h"
float complex
cprojf(float complex z)
{
if (!isinf(crealf(z)) && !isinf(cimagf(z)))
return (z);
else
return (cpackf(INFINITY, copysignf(0.0, cimagf(z))));
}

43
lib/msun/src/s_cprojl.c Normal file
View file

@ -0,0 +1,43 @@
/*-
* Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <complex.h>
#include <math.h>
#include "math_private.h"
long double complex
cprojl(long double complex z)
{
if (!isinf(creall(z)) && !isinf(cimagl(z)))
return (z);
else
return (cpackl(INFINITY, copysignl(0.0, cimagl(z))));
}