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.
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.
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. 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.
(abs z)
Calculates the magnitude (absolute value) of the complex number z
.
Calculates the magnitude (absolute value) of the complex number `z`.
(arg z)
Argument (angle) of the complex number.
Argument (angle) of the complex number.
(complex)
(complex a)
(complex a b)
Creates a complex number represented as a [[Vec2]]. Takes optional real and imaginary parts.
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. Examples: (complex 1 2) ;; => #vec2 [1.0, 2.0] (complex 3) ;; => #vec2 [3.0, 0.0] (complex) ;; => #vec2 [0.0, 0.0]
(csgn z)
(csgn re im)
Complex signum function.
Returns 0.0
for the zero. For any other vector, returns the sign of the real part.
Complex signum function. Returns `0.0` for the zero. For any other vector, returns the sign of the real part.
(delta-eq q1 q2)
(delta-eq q1 q2 accuracy)
Compare complex numbers with given accuracy (10e-6 by default)
Compare complex numbers with given accuracy (10e-6 by default)
(div z1 z2)
Division of two complex numbers.
Division of two complex numbers.
(ensure-complex v)
Convert possible number to complex or return input.
Convert possible number to complex or return input.
(flip z)
Exchange imaginary and real parts
Exchange imaginary and real parts
(imaginary? z)
Is z is a pure imaginary number?
Is z is a pure imaginary number?
(mult z1 z2)
Multiplication of two complex numbers.
Multiplication of two complex numbers.
(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
.
Also known as the squared modulus or squared Euclidean norm.
Calculates the squared magnitude (norm) of the complex number `z`. Also known as the squared modulus or squared Euclidean norm.
(normalize z)
Normalize complex number to make abs(z) = 1
Normalize complex number to make abs(z) = 1
(sqrt z)
Sqrt of the complex number, sqrt(z)
Sqrt of the complex number, sqrt(z)
(sub z1 z2)
Difference of two complex numbers.
Difference of two complex numbers.
(valid? z)
Is valid complex (not NaN or Inf)?
Is valid complex (not NaN or Inf)?
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 |