Liking cljdoc? Tell your friends :D

fastmath.complex

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).
raw docstring

-Iclj

Minus the imaginary unit, z=0-1i.

Minus the imaginary unit, z=0-1i.
raw docstring

absclj

(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).
raw docstring

abs-sqclj

(abs-sq z)

Squared magnitude of z, alias of norm.

Squared magnitude of `z`, alias of [[norm]].
raw docstring

acosclj

(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).

See also cos, asin, acosh.

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]].
raw docstring

acoshclj

(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.

See also cosh, acos, asinh.

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]].
raw docstring

acotclj

(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.

See also cot, atan.

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]].
raw docstring

acothclj

(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.

See also coth, atanh.

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]].
raw docstring

acscclj

(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.

See also csc, asin.

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]].
raw docstring

acschclj

(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).

See also csch, asinh.

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]].
raw docstring

addclj

(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.
raw docstring

addsclj

(adds z v)

Adds the real number v to the complex number z.

Adds the real number `v` to the complex number `z`.
raw docstring

argclj

(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.

See also abs, log.

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]].
raw docstring

asecclj

(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.

See also sec, acos.

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]].
raw docstring

asechclj

(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).

See also sech, acosh.

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]].
raw docstring

asinclj

(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.

See also sin, acos, asinh, sqrt1z.

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]].
raw docstring

asinhclj

(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.

See also sinh, asin, acosh, atanh.

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]].
raw docstring

atanclj

(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.

See also tan, atanh, acot.

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]].
raw docstring

atanhclj

(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.

See also tanh, atan, asinh.

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]].
raw docstring

cbrtclj

(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.

See also nth-root, sqrt.

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]].
raw docstring

cisclj

(cis theta)

Returns cos(theta) + i sin(theta), a point on the unit circle for the real angle theta.

See also exp, arg.

Returns `cos(theta) + i sin(theta)`, a point on the unit circle for the real angle `theta`.

See also [[exp]], [[arg]].
raw docstring

complexclj

(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]
raw docstring

conjugateclj

(conjugate z)

Complex conjugate, a-bi for a+bi.

Complex conjugate, `a-bi` for `a+bi`.
raw docstring

cosclj

(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.

See also sin, acos, cosh.

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]].
raw docstring

coshclj

(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.

See also sinh, acosh, cos.

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]].
raw docstring

cotclj

(cot z)

Complex cotangent, 1/tan(z).

See also tan, acot.

Complex cotangent, `1/tan(z)`.

See also [[tan]], [[acot]].
raw docstring

cothclj

(coth z)

Complex hyperbolic cotangent, 1/tanh(z).

See also tanh, acoth.

Complex hyperbolic cotangent, `1/tanh(z)`.

See also [[tanh]], [[acoth]].
raw docstring

cscclj

(csc z)

Complex cosecant, 1/sin(z).

See also sin, acsc.

Complex cosecant, `1/sin(z)`.

See also [[sin]], [[acsc]].
raw docstring

cschclj

(csch z)

Complex hyperbolic cosecant, 1/sinh(z).

See also sinh, acsch.

Complex hyperbolic cosecant, `1/sinh(z)`.

See also [[sinh]], [[acsch]].
raw docstring

csgnclj

(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.

See also arg, normalize.

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]].
raw docstring

delta-eqclj

(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]].
raw docstring

divclj

(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]].
raw docstring

ensure-complexclj

(ensure-complex z)

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).

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).
raw docstring

expclj

(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.

See also log, expm1, cis, pow.

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]].
raw docstring

expm1clj

(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.

See also exp, log1p.

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]].
raw docstring

flipclj

(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)`.
raw docstring

Iclj

The imaginary unit, z=0+1i.

The imaginary unit, z=0+1i.
raw docstring

I-clj

Minus the imaginary unit, z=0-1i. Alias of -I.

Minus the imaginary unit, z=0-1i. Alias of [[-I]].
raw docstring

imclj

(im z)

Imaginary part of z as a double.

Imaginary part of `z` as a double.
raw docstring

imaginary?clj

(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).
raw docstring

inf?clj

(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`).
raw docstring

invalid?clj

(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?]].
raw docstring

logclj

(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).

See also log1p, logb, exp, arg.

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]].
raw docstring

log1pclj

(log1p z)

Computes log(1+z) accurately for z near zero.

Principal value, the branch cut is z real and less than -1.

See also log, expm1.

Computes `log(1+z)` accurately for `z` near zero.

Principal value, the branch cut is `z` real and less than -1.

See also [[log]], [[expm1]].
raw docstring

logbclj

(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]].
raw docstring

muladdclj

(muladd x y z)

Multiply-add of complex numbers, z + x*y.

See also mult, add.

Multiply-add of complex numbers, `z + x*y`.

See also [[mult]], [[add]].
raw docstring

multclj

(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.

See also muladd, scale, mult-I.

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]].
raw docstring

mult-Iclj

(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.
raw docstring

mult-I-clj

(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.
raw docstring

nan?clj

(nan? z)

Returns true when any part of z is NaN.

Returns `true` when any part of `z` is `NaN`.
raw docstring

negclj

(neg z)

Negation of the complex number, -z.

Negation of the complex number, `-z`.
raw docstring

normclj

(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.

See also abs, abs-sq.

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]].
raw docstring

normalizeclj

(normalize z)

Normalizes z to the unit magnitude, z / abs(z). The zero stays zero.

See also abs, csgn.

Normalizes `z` to the unit magnitude, `z / abs(z)`. The zero stays zero.

See also [[abs]], [[csgn]].
raw docstring

nth-rootclj

(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.

See also sqrt, cbrt, pow.

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]].
raw docstring

ONEclj

The real unit, z=1+0i.

The real unit, z=1+0i.
raw docstring

PIclj

The real number pi as a complex number, z=pi+0i.

The real number pi as a complex number, z=pi+0i.
raw docstring

powclj

(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:

  • 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.

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]].
raw docstring

projclj

(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?]].
raw docstring

reclj

(re z)

Real part of z as a double.

Real part of `z` as a double.
raw docstring

real?clj

(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`).
raw docstring

reciprocalclj

(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]].
raw docstring

scaleclj

(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`.
raw docstring

secclj

(sec z)

Complex secant, 1/cos(z).

See also cos, asec.

Complex secant, `1/cos(z)`.

See also [[cos]], [[asec]].
raw docstring

sechclj

(sech z)

Complex hyperbolic secant, 1/cosh(z).

See also cosh, asech.

Complex hyperbolic secant, `1/cosh(z)`.

See also [[cosh]], [[asech]].
raw docstring

seq->complexclj

(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.
raw docstring

sinclj

(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.

See also cos, asin, sinh.

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]].
raw docstring

sinhclj

(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.

See also cosh, asinh, sin.

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]].
raw docstring

sqclj

(sq z)

Square of the complex number, z^2.

Square of the complex number, `z^2`.
raw docstring

sqrtclj

(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.

See also sqrt1z, cbrt, nth-root, abs.

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]].
raw docstring

sqrt1zclj

(sqrt1z z)

Computes sqrt(1-z^2), the companion of asin and acos (sin(acos z)).

Computes `sqrt(1-z^2)`, the companion of [[asin]] and [[acos]] (`sin(acos z)`).
raw docstring

subclj

(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.
raw docstring

tanclj

(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.

See also tanh, cot, atan.

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]].
raw docstring

tanhclj

(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.

See also tan, coth, atanh.

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]].
raw docstring

TWOclj

The real number two, z=2+0i.

The real number two, z=2+0i.
raw docstring

valid?clj

(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?]].
raw docstring

ZEROclj

The complex zero, z=0+0i.

The complex zero, z=0+0i.
raw docstring

zero?clj

(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).
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close