This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Generating Modulo and Remainder Operations


> Alternatively, for integers you can use the % operator with unsigned
> numbers.  (If you need to work with signed numbers, convert the signed
> numbers to unsigned numbers and adjust the result's sign accordingly.)

How would the conversion from signed to unsigned be done without a modulus
function?  For example -11 = -2 = 7 (mod 9) but am I supposed to repeatedly
add 9 to my negative number until it becomes positive?  I thought that was
the whole point of having a modulus function.  What if I ask what is -12323
mod 9?  I can always make a conversion like this:

-12323 - (9 * (floor(-12323/9))

But then I'm implementing a mod function myself.

Presumably this is the same in C++ which shares C's standard numerical
library IIRC. 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]