[Issue 13022] New: std.complex lacks a function returning the squared modulus of a Complex

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jul 2 08:52:51 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13022

          Issue ID: 13022
           Summary: std.complex lacks a function returning the squared
                    modulus of a Complex
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: dlang.element126 at gmail.com

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`.

--


More information about the Digitalmars-d-bugs mailing list