Classes | Math

# Complex : Number : Magnitude : Object

complex number
Source: Complex.sc

## Description

A class representing complex numbers. Note that this is a simplified representation of a complex number, which does not implement the full mathematical notion of a complex number.

## Class Methods

### Complex.new(real, imag)

Create a new complex number with the given real and imaginary parts.

#### Arguments:

 real the real part imag the imaginary part

#### Returns:

a new instance of Complex.

## Instance Methods

### .real = value

The real part of the number.

### .imag = value

The imaginary part of the number.

### .conjugate

the complex conjugate.

#### Discussion:

Complex subtraction

#### Discussion:

Complex multiplication

#### Discussion:

Complex division.

### .exp

Complex exponentiation with base e.

### .squared

Complex self multiplication.

### .cubed

complex triple self multiplication.

### **(that)

From superclass: Object

### .pow(aNumber)

Complex exponentiation

#### Discussion:

not implemented for all combinations - some are mathematically ambiguous.

the comparison of just the real parts.

#### Discussion:

the comparison assuming that the reals (floats) are fully embedded in the complex numbers

### .neg

negation of both parts

### .reciprocal

the reciprocal of a complex number

### .abs

the absolute value of a complex number is its magnitude.

### .magnitude

distance to the origin.

### .rho

the distance to the origin.

### .theta

the angle in radians.

### .asPoint

Convert to a Point.

### .asPolar

Convert to a Polar

### .asInteger

real part as Integer.

### .asFloat

real part as Float.

returns this

a hash value

### .printOn(stream)

print this on given stream

## Examples

Basic example:

Julia set approximation: