Implement carg(3) and cargf(3).

Rotting in an old src tree since: March 2005
This commit is contained in:
David Schultz 2007-12-12 23:43:51 +00:00
parent 76b262c426
commit 205bd64894
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=174561
6 changed files with 122 additions and 9 deletions

View File

@ -45,6 +45,8 @@ __BEGIN_DECLS
double cabs(double complex);
float cabsf(float complex);
double carg(double complex);
float cargf(float complex);
double cimag(double complex);
float cimagf(float complex);
long double cimagl(long double complex);

View File

@ -38,8 +38,8 @@ COMMON_SRCS= b_exp.c b_log.c b_tgamma.c \
e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c fenv.c \
k_cos.c k_cosf.c k_rem_pio2.c k_sin.c k_sinf.c \
k_tan.c k_tanf.c \
s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_cbrt.c s_cbrtf.c \
s_ceil.c s_ceilf.c s_ceill.c \
s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_carg.c s_cargf.c \
s_cbrt.c s_cbrtf.c s_ceil.c s_ceilf.c s_ceill.c \
s_copysign.c s_copysignf.c s_cos.c s_cosf.c s_erf.c s_erff.c \
s_exp2.c s_exp2f.c s_expm1.c s_expm1f.c s_fabsf.c s_fdim.c \
s_finite.c s_finitef.c \
@ -106,7 +106,7 @@ MLINKS+=asin.3 asinf.3
MLINKS+=asinh.3 asinhf.3
MLINKS+=atan.3 atanf.3
MLINKS+=atanh.3 atanhf.3
MLINKS+=atan2.3 atan2f.3
MLINKS+=atan2.3 atan2f.3 atan2.3 carg.3 atan2.3 cargf.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 \

View File

@ -28,13 +28,15 @@
.\" from: @(#)atan2.3 5.1 (Berkeley) 5/2/91
.\" $FreeBSD$
.\"
.Dd January 14, 2005
.Dd December 12, 2007
.Dt ATAN2 3
.Os
.Sh NAME
.Nm atan2 ,
.Nm atan2f
.Nd arc tangent functions of two variables
.Nm atan2f ,
.Nm carg ,
.Nm cargf
.Nd arc tangent and complex phase angle functions
.Sh LIBRARY
.Lb libm
.Sh SYNOPSIS
@ -43,6 +45,10 @@
.Fn atan2 "double y" "double x"
.Ft float
.Fn atan2f "float y" "float x"
.Ft double
.Fn carg "double complex z"
.Ft float
.Fn cargf "float complex z"
.Sh DESCRIPTION
The
.Fn atan2
@ -52,6 +58,29 @@ functions compute the principal value of the arc tangent of
.Fa y/ Ns Ar x ,
using the signs of both arguments to determine the quadrant of
the return value.
.ie '\*[.T]'utf8' \{\
. ds Th \[*h]
.\}
.el \{\
. ds Th theta
.\}
.Pp
The
.Fn carg
and
.Fn cargf
functions compute the complex argument (or phase angle) of
.Fa z .
The complex argument is the number \*(Th such that
.Li z = r * e^(I * \*(Th) ,
where
.Li r = cabs(z) .
The call
.Li carg(z)
is equivalent to
.Li atan2(cimag(z), creal(z)) ,
and similarly for
.Fn cargf .
.Sh RETURN VALUES
The
.Fn atan2
@ -169,6 +198,7 @@ r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);
.Xr acos 3 ,
.Xr asin 3 ,
.Xr atan 3 ,
.Xr cabs 3 ,
.Xr cos 3 ,
.Xr cosh 3 ,
.Xr math 3 ,
@ -178,6 +208,10 @@ r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);
.Xr tanh 3
.Sh STANDARDS
The
.Fn atan2
function conforms to
.Fn atan2 ,
.Fn atan2f ,
.Fn carg ,
and
.Fn cargf
functions conform to
.St -isoC .

View File

@ -28,7 +28,7 @@
.\" from: @(#)hypot.3 6.7 (Berkeley) 5/6/91
.\" $FreeBSD$
.\"
.Dd January 14, 2005
.Dd December 12, 2007
.Dt HYPOT 3
.Os
.Sh NAME
@ -118,6 +118,7 @@ the
disappear when it turns out to be irrelevant, as it does in
.Fn hypot "\*(If" "\*(Na" .
.Sh SEE ALSO
.Xr carg 3 ,
.Xr math 3 ,
.Xr sqrt 3
.Sh HISTORY

38
lib/msun/src/s_carg.c Normal file
View File

@ -0,0 +1,38 @@
/*-
* Copyright (c) 2005 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>
double
carg(double complex z)
{
return (atan2(cimag(z), creal(z)));
}

38
lib/msun/src/s_cargf.c Normal file
View File

@ -0,0 +1,38 @@
/*-
* Copyright (c) 2005 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>
float
cargf(float complex z)
{
return (atan2f(cimagf(z), crealf(z)));
}