num-complex
A generic complex-number type with full arithmetic and analysis for Rust
Repository Health
Technical Analysis
num-complex provides a generic Complex<T> number type for Rust as part of the wider num project. It implements the full set of arithmetic operators along with trigonometric, hyperbolic, exponential, and logarithmic functions, so you can work with complex numbers as naturally as with the built-in float and integer types.
The crate is generic over the underlying scalar type and integrates with num-traits, letting you build complex values on top of f32, f64, or any custom numeric type. It supports #![no_std] environments and optional libm-backed floating-point math, making it usable in embedded and scientific-computing contexts alike.
What You Get
- A generic
Complex<T>type parameterized over any numeric scalar - Complete arithmetic: add, subtract, multiply, divide, and negation operators
- Transcendental functions: exp, ln, powers, roots, sin/cos, and hyperbolic variants
- Polar-form helpers such as
norm,arg,to_polar, andfrom_polar - no_std support and optional libm backing for floating-point operations
Common Use Cases
- Implementing signal-processing and FFT routines that operate on complex values
- Numerical and scientific computing that requires complex arithmetic
- Evaluating mathematical functions over the complex plane
- Embedded or no_std math code that still needs complex-number support
Under The Hood
Architecture - The core Complex<T> struct lives in src/lib.rs with re and im fields, and the crate layers functionality across small focused modules: pow.rs for integer and float powers, cast.rs for numeric conversions, complex_float.rs for float-specific behavior, and crand.rs for optional rand integration. Arithmetic and transcendental methods are implemented as generic impls bounded by num-traits, so the same code works across scalar types.
Tech Stack - Pure Rust, dual-licensed Apache-2.0 OR MIT, minimum rustc 1.60. It builds on num-traits for its numeric abstractions and optionally on libm (for no_std float math), rand, serde, and bytemuck behind feature flags. The default std feature can be disabled for #![no_std] builds.
Code Quality - As a long-standing member of the rust-num organization with hundreds of millions of downloads and ~99 contributors, num-complex is stable and well tested, with CI across multiple rustc versions and detailed release notes in RELEASES.md. The code is compact, idiomatic, and carefully feature-gated to keep no_std and float paths correct.
API Design - The public API mirrors what Rust developers already expect from numbers: standard operator traits, From/Into conversions, and clearly named methods like conj, norm, arg, and to_polar. Genericity over the scalar type via num-traits keeps the surface small while remaining broadly reusable, and documentation on docs.rs is thorough.