std.algorithm - notes
bearophile
bearophileHUGS at lycos.com
Tue Mar 4 08:36:07 PST 2008
bearophile:
> - max/min: nicely done. A max/min of iterables (without the need to use reduce) is useful too (even with 'key' function, see my d libs).
Nevermind, I'll not use them, and I'll keep using my max/min functions. This prints 10:
void main() {
int a = -10;
uint b = 10;
writefln( min(a, b) );
}
The result type here must be a long, it's the only one that gives the right result whenever a,b of type int,uint.
Related problem: my abs() functions are like this (and I don't like them much still), they aren't templated:
int abs(int n) {
assert(n != int.min, "abs(int.min) == int.min");
return (n >= 0) ? n : -n;
}
Such bug catching show why I think multi-precision integers are useful for far more than just cryptography: they help avoid many bugs.
Bye,
bearophile
More information about the Digitalmars-d
mailing list