Skip to Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

Math::Complex

use Math::Complex;

$z = Math::Complex->make(5, 6);
$z = cplx(5, 6);         # same thing, but shorter
$t = 4 - 3*i + $z;       # do standard complex math
print "$t\n";            # prints 9+3i

print sqrt(-9), "\n";    # prints 3i

The Math::Complex module provides complex number objects with overloaded operators. These are numbers with both real and imaginary portions, like those satisfying even-numbered integral roots of negative numbers as shown above. Besides arithmetical operators, many built-in math functions are also overridden by versions that understand complex numbers, including abs, log, sqrt, sin, cos, and atan2. Other functions provided are Re and Im to provide the real and imaginary portions of their complex arguments, plus a full battery of extended trigonometric functions, such as tan, asin, acos, sinh, cosh, and tanh. The module also exports the constant i, which, as you might imagine, holds the value of i; that is, the square root of -1.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Perl, 4th Edition

Programming Perl, 4th Edition

Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata