Rational and complex numbers
Julia supports these types out of the box. The global constant im represents the square root of -1, so that 3.2 + 7.1im is a complex number with floating point coefficients, so it is of the type Complex{Float64}.
This is the first example of a parametric type in Julia. For this example, we can write this as Complex{T}, where type T can take a number of different type values such as Int32 or Int64.
All operations and elementary functions such as exp(), sqrt(), sinh(), real(), imag(), abs(), and so on are also defined on complex numbers; for example, abs(3.2 + 7.1im) = 7.787810988975015.
If a and b are two variables that contain a number, use complex(a,b) to form a complex number with them. Rational numbers are useful when ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access