Complex numbers operations.
Complex numbers are represented using the [[Vec2]] type defined in the fastmath.vector namespace.
A complex number $z = a + bi$ corresponds to the vector (Vec2. a b).
To create a complex number, use complex, [[vec2]], or convert from sequences/arrays using functions like fastmath.vector/seq->vec2.
The implementation correctly handles floating-point special values such as ##Inf, ##NaN, and distinguishes between +0.0 and -0.0 where necessary. Branch cuts follow C99 (Annex G) and the signed zero of the imaginary part selects the side of the cut: the result for x+0.0i is the limit from above, for x-0.0i from below.
This namespace provides standard complex number operations like arithmetic (+, -, *, /), exponentiation (pow, exp, log), trigonometric functions (sin, cos, tan, etc.), and their inverses, as well as utility functions like abs, arg, conjugate, etc.
The functions are accurate over the whole range of doubles: they do not overflow or underflow in intermediate results and do not lose the small component near zero, near the unit circle and near the branch points. The exception are asec, acsc, acot, asech, acsch and acoth, computed from the rounded reciprocal 1/z: close to their branch points they are less accurate (see the functions).
Complex numbers operations. Complex numbers are represented using the [[Vec2]] type defined in the `fastmath.vector` namespace. A complex number $z = a + bi$ corresponds to the vector `(Vec2. a b)`. To create a complex number, use [[complex]], [[vec2]], or convert from sequences/arrays using functions like [[fastmath.vector/seq->vec2]]. The implementation correctly handles floating-point special values such as `##Inf`, `##NaN`, and distinguishes between `+0.0` and `-0.0` where necessary. Branch cuts follow C99 (Annex G) and the signed zero of the imaginary part selects the side of the cut: the result for `x+0.0i` is the limit from above, for `x-0.0i` from below. This namespace provides standard complex number operations like arithmetic (+, -, *, /), exponentiation (pow, exp, log), trigonometric functions (sin, cos, tan, etc.), and their inverses, as well as utility functions like `abs`, `arg`, `conjugate`, etc. The functions are accurate over the whole range of doubles: they do not overflow or underflow in intermediate results and do not lose the small component near zero, near the unit circle and near the branch points. The exception are `asec`, `acsc`, `acot`, `asech`, `acsch` and `acoth`, computed from the rounded reciprocal `1/z`: close to their branch points they are less accurate (see the functions).
(abs z)Calculates the magnitude (absolute value) of the complex number z.
The magnitude is computed without intermediate overflow or underflow, so it is correct for the whole range of doubles (for example 1e200+1e200i or 1e-200+1e-200i). It is Infinity when any part is infinite, also when the other one is NaN.
See also norm (the squared magnitude).
Calculates the magnitude (absolute value) of the complex number `z`. The magnitude is computed without intermediate overflow or underflow, so it is correct for the whole range of doubles (for example `1e200+1e200i` or `1e-200+1e-200i`). It is `Infinity` when any part is infinite, also when the other one is `NaN`. See also [[norm]] (the squared magnitude).
(abs-sq z)Squared magnitude of z, alias of norm.
Squared magnitude of `z`, alias of [[norm]].
(acos z)Inverse cosine, the principal value.
The real part is in [0, pi], the imaginary part has the sign opposite to b. Branch cuts are the real axis for |a|>1; the sign of a zero imaginary part selects the side. Accurate near 1, -1 and for large arguments (Hull, Fairgrieve, Tang).
Inverse cosine, the principal value. The real part is in `[0, pi]`, the imaginary part has the sign opposite to `b`. Branch cuts are the real axis for `|a|>1`; the sign of a zero imaginary part selects the side. Accurate near `1`, `-1` and for large arguments (Hull, Fairgrieve, Tang). See also [[cos]], [[asin]], [[acosh]].
(acosh z)Inverse hyperbolic cosine, the principal value, acosh(z) = +-i acos(z).
The real part is not negative, the imaginary part is in [-pi, pi] and has the sign of b. The branch cut is the real axis for a<1; the sign of a zero imaginary part selects the side.
Inverse hyperbolic cosine, the principal value, `acosh(z) = +-i acos(z)`. The real part is not negative, the imaginary part is in `[-pi, pi]` and has the sign of `b`. The branch cut is the real axis for `a<1`; the sign of a zero imaginary part selects the side. See also [[cosh]], [[acos]], [[asinh]].
(acot z)Inverse cotangent, the principal value, acot(z) = atan(1/z).
The real part is in [-pi/2, pi/2] and it is odd, acot(-x) = -acot(x) (the other common definition, pi/2 - atan(z), differs on the negative real axis and on the cut). Branch cut: the segment of the imaginary axis between -i and i. Computed from 1/z, which is rounded: close to the branch points +-i the relative error grows (about eps/distance; 3e-7 at the distance 2e-11). Away from them it is a few ulps.
Inverse cotangent, the principal value, `acot(z) = atan(1/z)`. The real part is in `[-pi/2, pi/2]` and it is odd, `acot(-x) = -acot(x)` (the other common definition, `pi/2 - atan(z)`, differs on the negative real axis and on the cut). Branch cut: the segment of the imaginary axis between `-i` and `i`. Computed from `1/z`, which is rounded: close to the branch points `+-i` the relative error grows (about `eps/distance`; 3e-7 at the distance 2e-11). Away from them it is a few ulps. See also [[cot]], [[atan]].
(acoth z)Inverse hyperbolic cotangent, the principal value, acoth(z) = atanh(1/z).
Branch cut: the segment of the real axis between -1 and 1. acoth(+-1) is +-Infinity. Computed from 1/z, which is rounded: close to the branch points +-1 the relative error grows (about eps/distance; 1e-6 at the distance 3e-12). Away from them it is a few ulps.
Inverse hyperbolic cotangent, the principal value, `acoth(z) = atanh(1/z)`. Branch cut: the segment of the real axis between `-1` and `1`. `acoth(+-1)` is `+-Infinity`. Computed from `1/z`, which is rounded: close to the branch points `+-1` the relative error grows (about `eps/distance`; 1e-6 at the distance 3e-12). Away from them it is a few ulps. See also [[coth]], [[atanh]].
(acsc z)Inverse cosecant, the principal value, acsc(z) = asin(1/z).
Branch cuts follow asin. Computed from 1/z, which is rounded: close to the branch points +-1 the relative error grows (about eps/sqrt(distance); 3e-11 at the distance 3e-12). Away from them it is a few ulps. At zero the value is the limit along the real axis: acsc(0) is pi/2-Infinity*i.
Inverse cosecant, the principal value, `acsc(z) = asin(1/z)`. Branch cuts follow [[asin]]. Computed from `1/z`, which is rounded: close to the branch points `+-1` the relative error grows (about `eps/sqrt(distance)`; 3e-11 at the distance 3e-12). Away from them it is a few ulps. At zero the value is the limit along the real axis: `acsc(0)` is `pi/2-Infinity*i`. See also [[csc]], [[asin]].
(acsch z)Inverse hyperbolic cosecant, the principal value, acsch(z) = asinh(1/z).
Branch cut: the segment of the imaginary axis between -i and i. Computed from 1/z, which is rounded: close to the branch points +-i the relative error grows (about eps/sqrt(distance); 1e-11 at the distance 2e-11). Away from them it is a few ulps. acsch(0) is Infinity-0i (-Infinity-0i for -0; the sign of the zero is the opposite of the sign of the zero imaginary part of z).
Inverse hyperbolic cosecant, the principal value, `acsch(z) = asinh(1/z)`. Branch cut: the segment of the imaginary axis between `-i` and `i`. Computed from `1/z`, which is rounded: close to the branch points `+-i` the relative error grows (about `eps/sqrt(distance)`; 1e-11 at the distance 2e-11). Away from them it is a few ulps. `acsch(0)` is `Infinity-0i` (`-Infinity-0i` for `-0`; the sign of the zero is the opposite of the sign of the zero imaginary part of `z`). See also [[csch]], [[asinh]].
(add)(add z)(add z1 z2)(add z1 z2 & more)Sum of complex numbers.
Without arguments returns 0, with one argument the argument itself. More than two arguments are added from left to right.
Sum of complex numbers. Without arguments returns `0`, with one argument the argument itself. More than two arguments are added from left to right.
(adds z v)Adds the real number v to the complex number z.
Adds the real number `v` to the complex number `z`.
(arg z)Argument (phase angle) of the complex number z, atan2(im, re), in the range [-pi, pi].
The sign of a zero imaginary part is respected: arg(-1-0i) is -pi, arg(-1+0i) is pi.
Argument (phase angle) of the complex number `z`, `atan2(im, re)`, in the range `[-pi, pi]`. The sign of a zero imaginary part is respected: `arg(-1-0i)` is `-pi`, `arg(-1+0i)` is `pi`. See also [[abs]], [[log]].
(asec z)Inverse secant, the principal value, asec(z) = acos(1/z).
Branch cuts follow acos. Computed from 1/z, which is rounded: close to the branch points 1 the relative error grows (about eps/distance; 8e-10 at the distance 1.4e-8). Away from them it is a few ulps. At zero the value is the limit along the real axis: asec(0) is 0+Infinity*i (pi for -0), the sign of the infinite part follows the sign of the zero imaginary part.
Inverse secant, the principal value, `asec(z) = acos(1/z)`. Branch cuts follow [[acos]]. Computed from `1/z`, which is rounded: close to the branch points `1` the relative error grows (about `eps/distance`; 8e-10 at the distance 1.4e-8). Away from them it is a few ulps. At zero the value is the limit along the real axis: `asec(0)` is `0+Infinity*i` (`pi` for `-0`), the sign of the infinite part follows the sign of the zero imaginary part. See also [[sec]], [[acos]].
(asech z)Inverse hyperbolic secant, the principal value, asech(z) = acosh(1/z).
The real part is not negative. Branch cuts are the negative real axis and the real axis for a>1. Computed from 1/z, which is rounded: close to the branch points 1 the relative error grows (about eps/distance; 8e-10 at the distance 1.4e-8). Away from them it is a few ulps. asech(0) is Infinity-0i (Infinity-pi*i for -0; the sign of the imaginary part is the opposite of the sign of the zero imaginary part of z).
Inverse hyperbolic secant, the principal value, `asech(z) = acosh(1/z)`. The real part is not negative. Branch cuts are the negative real axis and the real axis for `a>1`. Computed from `1/z`, which is rounded: close to the branch points `1` the relative error grows (about `eps/distance`; 8e-10 at the distance 1.4e-8). Away from them it is a few ulps. `asech(0)` is `Infinity-0i` (`Infinity-pi*i` for `-0`; the sign of the imaginary part is the opposite of the sign of the zero imaginary part of `z`). See also [[sech]], [[acosh]].
(asin z)Inverse sine, the principal value, asin(z) = -i asinh(iz).
The real part is in [-pi/2, pi/2]. Branch cuts are the real axis for |a|>1; the sign of a zero imaginary part selects the side (asin(2+0i) is pi/2 + 1.317i, asin(2-0i) is pi/2 - 1.317i). Accurate near zero, near +-1 and for large arguments.
Inverse sine, the principal value, `asin(z) = -i asinh(iz)`. The real part is in `[-pi/2, pi/2]`. Branch cuts are the real axis for `|a|>1`; the sign of a zero imaginary part selects the side (`asin(2+0i)` is `pi/2 + 1.317i`, `asin(2-0i)` is `pi/2 - 1.317i`). Accurate near zero, near `+-1` and for large arguments. See also [[sin]], [[acos]], [[asinh]], [[sqrt1z]].
(asinh z)Inverse hyperbolic sine, the principal value.
The real part has the sign of a, the imaginary part is in [-pi/2, pi/2] and has the sign of b. Branch cuts are the imaginary axis for |b|>1. The algorithm (Hull, Fairgrieve, Tang) is accurate near zero, near the branch points +-i and for arguments up to the maximum double.
Special values (C99): asinh(NaN+0i) keeps the zero imaginary part, +-Infinity with a NaN imaginary part gives +-Infinity+NaN*i.
Inverse hyperbolic sine, the principal value. The real part has the sign of `a`, the imaginary part is in `[-pi/2, pi/2]` and has the sign of `b`. Branch cuts are the imaginary axis for `|b|>1`. The algorithm (Hull, Fairgrieve, Tang) is accurate near zero, near the branch points `+-i` and for arguments up to the maximum double. Special values (C99): `asinh(NaN+0i)` keeps the zero imaginary part, `+-Infinity` with a `NaN` imaginary part gives `+-Infinity+NaN*i`. See also [[sinh]], [[asin]], [[acosh]], [[atanh]].
(atan z)Inverse tangent, the principal value, atan(z) = -i atanh(iz).
The real part is in [-pi/2, pi/2]. Branch cuts are the imaginary axis for |b|>1; the sign of a zero real part selects the side. atan(+-i) has an infinite imaginary part. Accurate near zero, near +-i and for large arguments.
Special values (C99): an infinite real part gives +-pi/2 with a zero imaginary part of the sign of the imaginary part.
Inverse tangent, the principal value, `atan(z) = -i atanh(iz)`. The real part is in `[-pi/2, pi/2]`. Branch cuts are the imaginary axis for `|b|>1`; the sign of a zero real part selects the side. `atan(+-i)` has an infinite imaginary part. Accurate near zero, near `+-i` and for large arguments. Special values (C99): an infinite real part gives `+-pi/2` with a zero imaginary part of the sign of the imaginary part. See also [[tan]], [[atanh]], [[acot]].
(atanh z)Inverse hyperbolic tangent, the principal value.
The imaginary part is in [-pi/2, pi/2]. Branch cuts are the real axis for |a|>1; the sign of a zero imaginary part selects the side. atanh(+-1) is +-Infinity with a zero imaginary part. Accurate near zero, near the branch points +-1 and for large arguments.
Special values (C99): an infinite imaginary part gives +-0 with the sign of the real part and +-pi/2 (finite real part); atanh(+-1) is +-Infinity.
Inverse hyperbolic tangent, the principal value. The imaginary part is in `[-pi/2, pi/2]`. Branch cuts are the real axis for `|a|>1`; the sign of a zero imaginary part selects the side. `atanh(+-1)` is `+-Infinity` with a zero imaginary part. Accurate near zero, near the branch points `+-1` and for large arguments. Special values (C99): an infinite imaginary part gives `+-0` with the sign of the real part and `+-pi/2` (finite real part); `atanh(+-1)` is `+-Infinity`. See also [[tanh]], [[atan]], [[asinh]].
(cbrt z)Principal cube root of the complex number z.
For a non negative real number the result is the real cube root (exact for perfect cubes). The branch cut is the negative real axis.
Principal cube root of the complex number `z`. For a non negative real number the result is the real cube root (exact for perfect cubes). The branch cut is the negative real axis. See also [[nth-root]], [[sqrt]].
(complex)(complex a)(complex a b)Creates a complex number represented as a [[Vec2]].
Takes optional real and imaginary parts. Without arguments returns 0+0i, with one argument the imaginary part is 0.0.
Examples:
(complex 1 2) ;; => #vec2 [1.0, 2.0] (complex 3) ;; => #vec2 [3.0, 0.0] (complex) ;; => #vec2 [0.0, 0.0]
Creates a complex number represented as a [[Vec2]]. Takes optional real and imaginary parts. Without arguments returns `0+0i`, with one argument the imaginary part is `0.0`. Examples: (complex 1 2) ;; => #vec2 [1.0, 2.0] (complex 3) ;; => #vec2 [3.0, 0.0] (complex) ;; => #vec2 [0.0, 0.0]
(conjugate z)Complex conjugate, a-bi for a+bi.
Complex conjugate, `a-bi` for `a+bi`.
(cos z)Complex cosine, cos(a+bi) = cos(a) cosh(b) - i sin(a) sinh(b).
Entire function. A part overflows only when it is not representable (the other part can be finite).
Special values (C99): an infinite real part with a zero imaginary part gives NaN and a zero imaginary part, with an infinite imaginary part Infinity+NaN*i.
Complex cosine, `cos(a+bi) = cos(a) cosh(b) - i sin(a) sinh(b)`. Entire function. A part overflows only when it is not representable (the other part can be finite). Special values (C99): an infinite real part with a zero imaginary part gives `NaN` and a zero imaginary part, with an infinite imaginary part `Infinity+NaN*i`. See also [[sin]], [[acos]], [[cosh]].
(cosh z)Complex hyperbolic cosine, cosh(a+bi) = cosh(a) cos(b) + i sinh(a) sin(b).
Entire function. The zero parts have the signs as in C99.
Special values (C99): an infinite real part with an infinite or NaN imaginary part gives Infinity+NaN*i.
Complex hyperbolic cosine, `cosh(a+bi) = cosh(a) cos(b) + i sinh(a) sin(b)`. Entire function. The zero parts have the signs as in C99. Special values (C99): an infinite real part with an infinite or `NaN` imaginary part gives `Infinity+NaN*i`. See also [[sinh]], [[acosh]], [[cos]].
(csgn z)(csgn re im)Complex signum function.
Takes z or the parts re and im. Returns 0.0 for the zero. For any other number returns the sign of the real part (-1.0 or 1.0), not the unit complex number.
Complex signum function. Takes `z` or the parts `re` and `im`. Returns `0.0` for the zero. For any other number returns the sign of the real part (`-1.0` or `1.0`), not the unit complex number. See also [[arg]], [[normalize]].
(delta-eq q1 q2)(delta-eq q1 q2 accuracy)Compares complex numbers q1 and q2 with the given absolute accuracy (1.0e-6 by default) in each part.
The comparison is absolute, so use a relative check for large magnitudes. It returns false for infinite parts, because Inf - Inf is NaN.
See also fastmath.vector/delta-eq.
Compares complex numbers `q1` and `q2` with the given absolute `accuracy` (`1.0e-6` by default) in each part. The comparison is absolute, so use a relative check for large magnitudes. It returns `false` for infinite parts, because `Inf - Inf` is `NaN`. See also [[fastmath.vector/delta-eq]].
(div z1 z2)Division of two complex numbers, z1 / z2.
Smith's algorithm: the result does not overflow or underflow in the middle when the quotient is representable (for example 1e200/1e200 or 1e-200/1e-200 with complex parts). Division by zero gives NaN parts.
See also reciprocal, mult.
Division of two complex numbers, `z1 / z2`. Smith's algorithm: the result does not overflow or underflow in the middle when the quotient is representable (for example `1e200/1e200` or `1e-200/1e-200` with complex parts). Division by zero gives `NaN` parts. See also [[reciprocal]], [[mult]].
(ensure-complex z)Converts z to a complex number ([[Vec2]]).
Accepted values:
Complex[re im] (see seq->complex)double array of length 2Throws ex-info for any other value, ex-data holds :reason and its details: :sequence-size with :count (a sequence without exactly two elements, also a 3d or 4d vector), :non-number with :z (a two element sequence with a non-number element), :array-size with :length (a double array of other length) or :unknown-type with :type (the class of the value).
Converts `z` to a complex number ([[Vec2]]). Accepted values: - a [[Vec2]], returned as is - a number (including a ratio), becomes a complex number with zero imaginary part - an Apache Commons Math `Complex` - a sequence of exactly two numbers `[re im]` (see [[seq->complex]]) - a `double` array of length 2 Throws `ex-info` for any other value, ex-data holds `:reason` and its details: `:sequence-size` with `:count` (a sequence without exactly two elements, also a 3d or 4d vector), `:non-number` with `:z` (a two element sequence with a non-number element), `:array-size` with `:length` (a `double` array of other length) or `:unknown-type` with `:type` (the class of the value).
(exp z)Complex exponential, exp(z) = exp(a) (cos(b) + i sin(b)).
Entire function, no branch cut. For a real argument returns a real number with the sign of the zero imaginary part kept. The result does not overflow too early: exp(710+i) is finite in the parts which are representable.
Special values (C99): an infinite real part with a non finite imaginary part gives Infinity+NaN*i for +Infinity and a zero for -Infinity.
Complex exponential, `exp(z) = exp(a) (cos(b) + i sin(b))`. Entire function, no branch cut. For a real argument returns a real number with the sign of the zero imaginary part kept. The result does not overflow too early: `exp(710+i)` is finite in the parts which are representable. Special values (C99): an infinite real part with a non finite imaginary part gives `Infinity+NaN*i` for `+Infinity` and a zero for `-Infinity`. See also [[log]], [[expm1]], [[cis]], [[pow]].
(expm1 z)Computes exp(z) - 1 accurately for z near zero.
The real part is computed as expm1(a) cos(b) - 2 sin^2(b/2), so it does not cancel.
Computes `exp(z) - 1` accurately for `z` near zero. The real part is computed as `expm1(a) cos(b) - 2 sin^2(b/2)`, so it does not cancel. See also [[exp]], [[log1p]].
(flip z)Exchanges the real and imaginary parts: a+bi becomes b+ai. It is i * conjugate(z).
Exchanges the real and imaginary parts: `a+bi` becomes `b+ai`. It is `i * conjugate(z)`.
Minus the imaginary unit, z=0-1i. Alias of -I.
Minus the imaginary unit, z=0-1i. Alias of [[-I]].
(imaginary? z)Returns true when the real part of z is zero (+0.0 or -0.0), a pure imaginary number (zero included).
Returns `true` when the real part of `z` is zero (`+0.0` or `-0.0`), a pure imaginary number (zero included).
(inf? z)Returns true when any part of z is infinite (also when the other part is NaN).
Returns `true` when any part of `z` is infinite (also when the other part is `NaN`).
(invalid? z)Returns true when z has an infinite or NaN part. See also valid?.
Returns `true` when `z` has an infinite or `NaN` part. See also [[valid?]].
(log z)Principal value of the natural logarithm, log(z) = log|z| + i arg(z).
The imaginary part is in the range [-pi, pi]. The branch cut is the negative real axis, the sign of a zero imaginary part selects the side. The real part is computed without overflow or underflow (1e200+1e200i gives 461.8) and without cancellation near the unit circle. log(0) is -Infinity with the argument of the signed zeros (0, -0 or +-pi).
Principal value of the natural logarithm, `log(z) = log|z| + i arg(z)`. The imaginary part is in the range `[-pi, pi]`. The branch cut is the negative real axis, the sign of a zero imaginary part selects the side. The real part is computed without overflow or underflow (`1e200+1e200i` gives `461.8`) and without cancellation near the unit circle. `log(0)` is `-Infinity` with the argument of the signed zeros (`0`, `-0` or `+-pi`). See also [[log1p]], [[logb]], [[exp]], [[arg]].
(logb z b)Logarithm of z with the complex base b, log(z)/log(b).
Both arguments can be numbers. See also log.
Logarithm of `z` with the complex base `b`, `log(z)/log(b)`. Both arguments can be numbers. See also [[log]].
(mult)(mult z)(mult z1 z2)(mult z1 z2 & more)Product of complex numbers.
Without arguments returns 1, with one argument the argument itself. More than two arguments are multiplied from left to right.
Product of complex numbers. Without arguments returns `1`, with one argument the argument itself. More than two arguments are multiplied from left to right. See also [[muladd]], [[scale]], [[mult-I]].
(mult-I z)Multiplication by 0+i, i*z. Exact, a rotation by 90 degrees.
Multiplication by `0+i`, `i*z`. Exact, a rotation by 90 degrees.
(mult-I- z)Multiplication by 0-i, -i*z. Exact, a rotation by -90 degrees.
Multiplication by `0-i`, `-i*z`. Exact, a rotation by -90 degrees.
(nan? z)Returns true when any part of z is NaN.
Returns `true` when any part of `z` is `NaN`.
(neg z)Negation of the complex number, -z.
Negation of the complex number, `-z`.
(norm z)Calculates the squared magnitude (norm) of the complex number z, a^2+b^2.
Also known as the squared modulus or squared Euclidean norm. Note that fastmath.quaternion/norm is the magnitude (not squared). The value overflows to Infinity when a^2+b^2 is not representable.
Calculates the squared magnitude (norm) of the complex number `z`, `a^2+b^2`. Also known as the squared modulus or squared Euclidean norm. Note that [[fastmath.quaternion/norm]] is the magnitude (not squared). The value overflows to `Infinity` when `a^2+b^2` is not representable. See also [[abs]], [[abs-sq]].
(nth-root z n)Principal n-th root of z, z^(1/n) for the integer n (positive or negative).
The root has the argument arg(z)/n, the other roots are obtained by multiplying by the roots of unity. The root of zero is zero for n>0 and Infinity+NaN*i for n<0, the root of an infinite number is infinite for n>0 and zero for n<0.
Throws ex-info when n is zero.
Principal `n`-th root of `z`, `z^(1/n)` for the integer `n` (positive or negative). The root has the argument `arg(z)/n`, the other roots are obtained by multiplying by the roots of unity. The root of zero is zero for `n>0` and `Infinity+NaN*i` for `n<0`, the root of an infinite number is infinite for `n>0` and zero for `n<0`. Throws `ex-info` when `n` is zero. See also [[sqrt]], [[cbrt]], [[pow]].
The real number pi as a complex number, z=pi+0i.
The real number pi as a complex number, z=pi+0i.
(pow z1 z2)Complex power z1^z2, the principal value exp(z2 log(z1)).
Integer real exponents with absolute value up to 32 are computed by repeated multiplication, so they are exact for exactly representable results ((1+2i)^3 = -11-2i). Other exponents use the logarithm and the exponential, which are free of overflow in the intermediate results.
Special cases:
1;0 when the real part of the exponent is positive, Infinity+NaN*i (the complex infinity) when it is negative, NaN+NaN*i when it is zero (also for 0^0).Complex power `z1^z2`, the principal value `exp(z2 log(z1))`. Integer real exponents with absolute value up to 32 are computed by repeated multiplication, so they are exact for exactly representable results (`(1+2i)^3 = -11-2i`). Other exponents use the logarithm and the exponential, which are free of overflow in the intermediate results. Special cases: * any non zero base with a zero exponent gives `1`; * zero base: `0` when the real part of the exponent is positive, `Infinity+NaN*i` (the complex infinity) when it is negative, `NaN+NaN*i` when it is zero (also for `0^0`). See also [[exp]], [[log]], [[sq]], [[nth-root]].
(proj z)Projection onto the Riemann sphere (C99 cproj).
Any number with an infinite part is mapped to the single point at infinity, Infinity as the real part and a zero imaginary part with the sign of the original imaginary part. Other numbers (also NaN) are returned unchanged.
See also inf?.
Projection onto the Riemann sphere (C99 `cproj`). Any number with an infinite part is mapped to the single point at infinity, `Infinity` as the real part and a zero imaginary part with the sign of the original imaginary part. Other numbers (also `NaN`) are returned unchanged. See also [[inf?]].
(real? z)Returns true when the imaginary part of z is zero (+0.0 or -0.0).
Returns `true` when the imaginary part of `z` is zero (`+0.0` or `-0.0`).
(reciprocal z)Reciprocal, 1/z.
Computed without intermediate overflow or underflow, correct for the whole range of doubles. The reciprocal of zero has infinite parts with the signs of the zeros (1/(+0+0i) is Inf-Inf*i), the reciprocal of an infinite number is zero.
See also div.
Reciprocal, `1/z`. Computed without intermediate overflow or underflow, correct for the whole range of doubles. The reciprocal of zero has infinite parts with the signs of the zeros (`1/(+0+0i)` is `Inf-Inf*i`), the reciprocal of an infinite number is zero. See also [[div]].
(scale z v)Multiplication of the complex number z by the real number v.
Multiplication of the complex number `z` by the real number `v`.
(seq->complex [a b])Creates a complex number ([[Vec2]]) from a sequence [re im].
Unchecked: the first two elements are taken as the real and imaginary parts, elements beyond them are ignored, a missing or non-number element throws a JVM exception. Use ensure-complex for a validated conversion.
Creates a complex number ([[Vec2]]) from a sequence `[re im]`. Unchecked: the first two elements are taken as the real and imaginary parts, elements beyond them are ignored, a missing or non-number element throws a JVM exception. Use [[ensure-complex]] for a validated conversion.
(sin z)Complex sine, sin(a+bi) = sin(a) cosh(b) + i cos(a) sinh(b).
Entire function. A part overflows only when it is not representable (the other part can be finite).
Special values (C99): an infinite real part with a zero imaginary part gives NaN and the zero imaginary part, with two infinite parts NaN+-Infinity*i.
Complex sine, `sin(a+bi) = sin(a) cosh(b) + i cos(a) sinh(b)`. Entire function. A part overflows only when it is not representable (the other part can be finite). Special values (C99): an infinite real part with a zero imaginary part gives `NaN` and the zero imaginary part, with two infinite parts `NaN+-Infinity*i`. See also [[cos]], [[asin]], [[sinh]].
(sinh z)Complex hyperbolic sine, sinh(a+bi) = sinh(a) cos(b) + i cosh(a) sin(b).
Entire function.
Special values (C99): +-Infinity real part with an infinite or NaN imaginary part gives +-Infinity+NaN*i, +-0 with a NaN imaginary part gives +-0+NaN*i.
Complex hyperbolic sine, `sinh(a+bi) = sinh(a) cos(b) + i cosh(a) sin(b)`. Entire function. Special values (C99): `+-Infinity` real part with an infinite or `NaN` imaginary part gives `+-Infinity+NaN*i`, `+-0` with a `NaN` imaginary part gives `+-0+NaN*i`. See also [[cosh]], [[asinh]], [[sin]].
(sqrt z)Principal square root of the complex number, sqrt(z).
The real part of the result is not negative; the imaginary part has the sign of the imaginary part of z (the sign of a zero imaginary part included). The root is computed without cancellation and without intermediate overflow or underflow, so it is accurate to a few ulps over the whole range of doubles (for example 1e200+1e200i, 1e-200+1e-200i, -1e-10+1e-30i). The zero is returned as 0 with the imaginary part of the argument. Special values (C99): an infinite imaginary part gives Infinity+Infinity*i (with the sign of the imaginary part) whatever the real part is, also NaN.
Principal square root of the complex number, `sqrt(z)`. The real part of the result is not negative; the imaginary part has the sign of the imaginary part of `z` (the sign of a zero imaginary part included). The root is computed without cancellation and without intermediate overflow or underflow, so it is accurate to a few ulps over the whole range of doubles (for example `1e200+1e200i`, `1e-200+1e-200i`, `-1e-10+1e-30i`). The zero is returned as `0` with the imaginary part of the argument. Special values (C99): an infinite imaginary part gives `Infinity+Infinity*i` (with the sign of the imaginary part) whatever the real part is, also `NaN`. See also [[sqrt1z]], [[cbrt]], [[nth-root]], [[abs]].
(sub z)(sub z1 z2)(sub z1 z2 & more)Difference of complex numbers, z1 - z2 - ....
With one argument returns the negation neg. More than two arguments are subtracted from the first one, from left to right.
Difference of complex numbers, `z1 - z2 - ...`. With one argument returns the negation [[neg]]. More than two arguments are subtracted from the first one, from left to right.
(tan z)Complex tangent, tan(z) = -i tanh(iz).
Does not overflow for large |b| (the imaginary part is +-1 up to rounding). Poles at pi/2 + k pi give large values.
Complex tangent, `tan(z) = -i tanh(iz)`. Does not overflow for large `|b|` (the imaginary part is `+-1` up to rounding). Poles at `pi/2 + k pi` give large values. See also [[tanh]], [[cot]], [[atan]].
(tanh z)Complex hyperbolic tangent.
Computed with the formulas of Hull, Fairgrieve and Tang, which do not overflow for large |a| (for |a|>=22 the real part is +-1 up to rounding) and for b near pi/2 + k pi.
Special values (C99): an infinite real part with a non finite imaginary part gives +-1 and a zero imaginary part.
Complex hyperbolic tangent. Computed with the formulas of Hull, Fairgrieve and Tang, which do not overflow for large `|a|` (for `|a|>=22` the real part is `+-1` up to rounding) and for `b` near `pi/2 + k pi`. Special values (C99): an infinite real part with a non finite imaginary part gives `+-1` and a zero imaginary part. See also [[tan]], [[coth]], [[atanh]].
(valid? z)Returns true when both parts of z are finite numbers. See also invalid?.
Returns `true` when both parts of `z` are finite numbers. See also [[invalid?]].
(zero? z)Returns true when both parts of z are zero (the sign of a zero does not matter).
Returns `true` when both parts of `z` are zero (the sign of a zero does not matter).
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |