digitalmars.D.bugs - [Issue 6154] New: std.math.abs on std.complex numbers too
- d-bugmail puremagic.com (41/41) Jun 14 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6154
- d-bugmail puremagic.com (11/20) Jun 14 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6154
- d-bugmail puremagic.com (8/9) Jun 14 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6154
- d-bugmail puremagic.com (18/24) Jun 14 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6154
- d-bugmail puremagic.com (8/14) Jun 14 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6154
- d-bugmail puremagic.com (7/8) Jun 15 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6154
- d-bugmail puremagic.com (12/12) Aug 04 2013 http://d.puremagic.com/issues/show_bug.cgi?id=6154
http://d.puremagic.com/issues/show_bug.cgi?id=6154
Summary: std.math.abs on std.complex numbers too
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
I'd like std.math.abs to perform what std.complex.Complex!T.abs does. So I will
be able to use it functionally (currently std.math.abs is able to work on the
built-in complex numbers too). This means I'd like this code to work:
import std.stdio, std.math, std.algorithm, std.complex;
void main() {
alias Complex!double C;
C[] array2 = [C(1,2), C(2,4)];
auto m2 = map!abs(array2);
writeln(m2);
}
In DMD 2.053 similar code with built-in complex numbers works:
import std.stdio, std.math, std.algorithm;
void main() {
cdouble[] array1 = [1+2i, 2+4i];
auto m1 = map!abs(array1);
writeln(m1);
}
In DMD 2.053 if you want to do the same with complex numbers you need to write:
import std.stdio, std.math, std.algorithm, std.complex;
void main() {
alias Complex!double C;
C[] array2 = [C(1,2), C(2,4)];
auto m2 = map!((c){ return c.abs(); })(array2);
writeln(m2);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 14 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6154
kennytm gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kennytm gmail.com
In DMD 2.053 if you want to do the same with complex numbers you need to write:
import std.stdio, std.math, std.algorithm, std.complex;
void main() {
alias Complex!double C;
C[] array2 = [C(1,2), C(2,4)];
auto m2 = map!((c){ return c.abs(); })(array2);
writeln(m2);
}
auto m2 = map!`a.abs()`(array2);
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 14 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6154
auto m2 = map!`a.abs()`(array2);
Right. But std.math.abs has to work on complex numbers too, as before, for
polymorphism, and for a serious integration of complex numbers in Phobos.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 14 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6154
Don <clugdbug yahoo.com.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |clugdbug yahoo.com.au
auto m2 = map!`a.abs()`(array2);
Right. But std.math.abs has to work on complex numbers too, as before,
No, it does not, and will not.
BTW that approach would lead to executable bloat.
for polymorphism, and for a serious integration of complex numbers in Phobos.
No. This is what overload sets are for.
Complex must not be given special treatment ahead of user-defined types.
Otherwise, user-defined types become second-class citizens.
(std.math.abs is a bit of a problem at the moment, there are a couple of
functions in std.math which have range versions, which IMHO have no business
being in there).
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 14 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6154Right, but why must it be std.math.abs? Putting the free function as std.complex.abs works too. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------auto m2 = map!`a.abs()`(array2);Right. But std.math.abs has to work on complex numbers too, as before, for polymorphism, and for a serious integration of complex numbers in Phobos.
Jun 14 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6154Putting the free function as std.complex.abs works too.OK. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 15 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6154
Lars T. Kyllingstad <bugzilla kyllingen.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |bugzilla kyllingen.net
Resolution| |FIXED
05:51:12 PDT ---
std.complex.abs() was added in May 2012.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 04 2013









d-bugmail puremagic.com 