Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.utility

Class EM_COMPLEX


Direct ancestors

DOUBLE_MATH

Creation

Features

Invariants

indexing

description

Simple implementation of complex numbers using double values.

date

$Date: 2005/10/23 10:36:32 $

revision

$Revision: 1.7 $

class

EM_COMPLEX

inherit

DOUBLE_MATH
MATH_CONST

create

make (a_real_part, an_imaginary_part: DOUBLE)

-- creates a complex number

ensure
real_part_set: real = a_real_part
imaginary_part_set: imaginary = an_imaginary_part
make_from_polar (a_radius, an_angle: DOUBLE)

-- creates a complex number from the given arguments

feature -- Access

arc_cosine (v: DOUBLE): DOUBLE

-- Trigonometric arccosine of radian v
-- in the range [0, pi]

-- (From DOUBLE_MATH)

arc_sine (v: DOUBLE): DOUBLE

-- Trigonometric arcsine of radian v
-- in the range [-pi/2, +pi/2]

-- (From DOUBLE_MATH)

arc_tangent (v: DOUBLE): DOUBLE

-- Trigonometric arctangent of radian v
-- in the range [-pi/2, +pi/2]

-- (From DOUBLE_MATH)

ceiling (v: DOUBLE): DOUBLE

-- Least integral greater than or equal to v

-- (From DOUBLE_MATH)

cosine (v: DOUBLE): DOUBLE

-- Trigonometric cosine of radian v approximated
-- in the range [-pi/4, +pi/4]

-- (From DOUBLE_MATH)

dabs (v: DOUBLE): DOUBLE

-- Absolute of v

-- (From DOUBLE_MATH)

exp (x: DOUBLE): DOUBLE

-- Exponential of v.

-- (From DOUBLE_MATH)

floor (v: DOUBLE): DOUBLE

-- Greatest integral less than or equal to v

-- (From DOUBLE_MATH)

imaginary: DOUBLE

-- imaginary part of the complex number

log (v: DOUBLE): DOUBLE

-- Natural logarithm of v

-- (From DOUBLE_MATH)

log10 (v: DOUBLE): DOUBLE

-- Base 10 logarithm of v

-- (From DOUBLE_MATH)

log_2 (v: DOUBLE): DOUBLE

-- Base 2 logarithm of v

-- (From DOUBLE_MATH)

real: DOUBLE

-- real part of the complex number

sine (v: DOUBLE): DOUBLE

-- Trigonometric sine of radian v approximated
-- in range [-pi/4, +pi/4]

-- (From DOUBLE_MATH)

sqrt (v: DOUBLE): DOUBLE

-- Square root of v

-- (From DOUBLE_MATH)

tangent (v: DOUBLE): DOUBLE

-- Trigonometric tangent of radian v approximated
-- in range [-pi/4, +pi/4]

-- (From DOUBLE_MATH)

feature -- Element change

conjugate

-- conjugates current

ensure
conugated: imaginary = - (old imaginary)

feature -- Creation

make (a_real_part, an_imaginary_part: DOUBLE)

-- creates a complex number

ensure
real_part_set: real = a_real_part
imaginary_part_set: imaginary = an_imaginary_part
make_from_polar (a_radius, an_angle: DOUBLE)

-- creates a complex number from the given arguments

feature -- Calculations

abs: DOUBLE

-- length of Current.

ensure
result_calculated: Result >= sqrt (real*real + imaginary*imaginary) - epsilon and Result <= sqrt (real*real + imaginary*imaginary) + epsilon
abs_squared: DOUBLE

-- squared length of Current.

ensure
result_calculated: Result >= (real*real + imaginary*imaginary) - epsilon and Result <= (real*real + imaginary*imaginary) + epsilon
arg: DOUBLE

-- returns the angle of the complex number in the complex plane (Argand diagram).

ensure
result_in_range: Result >= 0 and Result < 2*pi
conjugated: like Current

-- also see conjugate

ensure
result_calculated: result.real = real and Result.imaginary = -imaginary
divided_by (other: DOUBLE): like Current

-- division with other

require
other_not_zero: other /= 0
infix "*" (other: like current): like Current

-- multiplication with other

require
other_not_void: other /= Void
infix "+" (other: like Current): like Current

-- Sum with other (commutative).

require
other_not_void: other /= Void
infix "-" (other: like Current): like Current

-- Result of subtracting other

require
other_not_void: other /= Void
infix "/" (other: like current): like Current

-- Scalar division by a_divisor.

require
other_not_void: other /= Void
length_not_zero: other.length_squared /= 0
length: DOUBLE

-- length of Current.

ensure
result_calculated: Result >= sqrt (real*real + imaginary*imaginary) - epsilon and Result <= sqrt (real*real + imaginary*imaginary) + epsilon
length_squared: DOUBLE

-- squared length of Current.

ensure
result_calculated: Result >= (real*real + imaginary*imaginary) - epsilon and Result <= (real*real + imaginary*imaginary) + epsilon
multiplicative_inverse: like Current

-- returns the multiplicative inverse of current. (1/Current)

require
length_not_zero: length_squared /= 0
prefix "+": like Current

-- Unary plus

ensure
result_is_same: Result.real = real and Result.imaginary = imaginary
prefix "-": like Current

-- Unary minus

ensure
result_is_negation: Result.real = -real and Result.imaginary = -imaginary
times (other: DOUBLE): like Current

-- multiplication with other

feature -- Output

out: STRING

-- Textual representation

-- (From ANY)

to_vector_2d: EM_VECTOR_2D

-- returns a vector

invariant

-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

end