Packages

case class Complex(re: Double, im: Double = 0) extends Product with Serializable

A class which represents a complex number, that is, a number in the form a + bi, where i is one of the two square roots of -1.

a is called the real part, and b is called the imaginary part.

re

The real part

im

The imaginary part

Source
Complex.scala
Linear Supertypes
Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Complex
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Complex(re: Double, im: Double = 0)

    re

    The real part

    im

    The imaginary part

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def *(that: Complex): Complex

    Multiplies this complex number by another one and returns the result.

    Multiplies this complex number by another one and returns the result.

    This implements the formula:

    (a + bi) * (c + di) = (ac - bd) + (ad + bc)
    that

    The complex number to be multiplied with this one

    returns

    this * that

  4. def +(that: Complex): Complex

    Adds this complex number to another one and returns the result.

    Adds this complex number to another one and returns the result.

    This implements the formula:

    (a + bi) + (c + di) = (a + c) + (b + d)i
    that

    The complex number to be added to this one

    returns

    this + that

  5. def -(that: Complex): Complex

    Subtracts another complex number from this one and returns the result.

    Subtracts another complex number from this one and returns the result.

    This implements the formula:

    (a + bi) - (c + di) = (a - c) + (b - d)i
    that

    The complex number to be subtracted from this one

    returns

    this - that

  6. def /(that: Complex): Complex

    Divides this complex number by another one and returns the result.

    Divides this complex number by another one and returns the result.

    This implements the formula:

    (a + bi) / (c + di) = (a + bi)(c - di) / (c^2 + d^2)

    The divisor is then a real number, and thus it is easy to compute the result when the nominator is divided by it.

    If the divisor is 0, the result will be NaN + NaNi.

    that

    The complex number by which this one is to be divided

    returns

    this / that

  7. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def abs: Double

    Calculates the absolute value of this complex number, also known as the modulus, and returns it.

    Calculates the absolute value of this complex number, also known as the modulus, and returns it. The absolute is the distance between a point on the complex plane representing the number and the origin.

    This implements the formula:

    |a + bi| = √(a^2 + b^2)

    where |z| denotes the absolute of z.

    If either the real part of the imaginary part, or both, are infinite, the result will be positive infinity.

    returns

    The absolute

  9. def acos: Complex

    Returns the principal inverse cosine of this number, that is, the number whose cosine this is.

    Returns the principal inverse cosine of this number, that is, the number whose cosine this is.

    This implements the formula:

    acos(z) = 1/2 * π - asin(z)
    returns

    cos-1(this)

  10. def acosh: Complex

    Returns the principal inverse hyperbolic cosine of this number, that is, the number whose hyperbolic cosine this is.

    Returns the principal inverse hyperbolic cosine of this number, that is, the number whose hyperbolic cosine this is.

    This implements the formula:

    acosh(z) = log(z + √(z + 1) * √(z - 1))
    returns

    cosh-1(this)

  11. def arg: Double

    Calculates the argument, that is, the angle between the positive real axis and the point representing this number on the complex plane.

    Calculates the argument, that is, the angle between the positive real axis and the point representing this number on the complex plane. The result will be between π and .

    NaN and infinite values are handled by math.atan2(Double, Double).

    returns

    The argument

  12. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  13. def asin: Complex

    Returns the principal inverse sine of this number, that is, the number whose sine this is.

    Returns the principal inverse sine of this number, that is, the number whose sine this is.

    This implements the formula:

    asin(z) = -i * log(iz + √(1 - z^2))
    returns

    sin-1(this)

  14. def asinh: Complex

    Returns the principal inverse hyperbolic sine of this number, that is, the number whose hyperbolic sine this is.

    Returns the principal inverse hyperbolic sine of this number, that is, the number whose hyperbolic sine this is.

    This implements the formula:

    asinh(z) = -i * asin(iz)
    returns

    sinh-1(this)

  15. def atan: Complex

    Returns the principal inverse tangent of this number, that is, the number whose tangent this is.

    Returns the principal inverse tangent of this number, that is, the number whose tangent this is.

    This implements the formula:

    atan(z) = i(log(1 - iz) - log(1 + iz)) / 2
    returns

    tan-1(this)

  16. def atanh: Complex

    Returns the principal inverse hyperbolic tangent of this number, that is, the number whose hyperbolic tangent this is.

    Returns the principal inverse hyperbolic tangent of this number, that is, the number whose hyperbolic tangent this is.

    This implements the formula:

    atanh(z) = -i * atan(iz)
    returns

    tanh-1(this)

  17. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. def conj: Complex

    Returns the complex conjugate of this number, that is, a complex number with the same real part but with the imaginary part negated.

    Returns the complex conjugate of this number, that is, a complex number with the same real part but with the imaginary part negated.

    The conjugate of a + bi, therefore, is a - bi

    returns

    The complex conjugate

  19. def cos: Complex

    Returns the cosine of this number.

    Returns the cosine of this number.

    This implements the formula:

    cos(z) = (e^(iz) + e^(-iz)) / 2
    returns

    cos(this)

  20. def cosh: Complex

    Returns the hyperbolic cosine of this number.

    Returns the hyperbolic cosine of this number.

    This implements the formula:

    cosh(z) = cos(iz)
    returns

    cosh(this)

  21. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  22. def exp: Complex

    Calculates e to the power of this complex number and returns the result.

    Calculates e to the power of this complex number and returns the result.

    This implements the formula:

    e ^ (a + bi) = (e ^ a) * (cos(b) + i * sin(b)
    returns

    ethis

  23. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  24. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  25. def hasNaNPart: Boolean

    Whether either the real part or the imaginary part of this complex number is NaN.

    Whether either the real part or the imaginary part of this complex number is NaN.

    returns

    re.isNaN || im.isNaN

  26. val im: Double
  27. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  28. def log: Complex

    Calculates the principle natural logarithm of this number.

    Calculates the principle natural logarithm of this number. Although numbers have infinitely many logarithms, separated from each-other by 2πi, this will only return the one with its imaginary part in the range [-π, π].

    If the input is 0, the result will be negative infinity.

    returns

    logₑ(this)

  29. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  30. final def notify(): Unit
    Definition Classes
    AnyRef
  31. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  32. def pow(that: Complex): Complex

    Raises this number to the power of another and returns the result.

    Raises this number to the power of another and returns the result.

    This implements the formula:

    a ^ b = e ^ (b * logₑ(a))

    When this number is 0, then:

    • if the real part of the exponent is greater than 0, then the result will be 0
    • otherwise, the result will be NaN.

    Note that this is a multivalued function, so there would be multiple possible results in reality. This will return the principle value, as determined by the principle value of logₑ(a).

    that

    The exponent

    returns

    thisthat

  33. val re: Double
  34. def round(implicit precision: Int = 8): Complex

    Rounds this complex number to the given number of significant figures and returns the result.

    Rounds this complex number to the given number of significant figures and returns the result.

    precision

    The number of significant figures to round to

    returns

    The rounded complex number

  35. def sin: Complex

    Returns the sine of this number.

    Returns the sine of this number.

    This implements the formula:

    sin(z) = i(e^(-iz) - e^(iz)) / 2
    returns

    sin(this)

  36. def sinh: Complex

    Returns the hyperbolic sine of this number.

    Returns the hyperbolic sine of this number.

    This implements the formula:

    sinh(z) = -i * sin(iz)
    returns

    sinh(this)

  37. def sqrt: Complex

    Returns the square root of this number, as given by pow(0.5).

    Returns the square root of this number, as given by pow(0.5).

    Every number apart from 0 has two square roots. The other square root will be the negative of this one. The returned square root will be the one whose real part is positive.

    returns

    √this

  38. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  39. def tan: Complex

    Returns the tangent of this number.

    Returns the tangent of this number.

    This implements the formula:

    tan(z) = i(1 - e^(2iz)) / (e^(2iz) + 1)

    This will return NaN where the tan function is undefined, which is where:

    e^(2iz) + 1 = 0
    returns

    tan(this)

  40. def tanh: Complex

    Returns the hyperbolic tangent of this number.

    Returns the hyperbolic tangent of this number.

    This implements the formula:

    tanh(z) = -i * tan(iz)
    returns

    tanh(this)

  41. def toString(): String

    Returns a string representation of this complex number as it would be written mathematically.

    Returns a string representation of this complex number as it would be written mathematically.

    For example, the string representation of Complex(1, -2) is 1 - 2i, and the string representation of Complex(0, -1) is -i.

    returns

    A string representation of this complex number

    Definition Classes
    Complex → AnyRef → Any
  42. def unary_-: Complex

    Calculates and returns the negative of this complex number.

    Calculates and returns the negative of this complex number.

    This implements the formula:

    -(a + bi) = -a - bi
    returns

    -a - bi

  43. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  44. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  45. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  46. def ~^(that: Complex): Complex

    Raises this number to the power of another and returns the result.

    Raises this number to the power of another and returns the result.

    This implements the formula:

    a ^ b = e ^ (b * logₑ(a))

    When this number is 0, then:

    • if the real part of the exponent is greater than 0, then the result will be 0
    • otherwise, the result will be NaN.

    Note that this is a multivalued function, so there would be multiple possible results in reality. This will return the principle value, as determined by the principle value of logₑ(a).

    that

    The exponent

    returns

    thisthat

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped