PDL::Math#
📦 stdpdl
PDL’s mathematical functions: trigonometric and hyperbolic, rounding, error and Bessel functions, log gamma, complex square roots, logarithms and inverses, and polynomials.
use PDL;
print floor(pdl(1.5, -1.5)), " ", ceil(pdl(1.5, -1.5)), " ", rint(pdl(0.5, 1.5, 2.5)), "\n"; # [1 -2] [2 -1] [0 2 2]
printf "%.4f %.4f %.4f\n", asin(pdl(1)), tanh(pdl(1)), erf(pdl(1)); # 1.5708 0.7616 0.8427
print isfinite(pdl(1, 9**9**9, -9**9**9)), "\n"; # [1 0 0]
my ($lg, $sign) = lgamma(pdl(5));
print "$lg $sign ", pow(byte(2), 3), "\n"; # 3.17805383034795 1 8
print clog(czip(0, 1)), "\n"; # 1.57079637050629i
Each function works element by element and broadcasts; most work in place ($x->inplace->floor). sin, cos, exp, log and sqrt are PDL::Ops’s, as upstream has them. The c... functions take real input as complex, so csqrt(-4) is 2i where sqrt(-4) is NaN.
This is PDL::Math of PDL 2.106. The kernels are PDL’s own, through pperl’s engine; polyroots (the roots of a polynomial), polyfromroots (its coefficients from the roots) and polyval (its value at a point), all with coefficients in decreasing powers, are upstream’s Perl unchanged.