iyi

Standard library, 0.18.0

std/complex

import std/complex to use it. Source: src/std/complex.iyi at v0.18.0.

Complexstruct

std/complexiyi doc src/std/complex.iyi
pub struct Complex
  def *(other : Complex) : Complex
  def *(other : ::Number) : Complex
  def +(other : Complex) : Complex
  def +(other : ::Number) : Complex
  def + : Complex
  def -(other : Complex) : Complex
  def -(other : ::Number) : Complex
  def - : Complex
  # Smith's scaled quotient, as the other library divides: through
  # `abs2`, a divisor past 1e154 squared to infinity and gave 0, and one
  # under 1e-162 squared to 0 and panicked "Division by zero". A zero
  # divisor answers what a float quotient does, infinities and NaN.
  def /(other : Complex) : Complex
  # A zero divisor is a float quotient's infinities and NaN, not a panic.
  def /(other : ::Number) : Complex
  def ==(other : Complex) : ::Bool
  def ==(other : ::Number) : ::Bool
  def abs : Float64
  def abs2 : Float64
  def self.additive_identity : Complex
  def clone : Complex
  # Negated, not subtracted from 0.0: `0.0 - 0.0` is `+0.0`, so the
  # conjugate of `-1 + 0i` sat above the branch cut and its log was `+pi i`.
  def conj : Complex
  # A real exponent keeps its imaginary zero: `r * sin(0.0)` was NaN once
  # `r` overflowed, so e^710 and e^Infinity were `Infinity + NaNi`.
  def exp : Complex
  # The parts' own hashes, the imaginary one left out when it is zero as
  # the other library does, so `Complex.new(x, 0)` hashes as `x`, which it
  # equals. `to_i64` of a part panicked "arithmetic overflow" past 2^63 or
  # at NaN and infinity, and `to_i32` of that past 2^31.
  def hash : Int32
  def imag : Float64
  def initialize(real : ::Number, imag : ::Number = 0)
  def inspect(io : IyiIO) : ::Nil
  def inspect : String
  # `conj / abs2`, as the other library inverts, wherever `abs2` is a
  # normal float; past that it overflowed or underflowed, and the inverse
  # of 1e-170 was `Infinity + NaNi` and of 1e170 `0.0 - 0.0i`. There the
  # conjugate is scaled as the division scales it (Smith's), which keeps
  # its zeros' signs.
  def inv : Complex
  def log : Complex
  def self.multiplicative_identity : Complex
  def self.new(c : Complex) : Complex
  def phase : Float64
  def polar : ::Tuple(Float64, Float64)
  def real : Float64
  def round(digits : Int32 = 0) : Complex
  # The other library's cases, one by one: dividing by `abs` answered NaN
  # for an infinite part, 0 once `abs` overflowed (both parts 1.5e308),
  # and a magnitude of 1.414 for two subnormal parts, whose `abs` rounds.
  def sign : Complex
  # A part past an eighth of `Float64::MAX` is rooted a sixteenth of the
  # way down and the root doubled twice: `2.0 * (r + @real)` overflowed,
  # and the root of 1e308 + 1e308i was `Infinity + 0.0i`. A power of two
  # scales each step exactly, so the root is the one the steps would
  # answer had they not overflowed.
  def sqrt : Complex
  def to_c : Complex
  def to_f : Float64
  def to_f32 : Float32
  def to_f64 : Float64
  def to_i32 : Int32
  def to_i64 : Int64
  def to_s(io : IyiIO) : ::Nil
  # The joiner is the imaginary part's sign bit and its magnitude follows,
  # as the other library prints: comparing `>= 0.0` printed `1.0 + -0.0i`
  # for a negative zero and `1.0 - NaNi` for NaN.
  def to_s : String
  def self.zero : Complex
  def zero? : ::Bool
end

Numberstruct, reopened

std/complexiyi doc src/std/complex.iyi
struct ::Number
  def *(other : Std::Complex::Complex) : Std::Complex::Complex
  def +(other : Std::Complex::Complex) : Std::Complex::Complex
  def -(other : Std::Complex::Complex) : Std::Complex::Complex
  # Times the inverse, as the other library divides a number by a complex:
  # dividing `Complex.new(self, 0)` rounded otherwise, and panicked
  # "Division by zero" once the divisor's `abs2` underflowed to 0.
  def /(other : Std::Complex::Complex) : Std::Complex::Complex
  # `1.0 == Complex.new(1, 0)` was false while the reverse was true.
  def ==(other : Std::Complex::Complex) : ::Bool
  # Spelled in full: this file's import of `Math` does not reach the
  # reopened `::Number`, so `0.5.cis` failed to compile ("undefined
  # constant Math") unless the caller had imported `Math` itself.
  def cis : Std::Complex::Complex
  def i : Std::Complex::Complex
  def to_c : Std::Complex::Complex
end