NAME

Sidef::Types::Number::Complex - Complex number support for Sidef

DESCRIPTION

This class implements support for complex numbers in Sidef. It inherits from Sidef::Types::Number::Number.

Complex numbers are typically created using the imaginary unit i, or by explicitly calling the constructor.

SYNOPSIS

var z = 3+4i
say z.class         # Number

var a = 1+2i
var b = 1-2i

say (a + b)         # 2
say (a - b)         # 4i
say (a * b)         # 5
say (a / b)         # -0.6 + 0.8i

say z.real          # 3
say z.imag          # 4
say z.abs           # 5

INHERITANCE

Sidef::Types::Number::Complex
isa Sidef::Types::Number::Number
isa Sidef::Object::Object

METHODS

new

Complex(real, imag)

Creates a new Complex object with the given real part real and imaginary part imag.

real

z.real
z.re

Returns the real part of the complex number.

imag

z.imag
z.im

Returns the imaginary part of the complex number.

parts

z.parts

Returns a list containing the real part and the imaginary part.

var z = 3+4i
var (r, i) = z.parts    # (3, 4)

abs

z.abs
z.mag

Returns the absolute value (magnitude) of the complex number ($|z| = \sqrt{a^2 + b^2}$).

arg

z.arg
z.angle
z.phase

Returns the argument (phase angle) of the complex number in radians.

conj

z.conj

Returns the complex conjugate of the number ($\bar{z} = a - bi$).

inv

z.inv

Returns the multiplicative inverse (reciprocal) of the complex number ($1/z$).

neg

z.neg
-z

Returns the negation of the complex number.

sign

z.sign

Returns the complex sign (signum) of the number ($z / |z|$), or 0 if $z$ is 0.

sqr

z.sqr

Returns the square of the complex number ($z^2$).

sqrt

z.sqrt

Returns the principal square root of the complex number.

exp

z.exp

Returns the exponential of the complex number ($e^z$).

log

z.log

Returns the natural logarithm of the complex number.

sin

z.sin

Returns the sine of the complex number.

cos

z.cos

Returns the cosine of the complex number.

tan

z.tan

Returns the tangent of the complex number.

asin

z.asin

Returns the arc sine of the complex number.

acos

z.acos

Returns the arc cosine of the complex number.

atan

z.atan

Returns the arc tangent of the complex number.

sinh

z.sinh

Returns the hyperbolic sine of the complex number.

cosh

z.cosh

Returns the hyperbolic cosine of the complex number.

tanh

z.tanh

Returns the hyperbolic tangent of the complex number.

asinh

z.asinh

Returns the inverse hyperbolic sine of the complex number.

acosh

z.acosh

Returns the inverse hyperbolic cosine of the complex number.

atanh

z.atanh

Returns the inverse hyperbolic tangent of the complex number.

is_real

z.is_real

Returns true if the imaginary part is zero.

is_imag

z.is_imag

Returns true if the real part is zero.

is_zero

z.is_zero

Returns true if the complex number is equal to zero.

is_one

z.is_one

Returns true if the complex number is equal to one.

to_s

z.to_s

Returns the string representation of the complex number (e.g., "3+4i").

dump

z.dump

Returns a string representation of the object for debugging purposes.

OPERATORS

The following operators are overloaded for Sidef::Types::Number::Complex:

  • + (Addition)

  • - (Subtraction)

  • * (Multiplication)

  • / (Division)

  • ** (Exponentiation)

  • <=> (Comparison)

AUTHOR

Daniel "Trizen" Șuteu, <trizen@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2013-2025 by Daniel "Trizen" Șuteu

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.26.1 or, at your option, any later version of Perl 5 you may have available.