diff options
author | Jun T <takimoto-j@kba.biglobe.ne.jp> | 2013-10-27 00:41:03 +0900 |
---|---|---|
committer | Peter Stephenson <p.w.stephenson@ntlworld.com> | 2013-10-27 00:00:56 +0100 |
commit | ef4d20ad6fde1ca519a19ad60f2c31d86f5b1d98 (patch) | |
tree | e328dcbb8127ce13408d57af693e1a386b84fb6f | |
parent | 7a79f660db07283c25205af38a4a9fd8618db4d5 (diff) | |
download | zsh-ef4d20ad6fde1ca519a19ad60f2c31d86f5b1d98.tar.gz zsh-ef4d20ad6fde1ca519a19ad60f2c31d86f5b1d98.tar.xz zsh-ef4d20ad6fde1ca519a19ad60f2c31d86f5b1d98.zip |
31902: rationalise use of gamma function.
Make zsh/mathfunc consistent across systems and use tgamma() where available
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Doc/Zsh/mod_mathfunc.yo | 2 | ||||
-rw-r--r-- | Src/Modules/mathfunc.c | 9 | ||||
-rw-r--r-- | Test/V03mathfunc.ztst | 6 | ||||
-rw-r--r-- | configure.ac | 2 |
5 files changed, 22 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog index 0561a3e0c..db0177eeb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-10-26 Peter Stephenson <p.w.stephenson@ntlworld.com> + + * Jun T: 31902: rationalise gamma function in mathfunc for + consistency with various libraries and user expectations. + 2013-10-25 Peter Stephenson <p.w.stephenson@ntlworld.com> * 31890 (with Mikael's fixes in 31891): NEWS: add descriptions diff --git a/Doc/Zsh/mod_mathfunc.yo b/Doc/Zsh/mod_mathfunc.yo index dda4f36fd..5239da5f8 100644 --- a/Doc/Zsh/mod_mathfunc.yo +++ b/Doc/Zsh/mod_mathfunc.yo @@ -33,7 +33,7 @@ returns an integer. The function tt(signgam) takes no arguments, and returns an integer, which is the C variable of the same name, as described in manref(gamma)(3). Note that it is therefore only useful immediately after a call to tt(gamma) or -tt(lgamma). Note also that `tt(signgam+LPAR()RPAR)' and `tt(signgam)' are +tt(lgamma). Note also that `tt(signgam+LPAR()RPAR())' and `tt(signgam)' are distinct expressions. The following functions take two floating point arguments: tt(copysign), diff --git a/Src/Modules/mathfunc.c b/Src/Modules/mathfunc.c index 04483b555..efadd86ff 100644 --- a/Src/Modules/mathfunc.c +++ b/Src/Modules/mathfunc.c @@ -340,7 +340,16 @@ math_func(char *name, int argc, mnumber *argv, int id) break; case MF_GAMMA: +#ifdef HAVE_TGAMMA + retd = tgamma(argd); +#else +#ifdef HAVE_SIGNGAM + retd = lgamma(argd); + retd = signgam*exp(retd); +#else /*XXX assume gamma(x) returns Gamma(x), not log(|Gamma(x)|) */ retd = gamma(argd); +#endif +#endif break; case MF_HYPOT: diff --git a/Test/V03mathfunc.ztst b/Test/V03mathfunc.ztst index 069059da4..ab383db43 100644 --- a/Test/V03mathfunc.ztst +++ b/Test/V03mathfunc.ztst @@ -136,3 +136,9 @@ F:This test fails if your math library doesn't have erand48(). done (( ok )) 0:Test random number generator distributions are not grossly broken + + float -F 5 g l + (( g = gamma(2), l = lgamma(2) )) + print $g, $l +0:Test Gamma function gamma and lgamma +>1.00000, 0.00000 diff --git a/configure.ac b/configure.ac index c3debd8ad..c3093f20d 100644 --- a/configure.ac +++ b/configure.ac @@ -1222,7 +1222,7 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \ getrlimit getrusage \ setlocale \ uname \ - signgam \ + signgam tgamma \ putenv getenv setenv unsetenv xw\ brk sbrk \ pathconf sysconf \ |