Package-level declarations

Types

Link copied to clipboard
data class Complex(val re: Double, val im: Double = 0.0)

Class representing a complex number (re + imj), where j == sqrt(-1). Yes, j, not i, because I'm an electrical engineer, and 'i' stands for current (Ohm's Law: V = IR).

Properties

Link copied to clipboard
const val NUL: Char = '\u0000'

Functions

Link copied to clipboard

Sample code to show in KDoc.

Link copied to clipboard
fun Double.close(other: Double, epsilon: Double = Complex.EPSILON): Boolean

Just like Complex.close; returns true if a Double is within epsilon of another.

Link copied to clipboard
operator fun Number.div(other: Complex): Complex

Expands the receiver to Complex and divides it by other

Link copied to clipboard

Sample code to show in KDoc.

Link copied to clipboard
fun expITheta(theta: Double): Complex

Turns the (radian) angle theta into the complex number at that angle, with unit magnitude. Thanks to Leonhard Euler for discovering this property: e^(jθ) = cos θ + j sin θ

Link copied to clipboard
fun Double.fmt(char: Char = NUL): String

Format a double, optionally with another char (like i or j). If char is the default NUL (ASCII 0), it is not part of the result string.

Link copied to clipboard

Creates a "pure imaginary" number from receiver * sqrt(-1).

Link copied to clipboard
fun main()
Link copied to clipboard
operator fun Number.minus(other: Complex): Complex

Expands the receiver to Complex and subtracts other from it.

Link copied to clipboard
operator fun Number.plus(other: Complex): Complex

Expands the receiver to Complex and adds other to it.

Link copied to clipboard
fun Double.round(decimals: Int): Double

Round to decimals places. If decimals is negative, rounds to the desired power of 10; so round(-2) will round to the nearest hundred.

Link copied to clipboard

Returns the square of the receiver.

Link copied to clipboard

Takes the square root, as a Complex number. Works just fine with negative real numbers. Does not interfere with Double.sqrt(x: Double), since the signature is different.

Link copied to clipboard
operator fun Number.times(other: Complex): Complex

Expands the receiver to Complex and multiplies it by other

Link copied to clipboard

Creates a "pure real" Complex number from the receiver