www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13022] New: std.complex lacks a function returning the

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 puremagic.com
          Reporter: dlang.element126 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`.

--
Jul 02 2014