complex number support
Nick Treleaven
nick at geany.org
Sun Feb 15 21:35:13 UTC 2026
On Sunday, 15 February 2026 at 21:04:17 UTC, Timon Gehr wrote:
> On 2/9/26 12:20, Quirin Schroll wrote:
>>
>> If you want to make D’s imaginary and complex types perfect,
>> allow for an implicit conversion from floating point types to
>> complex types that are bigger. I can’t remember how often I’ve
>> written `+ 0i`.
>
> Apparently that used to exist and was removed:
> https://forum.dlang.org/post/di2p73$2mgj$1@digitaldaemon.com
I don't think the logic below still applies:
```
real sin(real x)
-- (in user code) --
real w = sin(0.25);
float f = somefunc(); // maybe it's in a C library
real w2 = sin(f);
--------------------
Now we would like to add a complex sine function to std.math
creal sin(creal x)
```
The float argument would match both the real and the creal
parameter overloads as before. But now we have [partial
ordering](https://dlang.org/spec/function.html#partial-ordering)
which would find real converts to creal, but creal still would
not convert to real, so real is the more specialized overload. So
`sin(f)` would call the `sin(real)` overload even if float did
convert to cfloat.
More information about the Digitalmars-d
mailing list