Repository navigation
Tracking issue for RFC 3892: Complex numbers (complex_numbers) #154023
Description
This is a tracking issue for RFC 3892: Complex numbers.
The feature gate for the issue is #![feature(complex_numbers)].
About tracking issues
Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Library API
// in core::num
pub struct Complex<T> {
pub re: T,
pub im: T,
}
impl<T> Complex<T> {
pub fn new(re: T, im: T);
pub fn conjugate(self) -> Self;
}
impl<T: Default> Default for Complex<T> { /* ... */ }
impl<T: Neg> Neg for Complex<T> {
type Output = Complex<T::Output>;
// ...
}
impl<T: Add> Add<Self> for Complex<T> {
type Output = Complex<T::Output>;
// ...
}
impl<T: Add<Output = T>> Add<T> for Complex<T> {
type Output = Complex<T::Output>;
// ...
}
impl<T: Sub> Sub<Self> for Complex<T> {
type Output = Complex<T::Output>;
// ...
}
impl<T: Sub<Output = T>> Sub<T> for Complex<T> {
type Output = Complex<T::Output>;
// ...
}
impl Mul for Complex<{float}> {
type Output = Self;
// ...
}
impl Div for Complex<{float}> {
type Output = Self;
// ...
}Steps
- Accept an RFC.
- Implement in nightly.
- Add documentation to the reference.
- See the instructions.
- Stabilize.
- See the instructions.
Unresolved Questions
ABI compatibility
On some targets, Clang and GCC deviate on the ABI they use.
For Complex<{ float }>:
- [MIPS][clang] make
_ComplexABI match GCC llvm/llvm-project#212119 (fixed in LLVM 24) - [PowerPC] make
_ComplexABI GCC-compatible llvm/llvm-project#208917
For Complex<{ integer }>:
- [Sparc][clang] make
_ComplexABI GCC-compatible llvm/llvm-project#212340 (fixed in LLVM 24) - [Loongarch] ABI of
_Complexof small integers is different from GCC llvm/llvm-project#214810
Note that Complex<{ integer }> is a GNU extension, and we don't currently intend to guarantee ABI compatibility for the complex integers a part of the initial stabilization. The compatibility issues are tracked here for completeness.
Clang also outright rejects the type in some cases where it has no defined "C" ABI. If neither GCC nor clang accept the equivalent code (e.g. because SSE is missing), we should at least consider just refusing to compile the program.
Precision of Mul
See #154023 (comment).
Related
TODO.
Implementation history
TODO.
cc @scimind2460
Activity
MusicalNinjaDad commentedon Apr 2, 2026
I just saw the discussion on internals and would be keen to pick up the implementation of this if you are open to support @traviscross / @scimind2460
scimind2460 commentedon Apr 3, 2026
tgross35 commentedon Apr 3, 2026
@scimind2460 do you plan to reopen a PR with the initial changes?
If you're running into issues with git, open a PR anyway and just describe what's going on. We can help you fix it, some of us are reasonably good at git things :).
MusicalNinjaDad commentedon Apr 3, 2026
@scimind2460 - I can also offer to handle the rebase, or walk you through it, for the PR.
If you are able to reopen #154040 and I can support with the exact git commands to use, that's probably best. Then you keep all the review comments alive.
If you can't reopen then we can find another way too.
CodesInChaos commentedon Apr 8, 2026
num-complexmakes use ofnum-traitsto implement many of its functions. Anstd:num::Complexwhich doesn't build on similar traits will be less flexible (only work for a few underlying types) or powerful (only support few operations) thannum_complex. I'd expect such an inferior std implementation to splinter the ecosystem instead of unifying it.Is it planned to add something similar to
num_traitsto std?scimind2460 commentedon Apr 18, 2026
Thanks for the offer, @tgross35 and @MusicalNinjaDad! The problem is with certain submodules keeping on breaking. It also seems that my local copy has broken after me trying to horrendously fix a merge commit.
scimind2460 commentedon Apr 18, 2026
I don't think so. The libs-team folks didn't exactly like the idea. They thought it would bloat the MVP. But I think that if a different idea was proposed to move
num_traitsinto std, it might have some support.CodesInChaos commentedon Apr 18, 2026
It doesn't matter until it gets stabilized, but I think a
std::num::Complexwithout num-traits would be a mistake. It forces consumers to choose between the flexible but externalnum-complexcrate, and the built-in but limitedstd::num::Complex, fracturing the ecosystem. Which is the exact opposite of "provide a unified API" goal stated in the RFC.If no num-traits will be added (that's a pretty big change after all), then std should limit itself to a simple
std::ffi::complextype, with the expectation thatnum-complexwill wrap it (to solve the FFI issues), and consumers will continue to usenum-complex.tgross35 commentedon Apr 18, 2026
To get your repo back to a clean state you can try something like this:
Then just reapply a known good patch. Looking at #154040 it seems like fa06e21 might be a good candidate.
tgross35 commentedon Apr 18, 2026
Note that
num-complexwill be able to switch to reexporting thestdtype once available, and will likely want to do so given the ABI issues it resolves.Apersoma commentedon Apr 18, 2026
will there be any precision guarantees for multiplication? maybe even division, probably not though.
also what are all the git issues that all the prs seem to be having?
41 remaining items
Rollup merge of rust-lang#162832 - folkertdev:complex-mul-div, r=tgro…
Unrolled build for #162832 in rollup 163472
Rollup merge of #162832 - folkertdev:complex-mul-div, r=tgross35
Rollup merge of #162832 - folkertdev:complex-mul-div, r=tgross35
Rollup merge of rust-lang#162921 - folkertdev:complex-mips64, r=beetrees
Rollup merge of rust-lang#162921 - folkertdev:complex-mips64, r=beetrees
Unrolled build for #162921 in rollup 163583
Rollup merge of #162921 - folkertdev:complex-mips64, r=beetrees
Rollup merge of #162921 - folkertdev:complex-mips64, r=beetrees
Rollup merge of rust-lang#163617 - folkertdev:complex-mips, r=beetrees
Rollup merge of rust-lang#163617 - folkertdev:complex-mips, r=beetrees
Rollup merge of rust-lang#163617 - folkertdev:complex-mips, r=beetrees
Rollup merge of rust-lang#163617 - folkertdev:complex-mips, r=beetrees
Unrolled build for #163617 in rollup 164005
Rollup merge of #163617 - folkertdev:complex-mips, r=beetrees