43275: Add log2 to match func

This commit is contained in:
dana 2018-08-12 03:20:37 -05:00 committed by Peter Stephenson
parent 99fd8c0fe9
commit b21a641d4c
5 changed files with 25 additions and 3 deletions

View file

@ -1,3 +1,8 @@
2018-08-13 Peter Stephenson <p.stephenson@samsung.com>
* dana: 43275: Doc/Zsh/mod_mathfunc.yo, Src/Modules/mathfunc.c,
Test/V03mathfunc.ztst, configure.ac: Add log2 to mathfunc.
2018-08-12 Marc Cornellà <marc.cornella@live.com>
* unposted (PR #26): Completion/Unix/Command/_git: __git_files:

View file

@ -24,9 +24,9 @@ The following functions take a single floating point argument: tt(acos),
tt(acosh), tt(asin), tt(asinh), tt(atan), tt(atanh), tt(cbrt), tt(ceil),
tt(cos), tt(cosh), tt(erf), tt(erfc), tt(exp), tt(expm1), tt(fabs),
tt(floor), tt(gamma), tt(j0), tt(j1), tt(lgamma), tt(log), tt(log10),
tt(log1p), tt(logb), tt(sin), tt(sinh), tt(sqrt), tt(tan), tt(tanh),
tt(y0), tt(y1). The tt(atan) function can optionally take a second
argument, in which case it behaves like the C function tt(atan2).
tt(log1p), tt(log2), tt(logb), tt(sin), tt(sinh), tt(sqrt), tt(tan),
tt(tanh), tt(y0), tt(y1). The tt(atan) function can optionally take a
second argument, in which case it behaves like the C function tt(atan2).
The tt(ilogb) function takes a single floating point argument, but
returns an integer.

View file

@ -65,6 +65,7 @@ MF_LGAMMA,
MF_LOG,
MF_LOG10,
MF_LOG1P,
MF_LOG2,
MF_LOGB,
MF_NEXTAFTER,
MF_RINT,
@ -142,6 +143,7 @@ static struct mathfunc mftab[] = {
NUMMATHFUNC("log", math_func, 1, 1, MF_LOG),
NUMMATHFUNC("log10", math_func, 1, 1, MF_LOG10),
NUMMATHFUNC("log1p", math_func, 1, 1, MF_LOG1P),
NUMMATHFUNC("log2", math_func, 1, 1, MF_LOG2),
NUMMATHFUNC("logb", math_func, 1, 1, MF_LOGB),
NUMMATHFUNC("nextafter", math_func, 2, 2, MF_NEXTAFTER),
#ifdef HAVE_ERAND48
@ -338,6 +340,14 @@ math_func(UNUSED(char *name), int argc, mnumber *argv, int id)
retd = log1p(argd);
break;
case MF_LOG2:
#ifdef HAVE_LOG2
retd = log2(argd);
#else
retd = log(argd) / log(2);
#endif
break;
case MF_LOGB:
retd = logb(argd);
break;

View file

@ -139,3 +139,9 @@ F:This test fails if your math library doesn't have erand48().
print $g, $l
0:Test Gamma function gamma and lgamma
>1.00000, 0.00000
float -F 5 a b c
(( a = log2(0.5), b = log2(1.5), c = log2(99) ))
print -r - "$a, $b, $c"
0:log2
>-1.00000, 0.58496, 6.62936

View file

@ -1266,6 +1266,7 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \
isblank iswblank \
uname \
signgam tgamma \
log2 \
scalbn \
putenv getenv setenv unsetenv xw\
brk sbrk \