BigInteger.Remainder Method

Performs integer division on two BigInteger values and returns the remainder.

Namespace:  System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)

public static BigInteger Remainder(
	BigInteger dividend,
	BigInteger divisor


Type: System.Numerics.BigInteger
The value to be divided.
Type: System.Numerics.BigInteger
The value to divide by.

Return Value

Type: System.Numerics.BigInteger
The remainder after dividing dividend by divisor.


divisor is 0 (zero).

The sign of the remainder is the sign of the dividend parameter.

The Remainder method is implemented for languages that do not support custom operators. Its behavior is identical to division using the modulus operator.

If necessary, the method automatically performs implicit conversion of other integral types to BigInteger objects before it performs the modulus operation.

The following example compares the remainder from the DivRem method with the remainder returned by the Remainder method to establish that the two methods calculate identical remainders.

using System;
using System.Numerics;

public class Example
   public static void Main()
      BigInteger dividend1 = BigInteger.Pow(Int64.MaxValue, 3);
      BigInteger dividend2 = dividend1 * BigInteger.MinusOne;
      BigInteger divisor1 = Int32.MaxValue;
      BigInteger divisor2 = divisor1 * BigInteger.MinusOne;
      BigInteger remainder1, remainder2;
      BigInteger divRem1 = BigInteger.Zero;
      BigInteger divRem2 = BigInteger.Zero;

      remainder1 = BigInteger.Remainder(dividend1, divisor1);
      remainder2 = BigInteger.Remainder(dividend2, divisor1);

      BigInteger.DivRem(dividend1, divisor1, out divRem1);
      Console.WriteLine("BigInteger.Remainder({0}, {1}) = {2}", 
                        dividend1, divisor1, remainder1);
      Console.WriteLine("BigInteger.DivRem({0}, {1}) = {2}", 
                        dividend1, divisor1, divRem1);                    
      if (remainder1.Equals(divRem1))
         Console.WriteLine("The remainders are equal.\n");

      BigInteger.DivRem(dividend2, divisor2, out divRem2);
      Console.WriteLine("BigInteger.Remainder({0}, {1}) = {2}", 
                        dividend2, divisor2, remainder2);
      Console.WriteLine("BigInteger.DivRem({0}, {1}) = {2}", 
                        dividend2, divisor2, divRem2);                    
      if (remainder2.Equals(divRem2))
         Console.WriteLine("The remainders are equal.\n");
// The example displays the following output:
//    BigInteger.Remainder(7.8463771692333509522426190271E+56, 2147483647) = 1
//    BigInteger.DivRem(7.8463771692333509522426190271E+56, 2147483647) = 1
//    The remainders are equal.
//    BigInteger.Remainder(-7.8463771692333509522426190271E+56, -2147483647) = -1
//    BigInteger.DivRem(-7.8463771692333509522426190271E+56, -2147483647) = -1
//    The remainders are equal.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft