Re: Could we have mod in std.math?

2011-12-25 Thread Walter Bright
On 12/25/2011 10:57 PM, Don wrote: On 24.12.2011 22:12, bearophile wrote: Caligo: I'm hoping to see something like the above mod function in Phobos someday. I'd like that, for both int/long/BigInts. And I'd like some functions for BigInts: - divmod: returns both % and div and %, but it's mor

Re: Could we have mod in std.math?

2011-12-25 Thread Don
On 24.12.2011 22:12, bearophile wrote: Caligo: I'm hoping to see something like the above mod function in Phobos someday. I'd like that, for both int/long/BigInts. And I'd like some functions for BigInts: - divmod: returns both % and div and %, but it's more efficient if you need both value

Re: Could we have mod in std.math?

2011-12-24 Thread bearophile
Caligo: > I'm hoping to see something like the above mod function in Phobos someday. I'd like that, for both int/long/BigInts. And I'd like some functions for BigInts: - divmod: returns both % and div and %, but it's more efficient if you need both values; - gcd - pow: with a third optional arg

Re: Could we have mod in std.math?

2011-12-21 Thread Stewart Gordon
On 21/12/2011 06:08, Caligo wrote: assert(mod(-6, 20) == 14); assert(mod( 6, -20) == -14); assert(mod(-6, -20) == -6); I'm hoping to see something like the above mod function in Phobos someday. And perhapse a 'rem' or 'remainder' function that's a wrapper for the % operator, just t

Re: Could we have mod in std.math?

2011-12-20 Thread Don
On 21.12.2011 07:08, Caligo wrote: 1. The % operator, just like in C/C++, calculates the remainder, but it doesn't handle negative numbers properly. It's not a mod operator, even though sometimes it's called that. assert(-6 % 20 == -6); assert( 6 % -20 == 6); assert(-6 % -20 == -6);

Could we have mod in std.math?

2011-12-20 Thread Caligo
1. The % operator, just like in C/C++, calculates the remainder, but it doesn't handle negative numbers properly. It's not a mod operator, even though sometimes it's called that. assert(-6 % 20 == -6); assert( 6 % -20 == 6); assert(-6 % -20 == -6); I use my own mod function whenever I ne