log for complex

J-S Caux js at gmail.com
Wed Mar 7 10:47:40 UTC 2018


On Wednesday, 7 March 2018 at 10:28:23 UTC, Simen Kjærås wrote:
> On Wednesday, 7 March 2018 at 10:10:49 UTC, J-S Caux wrote:
>> On Wednesday, 7 March 2018 at 08:04:36 UTC, Simen Kjærås wrote:
>>> auto log(T)(Complex!T x) {
>>>     import std.math : log;
>>>     return Complex!T(log(abs(x)), arg(x));
>>> }
>>
>> Yes indeed I can do this, but isn't this inefficient as 
>> compared to what it should be? The internals of arg are 
>> presumable already doing part of/all the necessary work.
>
> arg is just atan2 in disguise, and doesn't do any logarithms. I 
> mean, in a way it does, but it's really just a fpatan 
> instruction. I don't expect there to be many optimization 
> opportunities here.
>
> --
>   Simen

OK thanks Simen. Should your suggestion for repairing this 
omission be filed as a bugreport? I can of course implement it 
locally for myself, but the language should really provide this 
function directly.


More information about the Digitalmars-d-learn mailing list