Perl already links to libm
.
$ ldd $(which perl)
...
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd8ce2ea000)
...
So if Perl already links to libm
, why aren't often used features like ceil
, floor
, and pow
provided as CORE::GLOBAL
s or provided in another namespace? Why does perldoc -q ceil
point to POSIX.pm
as a source for this function, and why does Math::Libm
even exist?
Python also links to libm
which is exposed to the user when you run import math
with the symbols available in the module math
and can be referenced from outside like math.ceil(num)
Perl does have maths functions built in: just its idea of the functions you might need are on par with a 1970s minicomputer. There are all the ones I could find:
resulting in:
Note that instead of a
pow()
function, Perl has the**
operator, just like FORTRAN does. You don't get atan()
function, because that'ssin($x)/cos($x)
. If you need other transcendental functions, that's why they put the trigonometric functions table (PDF, p.39) in all good programming books.I can't recall ever using or needing
ceil()
orfloor()
myself, but Perl missingsgn()
as a builtin gets me every time. Since Perl is a typeless scripting language at heart, numeric gardening tasks like rounding can already be done with string functions such assprintf "%.f", $val
.