Import std.math.big.complex
std.math.big.complex
Complex numbers, as two Doubles.
Complex: a complex number, Real + Imaginary times i, as two Doubles, and worked out as Python's cmath does: Arg is from -pi to pi, and Log, Sqrt, and Pow give the principal value, scaled near the largest Doubles and among the subnormals as cmath scales them, with C99's values at infinities. Like a Double's, its arithmetic never panics, and what has no value, like dividing by 0, has NaN parts. A Double on either side of an operator works too.
std/math/big/complex.fb
Types
Complex
struct
Public Struct Complex Implements Equatable, Hashable, Printable, Numeric, Defaultable
A complex number, of a real and an imaginary part, each a Double.
Examples
Local i = Complex(0, 1)
Expect(i * i == Complex(-1, 0))
Expect(Complex(3, 4).Abs() == 5.0)
Expect(Complex(3, 4).Conjugate() == Complex(3, -4))
Expect(Complex(-4, 0).Sqrt() == Complex(0, 2))std/math/big/complex.fb, line 44
-
Its real part.
-
Its imaginary part.
-
The zero Complex, 0 + 0i, which adding leaves alone.
-
The Complex 1 + 0i, which multiplying leaves alone.
-
The zero Complex, 0 + 0i.
-
The number of the
magnitude, at theanglein radians from the positive real axis, as cmath.rect gives it: an angle of 0 has a Real part of themagnitude, even an infinite one. -
"1+2i", "0-1.5i", or "-3+0i", the Imaginary part's sign always shown.
-
Its distance from 0.
-
Its angle from the positive real axis, from -pi to pi.
-
The same number with its imaginary part negated.
-
e to its power. A real number's is real, and one that a Double holds isn't infinite on the way, as e to past 709 would be.
-
Its natural logarithm: the log of its magnitude, and its Arg. Near a magnitude of 1, the log comes from log1p, which keeps the digits that log would lose; past a quarter of the largest Double, from half of it; and among the subnormals, from it scaled up by 2^53.
-
Its square root with a Real part 0 or more, and the Imaginary part's sign, scaled as cmath scales it, so the largest and the subnormal numbers keep their digits.
-
It to the power: anything to 0 is 1, and 0 to a power with a Real part above 0 and no Imaginary part is 0, but to any other power has NaN parts.
-
Whether
aandbhave equal real and imaginary parts. -
Whether
aandbare equal. -
Whether
aandbare equal. -
A hash of its two parts, which Complexes that are equal share.
-
aplusb. -
aplusb. -
aplusb. -
aminusb. -
aminusb. -
aminusb. -
atimesb. -
atimesb. -
atimesb. -
Smith's division, which scales by the larger part of
b, so no product overflows on the way. -
adivided byb. -
adivided byb. -
To a whole power, by squaring, which can be below 0.
-
anegated.
Report an issue with this page or with FutureBlitz on GitHub.