I have a question regarding modulus in C++. What I was trying to do was divide a very large number, lets say for example, M % 2, where M = 54,302,495,302,423. However, when I go to compile it says that the number is to ‘long’ for int. Then when I switch it to a double it repeats the same error message. Is there a way I can do this in which I will get the remainder of this very large number or possibly an even larger number? Thanks for your help, much appreciated.
Share
For large number arithmetic in C++, use the GMP library. In particular, the
mpz_modfunction would do this.For a more natural C++ wrapper, the
mpz_classclass can help by providing operator overloading for multiprecision operations.