Complex

Support for complex numbers is provided by Math::MPC, which is a Perl interface to the MPC library.

Complex(3, 4)

Alternatively:

3 + 4i
3:4

Complex numbers are deeply integrated into the language and can be used in combination with all the other Number types (with implicit propagation):

sqrt(-1)        # 1i
log(-1)         # 3.14159265358979323846264338327950288419716939938i
4 + sqrt(-1)    # 4+i
(3+4i)**2       # -7+24i

All complex numbers are Number objects:

(3 + 4i).class       # Number
Complex(3, 4).class  # =//=

Last updated