[phobos] std.math.abs + user-defined types
David Simcha
dsimcha at gmail.com
Sat Aug 28 18:18:02 PDT 2010
std.math.abs looks to have been written to accommodate user-defined
numeric types, but then have had pure nothow stuck on it somewhat
haphazardly. IMHO now that Phobos is starting to grow some user-defined
numeric types, abs() should work with them. Other std library functions
should, too, as much as practical. IMHO the best solution for this
specific case, since the code is so trivial, is to just make two
versions: One that's pure nothrow and accepts builtin numeric types,
and one that's not pure nothrow and accepts user-defined types.
(Multiplying a BigInt by -1, for example, probably can't easily be made
pure.) Should this quick fix be done for now so that abs() works with
BigInt and Rational if/when it's checked in?
On the other hand, the problem of propagating purity for generic
functions probably needs to be addressed on a more general level. I
think this is easily solvable and I'm going to propose a solution on the
newsgroup momentarily.
--Dave
More information about the phobos
mailing list