imaginary-part ( z -- y ) (original) (raw)

imaginary-part ( z -- y )
Factor handbook » The language » Numbers » Complex numbers

Prev: real-part ( z -- x )
Next: >rect ( z -- x y )

Vocabulary
math

Inputs

z a number

Outputs

y a real

Word description
Outputs the imaginary part of a complex number. This outputs zero for real numbers.

Examples

USING: math prettyprint ; C{ 1 2 } imaginary-part .
2

USING: math prettyprint ; 3 imaginary-part .
0

Definition

IN: math

GENERIC: imaginary-part ( z -- y )

Methods

USING: accessors math ;

M: complex imaginary-part imaginary>> ; inline

USING: kernel math ;

M: real imaginary-part drop 0 ; inline