BigInteger.Remainder Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Performs integer division on two BigInteger values and returns the remainder.
Namespace: System.Numerics
Assembly: System.Numerics (in System.Numerics.dll)
Syntax
'Declaration
Public Shared Function Remainder ( _
dividend As BigInteger, _
divisor As BigInteger _
) As BigInteger
public static BigInteger Remainder(
BigInteger dividend,
BigInteger divisor
)
Parameters
- dividend
Type: System.Numerics.BigInteger
The value to be divided.
- divisor
Type: System.Numerics.BigInteger
The value to divide by.
Return Value
Type: System.Numerics.BigInteger
The remainder after dividing dividend by divisor.
Remarks
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.
Examples
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.
Imports System.Numerics
Module Example
Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
Dim dividend1 As BigInteger = BigInteger.Pow(Int64.MaxValue, 3)
Dim dividend2 As BigInteger = dividend1 * BigInteger.MinusOne
Dim divisor1 As BigInteger = Int32.MaxValue
Dim divisor2 As BigInteger = divisor1 * BigInteger.MinusOne
Dim remainder1, remainder2 As BigInteger
Dim divRem1 As BigInteger = BigInteger.Zero
Dim divRem2 As BigInteger = BigInteger.Zero
remainder1 = BigInteger.Remainder(dividend1, divisor1)
remainder2 = BigInteger.Remainder(dividend2, divisor1)
BigInteger.DivRem(dividend1, divisor1, divRem1)
outputBlock.Text += String.Format("BigInteger.Remainder({0}, {1}) = {2}",
dividend1, divisor1, remainder1) + vbCrLf
outputBlock.Text += String.Format("BigInteger.DivRem({0}, {1}) = {2}",
dividend1, divisor1, divRem1) + vbCrLf
If remainder1.Equals(divRem1) Then outputBlock.Text &= "The remainders are equal." & vbCrLf
outputBlock.Text &= vbCrLf
BigInteger.DivRem(dividend2, divisor2, divRem2)
outputBlock.Text += String.Format("BigInteger.Remainder({0}, {1}) = {2}",
dividend2, divisor2, remainder2) + vbCrLf
outputBlock.Text += String.Format("BigInteger.DivRem({0}, {1}) = {2}",
dividend2, divisor2, divRem2) + vbCrLf
If remainder2.Equals(divRem2) Then outputBlock.Text &= "The remainders are equal." & vbCrLf
outputBlock.Text &= vbCrLf
End Sub
End Module
' 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.
using System;
using System.Numerics;
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
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);
outputBlock.Text += String.Format("BigInteger.Remainder({0}, {1}) = {2}",
dividend1, divisor1, remainder1) + "\n";
outputBlock.Text += String.Format("BigInteger.DivRem({0}, {1}) = {2}",
dividend1, divisor1, divRem1) + "\n";
if (remainder1.Equals(divRem1))
outputBlock.Text += "The remainders are equal.\n" + "\n";
BigInteger.DivRem(dividend2, divisor2, out divRem2);
outputBlock.Text += String.Format("BigInteger.Remainder({0}, {1}) = {2}",
dividend2, divisor2, remainder2) + "\n";
outputBlock.Text += String.Format("BigInteger.DivRem({0}, {1}) = {2}",
dividend2, divisor2, divRem2) + "\n";
if (remainder2.Equals(divRem2))
outputBlock.Text += "The remainders are equal.\n" + "\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.
Version Information
Silverlight
Supported in: 5, 4
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.