From 755d0bf04f6bc5a88960b759fbeff6ed789f37b9 Mon Sep 17 00:00:00 2001 From: bde Date: Tue, 26 Mar 2002 11:59:29 +0000 Subject: Resurrect Lite1's gamma() as C99's tgamma(). Minimal changes. --- lib/msun/Makefile | 6 ++++-- lib/msun/bsdsrc/b_exp.c | 2 ++ lib/msun/bsdsrc/b_log.c | 2 ++ lib/msun/bsdsrc/b_tgamma.c | 10 +++++----- lib/msun/man/lgamma.3 | 45 ++++++++++++++++++++++++++++----------------- lib/msun/src/math.h | 1 + 6 files changed, 42 insertions(+), 24 deletions(-) diff --git a/lib/msun/Makefile b/lib/msun/Makefile index b195fdc..b7c5184 100644 --- a/lib/msun/Makefile +++ b/lib/msun/Makefile @@ -62,13 +62,15 @@ ARCH_SRCS = e_acos.S e_asin.S e_atan2.S e_exp.S e_fmod.S e_log.S e_log10.S \ # Broken # ARCH_SRCS+= s_log1p.S +.PATH: ${.CURDIR}/bsdsrc .PATH: ${.CURDIR}/man .PATH: ${.CURDIR}/src CFLAGS+= -D_IEEE_LIBM -D_ARCH_INDIRECT=${ARCH_PREFIX} LIB= m -COMMON_SRCS = e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \ +COMMON_SRCS= b_exp.c b_log.c b_tgamma.c \ + e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \ e_atan2.c e_atan2f.c e_atanh.c e_atanhf.c e_cosh.c e_coshf.c e_exp.c \ e_expf.c e_fmod.c e_fmodf.c e_gamma.c e_gamma_r.c e_gammaf.c \ e_gammaf_r.c e_hypot.c e_hypotf.c e_j0.c e_j0f.c e_j1.c e_j1f.c \ @@ -147,7 +149,7 @@ MLINKS+=ieee_test.3 scalb.3 ieee_test.3 scalbf.3 MLINKS+=ieee_test.3 significand.3 ieee_test.3 significandf.3 MLINKS+=j0.3 j1.3 j0.3 jn.3 j0.3 y0.3 j0.3 y1.3 j0.3 y1f.3 j0.3 yn.3 MLINKS+=j0.3 j0f.3 j0.3 j1f.3 j0.3 jnf.3 j0.3 y0f.3 j0.3 ynf.3 -MLINKS+=lgamma.3 gamma.3 lgamma.3 lgammaf.3 lgamma.3 gammaf.3 +MLINKS+=lgamma.3 gamma.3 lgamma.3 gammaf.3 lgamma.3 lgammaf.3 lgamma.3 tgamma.3 MLINKS+=rint.3 rintf.3 MLINKS+=sin.3 sinf.3 MLINKS+=sinh.3 sinhf.3 diff --git a/lib/msun/bsdsrc/b_exp.c b/lib/msun/bsdsrc/b_exp.c index 3804766..64d9a3d 100644 --- a/lib/msun/bsdsrc/b_exp.c +++ b/lib/msun/bsdsrc/b_exp.c @@ -117,6 +117,7 @@ ic(lnhuge, 7.1602103751842355450E2, 9, 1.6602B15B7ECF2) ic(lntiny,-7.5137154372698068983E2, 9, -1.77AF8EBEAE354) ic(invln2, 1.4426950408889633870E0, 0, 1.71547652B82FE) +#if 0 double exp(x) double x; { @@ -159,6 +160,7 @@ double x; /* exp(INF) is INF, exp(+big#) overflows to INF */ return( finite(x) ? scalb(1.0,5000) : x); } +#endif /* returns exp(r = x + c) for |c| < |x| with no overlap. */ diff --git a/lib/msun/bsdsrc/b_log.c b/lib/msun/bsdsrc/b_log.c index 715fce1..101f8b1 100644 --- a/lib/msun/bsdsrc/b_log.c +++ b/lib/msun/bsdsrc/b_log.c @@ -367,6 +367,7 @@ static double logF_tail[N+1] = { -.00000000000017239444525614834 }; +#if 0 double #ifdef _ANSI_SOURCE log(double x) @@ -437,6 +438,7 @@ log(x) double x; u2 += logF_tail[N]*m; return (u1 + u2); } +#endif /* * Extra precision variant, returning struct {double a, b;}; diff --git a/lib/msun/bsdsrc/b_tgamma.c b/lib/msun/bsdsrc/b_tgamma.c index 4859088..6c405df 100644 --- a/lib/msun/bsdsrc/b_tgamma.c +++ b/lib/msun/bsdsrc/b_tgamma.c @@ -34,7 +34,7 @@ #ifndef lint static char sccsid[] = "@(#)gamma.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ -include +#include __FBSDID("$FreeBSD$"); /* @@ -138,7 +138,7 @@ static int endian; #endif double -gamma(x) +tgamma(x) double x; { struct Double u; @@ -225,7 +225,7 @@ small_gam(x) TRUNC(r.a); r.b += (t - r.a); } - /* Return r*gamma(y). */ + /* Return r*tgamma(y). */ yy = ratfun_gam(y - x0, 0); y = r.b*(yy.a + yy.b) + r.a*yy.b; y += yy.a*r.a; @@ -330,9 +330,9 @@ neg_gam(x) } y = one-x; if (one-y == x) - y = gamma(y); + y = tgamma(y); else /* 1-x is inexact */ - y = -x*gamma(-x); + y = -x*tgamma(-x); if (sgn < 0) y = -y; return (M_PI / (y*z)); } diff --git a/lib/msun/man/lgamma.3 b/lib/msun/man/lgamma.3 index 97630d1..c3d4ba7 100644 --- a/lib/msun/man/lgamma.3 +++ b/lib/msun/man/lgamma.3 @@ -39,8 +39,9 @@ .Nm lgamma , .Nm lgammaf , .Nm gamma , -.Nm gammaf -.Nd log gamma functions, gamma functions +.Nm gammaf , +.Nm tgamma +.Nd log gamma functions, gamma function .Sh LIBRARY .Lb libm .Sh SYNOPSIS @@ -56,6 +57,8 @@ .Fn gamma "double x" .Ft float .Fn gammaf "float x" +.Ft double +.Fn tgamma "double x" .Sh DESCRIPTION .Fn lgamma x and @@ -83,6 +86,9 @@ are deprecated aliases for and .Fn lgammaf , respectively. +.Fn tgamma x +returns \(*G(x), with no effect on +.Fa signgam . .Sh IDIOSYNCRASIES Do not use the expression .Dq Li signgam\(**exp(lgamma(x)) @@ -97,14 +103,14 @@ Only after or .Fn lgammaf has returned can signgam be correct. -.\".Pp -.\"For arguments in its range, -.\".Fn gamma -.\"is preferred, as for positive arguments -.\"it is accurate to within one unit in the last place. -.\"Exponentiation of -.\".Fn lgamma -.\"will lose up to 10 significant bits. +.Pp +For arguments in its range, +.Fn tgamma +is preferred, as for positive arguments +it is accurate to within one unit in the last place. +Exponentiation of +.Fn lgamma +will lose up to 10 significant bits. .Sh RETURN VALUES .Fn gamma , .Fn gammaf , @@ -121,11 +127,18 @@ and .Va errno is set to .Er ERANGE . -\."For large non-integer negative values, -\.".Fn gamma -\."will underflow. +For large non-integer negative values, +.Fn tgamma +will underflow. .Sh SEE ALSO .Xr math 3 +.Sh STANDARDS +The +.Fn lgamma +and +.Fn tgamma +functions are expected to conform to +.St -isoC-99 . .Sh HISTORY The .Fn lgamma @@ -146,8 +159,6 @@ function, and that usage was restored by switching to Sun's fdlibm in .Fx 1.1.5 . The -.St -isoC-99 -standard specifies a function .Fn tgamma -for computing \(*G(x). -This function is currently unimplemented in this library. +function appeared in +.Fx 5.0 . diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h index 1745ffa..108b086 100644 --- a/lib/msun/src/math.h +++ b/lib/msun/src/math.h @@ -153,6 +153,7 @@ double logb(double); double nextafter(double, double); double remainder(double, double); double scalb(double, double); +double tgamma(double); #ifndef __cplusplus int matherr(struct exception *); -- cgit v1.1