Chapter 5: structural numbers

- the imaginary number is the constant "im"

julia> (1 - 3im) / (2 + 2im)
-0.5 - 1.0im

julia> real(1 + 2im) # real part of z
1

julia> imag(1 + 2im) # imaginary part of z
2

julia> conj(1 + 2im) # complex conjugate of z
1 - 2im

julia> abs(1 + 2im) # absolute value of z
2.23606797749979

julia> abs2(1 + 2im) # squared absolute value
5

julia> angle(1 + 2im) # phase angle in radians
1.

julia> sqrt(-1)
ERROR: DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
[...]

julia> sqrt(-1 + 0im)
0.0 + 1.0im

constructing a complex number at runtime:
julia> a = 1; b = 2; complex(a, b)
1 + 2im


Rationals are constructed using the // operator:

julia> 2//3
2//3

julia> -4//-12
1//3

julia> numerator(2//3)
2

julia> denominator(2//3)
3

julia> float(3//4)
0.75

julia> x = -3//0
-1//0