## digitalmars.D.learn - log for complex

- J-S Caux (8/8) Mar 06 2018 Simple question: how do I get the log of a complex number?
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (8/16) Mar 07 2018 That seems like an oversight. For now, this should work:
- J-S Caux (4/24) Mar 07 2018 Yes indeed I can do this, but isn't this inefficient as compared
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (7/15) Mar 07 2018 arg is just atan2 in disguise, and doesn't do any logarithms. I
- J-S Caux (5/21) Mar 07 2018 OK thanks Simen. Should your suggestion for repairing this
- H. S. Teoh (6/24) Mar 07 2018 Yes, please file a bug.

Simple question: how do I get the log of a complex number? If I try the simple logtest = log(complex(1.0, 2.0)) I get the compiler error Error: function core.stdc.math.log(double x) is not callable using argument types (Complex!double) Some basic functions are described in https://dlang.org/phobos/std_complex.html, but not the log...

Mar 06 2018

On Wednesday, 7 March 2018 at 07:42:37 UTC, J-S Caux wrote:Simple question: how do I get the log of a complex number? If I try the simple logtest = log(complex(1.0, 2.0)) I get the compiler error Error: function core.stdc.math.log(double x) is not callable using argument types (Complex!double) Some basic functions are described in https://dlang.org/phobos/std_complex.html, but not the log...That seems like an oversight. For now, this should work: auto log(T)(Complex!T x) { import std.math : log; return Complex!T(log (abs(x)), arg(x)); } -- Simen

Mar 07 2018

On Wednesday, 7 March 2018 at 08:04:36 UTC, Simen KjÃ¦rÃ¥s wrote:On Wednesday, 7 March 2018 at 07:42:37 UTC, J-S Caux wrote: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.Simple question: how do I get the log of a complex number? If I try the simple logtest = log(complex(1.0, 2.0)) I get the compiler error Error: function core.stdc.math.log(double x) is not callable using argument types (Complex!double) Some basic functions are described in https://dlang.org/phobos/std_complex.html, but not the log...That seems like an oversight. For now, this should work: auto log(T)(Complex!T x) { import std.math : log; return Complex!T(log (abs(x)), arg(x)); } -- Simen

Mar 07 2018

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: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. -- Simenauto 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.

Mar 07 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: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.On Wednesday, 7 March 2018 at 08:04:36 UTC, Simen KjÃ¦rÃ¥s wrote: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. -- Simenauto 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.

Mar 07 2018

On Wed, Mar 07, 2018 at 10:47:40AM +0000, J-S Caux via Digitalmars-d-learn wrote: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: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.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.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.Yes, please file a bug. T -- The trouble with TCP jokes is that it's like hearing the same joke over and over.

Mar 07 2018