How would you describe the modulus function in c++ utilizing equations that don't include the actual modulus function

If x mod y equals a. I know that a = the remainder of x divided by y.
I've got a mental block and I can't figure out how I'd program mod without the utilization of the mod ("%") function. I have some variables in a program I'm using that I cannot use the mod function directly upon, without it disrupting the equation.

Anyone mind typing out some quick code of how I could substitute the mod function? My numbers are anywhere from 1 to 512 bit numbers I'm trying to mod.
Last edited on
Well, mathematically I'd see it like this:

a/b = c
floor(c)
a-(b*c) = d

and d would be the remainder.
I was not aware of the command "floor", thank you for that. Though, I'm still in need of help; boost::multiprecision (for the 512bit integers) doesn't have a matching function to call for "floor" 8(
For integers you can do it with only simple arithmetic operations.
I've got to do it with fractions that cannot be simplified until after the modulus is completed. The only way I've found to do that is to do each numerator/denominator individually. Peter87, that's what I'm asking for, what the arithmetic operations would be, though I may have found them.
Hint: Think about what integer division (division of two integers) gives you in C++.
Topic archived. No new replies allowed.