Bug 13022 – std.complex lacks a function returning the squared modulus of a Complex
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-07-02T15:52:00Z
Last change time
2014-07-23T21:02:54Z
Keywords
pull
Assigned to
dlang.element126
Creator
dlang.element126
Comments
Comment #0 by dlang.element126 — 2014-07-02T15:52:51Z
std.complex has the function `pure nothrow @safe T abs(T)(Complex!T z);`, which returns the modulus of a Complex!T, but lacks a function that returns its squared modulus.
Using abs(z)*abs(z) would be inefficient due to the computation of the square root.
I suggest adding a function `pure nothrow @safe T abs2(T)(Complex!T z);`, as well as `pure nothrow @safe T abs2(T)(T z);` for genericity. The latter would simply be x -> x*x.
This function would be equivalent to C++ std::complex::norm.
The name `abs2` is used for consistency with `abs`, and is less mathematically incorrect than `norm`.
Comment #1 by dlang.element126 — 2014-07-02T20:54:52Z