C# BigInteger.ModPow bug?

前端 未结 1 1778
广开言路
广开言路 2021-01-17 18:51

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

相关标签:
1条回答
  • 2021-01-17 19:20

    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-negative BigInteger.

    For more info, see http://en.wikipedia.org/wiki/Modulo_operation#Remainder_calculation_for_the_modulo_operation.

    0 讨论(0)
提交回复
热议问题