num-complex

A generic complex-number type with full arithmetic and analysis for Rust

Library
Cargo
v0.1.44
253stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
54/100Fair
Development Activity44
Maintenance12
Community80
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture82
Code Quality84
Innovation66
Learning Curve88

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, and from_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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search