I\'m using the .NET BigInteger class to perform some math operations. However the ModPow method is giving me the wrong results. I have compared it to Java which I think is c
It's just a matter of definitions. From MSDN on C#:
The sign of the value returned by the modulus operation depends on the sign of dividend: If dividend is positive, the modulus operation returns a positive result; if it is negative, the modulus operation returns a negative result. The behavior of the modulus operation with
BigInteger
values is identical to the modulus operation with other integral types.
And from the JavaDocs for mod:
This method differs from
remainder
in that it always returns a non-negativeBigInteger
.
For more info, see http://en.wikipedia.org/wiki/Modulo_operation#Remainder_calculation_for_the_modulo_operation.