digitalmars.D - complex number support
- Walter Bright (6/6) Feb 03 It's becoming clear that I cannot avoid supporting complex numbers in th...
- Richard (Rikki) Andrew Cattermole (4/15) Feb 03 I'm reminded of a certain comment you once made about extern(C++) about
- Walter Bright (2/3) Feb 04 ucent and float16 are a much simpler problem.
- Iain Buclaw (10/18) Feb 04 I've mentioned this before. I might be open to reintroducing
- Quirin Schroll (17/38) Feb 04 Please don’t miss `__imaginary`.
- jmh530 (3/19) Feb 04 What about `core.complex`?
- Walter Bright (4/11) Feb 04 Complex will always have to be supported because of C.
- Quirin Schroll (4/12) Feb 04 Having a built-in complex number types was a major selling point
- Iain Buclaw (9/24) Feb 04 I did the benchmarks with GDC way back when. `std.complex` was
- Walter Bright (2/4) Feb 04 I'm interested in your reasons!
It's becoming clear that I cannot avoid supporting complex numbers in the code generator for AArch64: 1. deprecating creal and use std.complex instead doesn't help since we need to support old code 2. C has complex real and imaginary real types, which need to be supported as well. I'm giving up and am just going to support complex types in the code generator.
Feb 03
On 04/02/2026 6:14 PM, Walter Bright wrote:It's becoming clear that I cannot avoid supporting complex numbers in the code generator for AArch64: 1. deprecating creal and use std.complex instead doesn't help since we need to support old code 2. C has complex real and imaginary real types, which need to be supported as well. I'm giving up and am just going to support complex types in the code generator.I'm reminded of a certain comment you once made about extern(C++) about how it was not worth the effort, until it was a few years later. Both (u)cent and float16 are in the same boat.
Feb 03
On 2/3/2026 9:22 PM, Richard (Rikki) Andrew Cattermole wrote:Both (u)cent and float16 are in the same boat.ucent and float16 are a much simpler problem.
Feb 04
On Wednesday, 4 February 2026 at 05:14:52 UTC, Walter Bright wrote:It's becoming clear that I cannot avoid supporting complex numbers in the code generator for AArch64: 1. deprecating creal and use std.complex instead doesn't help since we need to support old code 2. C has complex real and imaginary real types, which need to be supported as well. I'm giving up and am just going to support complex types in the code generator.I've mentioned this before. I might be open to reintroducing complex into the language as `__complex(float)` et al. so that it falls into the specialized category of types that aren't guaranteed to always be supported (whilst at the same time freeing up the old keywords to use as an identifier) We already have the means to test whether `__vector(T)` is supported on a given target, the same style hooks can be used for `__complex(T)`.
Feb 04
On Wednesday, 4 February 2026 at 16:58:42 UTC, Iain Buclaw wrote:On Wednesday, 4 February 2026 at 05:14:52 UTC, Walter Bright wrote:Please don’t miss `__imaginary`. It wouldn’t be too terrible if object.d had this: ```d version(ImaginarySupport) { alias ifloat = __imaginary(float); alias idouble = __imaginary(double); alias ireal = __imaginary(real); } version(ComplexSupport) { alias cfloat = __complex(float); alias cdouble = __complex(double); alias creal = __complex(real); } ```It's becoming clear that I cannot avoid supporting complex numbers in the code generator for AArch64: 1. deprecating creal and use std.complex instead doesn't help since we need to support old code 2. C has complex real and imaginary real types, which need to be supported as well. I'm giving up and am just going to support complex types in the code generator.I've mentioned this before. I might be open to reintroducing complex into the language as `__complex(float)` et al. so that it falls into the specialized category of types that aren't guaranteed to always be supported (whilst at the same time freeing up the old keywords to use as an identifier) We already have the means to test whether `__vector(T)` is supported on a given target, the same style hooks can be used for `__complex(T)`.
Feb 04
On Wednesday, 4 February 2026 at 17:19:36 UTC, Quirin Schroll
wrote:
[snip]
It wouldn’t be too terrible if object.d had this:
```d
version(ImaginarySupport)
{
alias ifloat = __imaginary(float);
alias idouble = __imaginary(double);
alias ireal = __imaginary(real);
}
version(ComplexSupport)
{
alias cfloat = __complex(float);
alias cdouble = __complex(double);
alias creal = __complex(real);
}
```
What about `core.complex`?
Feb 04
On 2/4/2026 8:58 AM, Iain Buclaw wrote:I've mentioned this before. I might be open to reintroducing complex into the language as `__complex(float)` et al. so that it falls into the specialized category of types that aren't guaranteed to always be supported (whilst at the same time freeing up the old keywords to use as an identifier) We already have the means to test whether `__vector(T)` is supported on a given target, the same style hooks can be used for `__complex(T)`.Complex will always have to be supported because of C. The vector types have a lot of specific code generator support. I have deferred investigating how to implement it for AArch64 until everything else is working.
Feb 04
On Wednesday, 4 February 2026 at 05:14:52 UTC, Walter Bright wrote:It's becoming clear that I cannot avoid supporting complex numbers in the code generator for AArch64: 1. deprecating creal and use std.complex instead doesn't help since we need to support old code 2. C has complex real and imaginary real types, which need to be supported as well. I'm giving up and am just going to support complex types in the code generator.Having a built-in complex number types was a major selling point when I started looking into D ~10 years ago.
Feb 04
On Wednesday, 4 February 2026 at 17:15:49 UTC, Quirin Schroll wrote:On Wednesday, 4 February 2026 at 05:14:52 UTC, Walter Bright wrote:I did the benchmarks with GDC way back when. `std.complex` was just as, or more performant than the built-in types - this can be easily explained as many complex operations are not _actually_ supported in hardware, so become an opaque library call like [__muldc3](https://compiler-explorer.com/z/nx5qEGnfs). The only thing lost was ABI compatibility, hence the special enum types that were added as the compromise.It's becoming clear that I cannot avoid supporting complex numbers in the code generator for AArch64: 1. deprecating creal and use std.complex instead doesn't help since we need to support old code 2. C has complex real and imaginary real types, which need to be supported as well. I'm giving up and am just going to support complex types in the code generator.Having a built-in complex number types was a major selling point when I started looking into D ~10 years ago.
Feb 04
On 2/4/2026 9:15 AM, Quirin Schroll wrote:Having a built-in complex number types was a major selling point when I started looking into D ~10 years ago.I'm interested in your reasons!
Feb 04









Walter Bright <newshound2 digitalmars.com> 