Math.DivRem Метод

Определение

Вычисляет частное двух чисел и возвращает остаток в выходном параметре.

Перегрузки

DivRem(IntPtr, IntPtr)

Создает цитент и оставшуюся часть двух подписанных собственных чисел.

DivRem(Int64, Int64, Int64)

Вычисляет частное двух 64-битовых целых чисел со знаком и возвращает остаток в выходном параметре.

DivRem(Int32, Int32, Int32)

Вычисляет частное двух 32-разрядных знаковых целых чисел и возвращает остаток в выходном параметре.

DivRem(UIntPtr, UIntPtr)

Создает цитент и оставшуюся часть двух неподписанных номеров собственного размера.

DivRem(UInt64, UInt64)

Создает 64-разрядные числа без знака и оставшуюся часть 64-разрядных чисел.

DivRem(UInt32, UInt32)

Создает цитент и оставшуюся часть двух 32-разрядных чисел без знака.

DivRem(Int64, Int64)

Создает 64-разрядные цифры со знаком и оставшуюся часть 64-разрядных чисел.

DivRem(SByte, SByte)

Создает цитиент и оставшуюся часть двух подписанных 8-разрядных чисел.

DivRem(Int32, Int32)

Создает цитент и оставшуюся часть двух подписанных 32-разрядных чисел.

DivRem(Int16, Int16)

Создает цитент и оставшуюся часть двух подписанных 16-разрядных чисел.

DivRem(Byte, Byte)

Создает цитиент и оставшуюся часть двух неназначенных 8-разрядных чисел.

DivRem(UInt16, UInt16)

Создает цитиент и оставшуюся часть двух 16-разрядных чисел без знака.

DivRem(IntPtr, IntPtr)

Создает цитент и оставшуюся часть двух подписанных собственных чисел.

public:
 static ValueTuple<IntPtr, IntPtr> DivRem(IntPtr left, IntPtr right);
public static (nint Quotient, nint Remainder) DivRem (nint left, nint right);
public static (IntPtr Quotient, IntPtr Remainder) DivRem (IntPtr left, IntPtr right);
static member DivRem : nativeint * nativeint -> ValueTuple<nativeint, nativeint>
Public Shared Function DivRem (left As IntPtr, right As IntPtr) As ValueTuple(Of IntPtr, IntPtr)

Параметры

left
IntPtr

nint

nativeint

Делимое.

right
IntPtr

nint

nativeint

Делитель.

Возвращаемое значение

ValueTuple<IntPtr,IntPtr>

ValueTuple<nint,nint>

ValueTuple<nativeint,nativeint>

Цитент и остальная часть указанных чисел.

Применяется к

DivRem(Int64, Int64, Int64)

Вычисляет частное двух 64-битовых целых чисел со знаком и возвращает остаток в выходном параметре.

public:
 static long DivRem(long a, long b, [Runtime::InteropServices::Out] long % result);
public static long DivRem (long a, long b, out long result);
static member DivRem : int64 * int64 * int64 -> int64
Public Shared Function DivRem (a As Long, b As Long, ByRef result As Long) As Long

Параметры

a
Int64

Делимое.

b
Int64

Делитель.

result
Int64

При возврате этого метода содержит оставшуюся часть.

Возвращаемое значение

Int64

Частное от деления указанных чисел.

Исключения

b равен нулю.

Примеры

В следующем примере демонстрируется DivRem(Int64, Int64, Int64) метод.

using System;

public class Example
{
   public static void Main()
   {
      // Define several positive and negative dividends.
      long[] dividends = { Int64.MaxValue, 13952, 0, -14032,
                           Int64.MinValue };
      // Define one positive and one negative divisor.
      long[] divisors = { 2000, -2000 };

      foreach (long divisor in divisors)
      {
         foreach (long dividend in dividends)
         {
            long remainder;
            long quotient = Math.DivRem(dividend, divisor, out remainder);
            Console.WriteLine(@"{0:N0} \ {1:N0} = {2:N0}, remainder {3:N0}",
                              dividend, divisor, quotient, remainder);
         }
      }
   }
}
// The example displays the following output:
//    9,223,372,036,854,775,807 \ 2,000 = 4,611,686,018,427,387, remainder 1,807
//    13,952 \ 2,000 = 6, remainder 1,952
//    0 \ 2,000 = 0, remainder 0
//    -14,032 \ 2,000 = -7, remainder -32
//    -9,223,372,036,854,775,808 \ 2,000 = -4,611,686,018,427,387, remainder -1,808
//    9,223,372,036,854,775,807 \ -2,000 = -4,611,686,018,427,387, remainder 1,807
//    13,952 \ -2,000 = -6, remainder 1,952
//    0 \ -2,000 = 0, remainder 0
//    -14,032 \ -2,000 = 7, remainder -32
//    -9,223,372,036,854,775,808 \ -2,000 = 4,611,686,018,427,387, remainder -1,808
open System

// Define several positive and negative dividends.
let dividends =
    [ Int64.MaxValue; 13952; 0; -14032; Int64.MinValue ]
// Define one positive and one negative divisor.
let divisors = [ 2000; -2000 ]

for divisor in divisors do
    for dividend in dividends do
        let quotient, remainder = Math.DivRem(dividend, divisor)
        printfn $@"{dividend:N0} \ {divisor:N0} = {quotient:N0}, remainder {remainder:N0}"

// The example displays the following output:
//    9,223,372,036,854,775,807 \ 2,000 = 4,611,686,018,427,387, remainder 1,807
//    13,952 \ 2,000 = 6, remainder 1,952
//    0 \ 2,000 = 0, remainder 0
//    -14,032 \ 2,000 = -7, remainder -32
//    -9,223,372,036,854,775,808 \ 2,000 = -4,611,686,018,427,387, remainder -1,808
//    9,223,372,036,854,775,807 \ -2,000 = -4,611,686,018,427,387, remainder 1,807
//    13,952 \ -2,000 = -6, remainder 1,952
//    0 \ -2,000 = 0, remainder 0
//    -14,032 \ -2,000 = 7, remainder -32
//    -9,223,372,036,854,775,808 \ -2,000 = 4,611,686,018,427,387, remainder -1,808
Module Example
   Public Sub Main()
      ' Define several positive and negative dividends.
      Dim dividends() As Long = { Int64.MaxValue, 13952, 0, -14032, _
                                     Int64.MinValue }
      ' Define one positive and one negative divisor.
      Dim divisors() As Long = { 2000, -2000 }
      
      For Each divisor As Long In divisors
         For Each dividend As Long In dividends
            Dim remainder As Long 
            Dim quotient As Long = Math.DivRem(dividend, divisor, remainder)
            Console.WriteLine("{0:N0} \ {1:N0} = {2:N0}, remainder {3:N0}", _
                              dividend, divisor, quotient, remainder)
         Next
      Next                                
   End Sub
End Module
' The example displays the following output:
'    9,223,372,036,854,775,807 \ 2,000 = 4,611,686,018,427,387, remainder 1,807
'    13,952 \ 2,000 = 6, remainder 1,952
'    0 \ 2,000 = 0, remainder 0
'    -14,032 \ 2,000 = -7, remainder -32
'    -9,223,372,036,854,775,808 \ 2,000 = -4,611,686,018,427,387, remainder -1,808
'    9,223,372,036,854,775,807 \ -2,000 = -4,611,686,018,427,387, remainder 1,807
'    13,952 \ -2,000 = -6, remainder 1,952
'    0 \ -2,000 = 0, remainder 0
'    -14,032 \ -2,000 = 7, remainder -32
'    -9,223,372,036,854,775,808 \ -2,000 = 4,611,686,018,427,387, remainder -1,808

Комментарии

Оставшееся значение равно результату оператора остатка.

См. также раздел

Применяется к

DivRem(Int32, Int32, Int32)

Вычисляет частное двух 32-разрядных знаковых целых чисел и возвращает остаток в выходном параметре.

public:
 static int DivRem(int a, int b, [Runtime::InteropServices::Out] int % result);
public static int DivRem (int a, int b, out int result);
static member DivRem : int * int * int -> int
Public Shared Function DivRem (a As Integer, b As Integer, ByRef result As Integer) As Integer

Параметры

a
Int32

Делимое.

b
Int32

Делитель.

result
Int32

При возврате этого метода содержит оставшуюся часть.

Возвращаемое значение

Int32

Частное от деления указанных чисел.

Исключения

b равен нулю.

Примеры

В следующем примере демонстрируется DivRem(Int32, Int32, Int32) метод.

using System;

public class Example
{
   public static void Main()
   {
      // Define several positive and negative dividends.
      int[] dividends = { Int32.MaxValue, 13952, 0, -14032,
                                     Int32.MinValue };
      // Define one positive and one negative divisor.
      int[] divisors = { 2000, -2000 };

      foreach (int divisor in divisors)
      {
         foreach (int dividend in dividends)
         {
            int remainder;
            int quotient = Math.DivRem(dividend, divisor, out remainder);
            Console.WriteLine(@"{0:N0} \ {1:N0} = {2:N0}, remainder {3:N0}",
                              dividend, divisor, quotient, remainder);
         }
      }
   }
}
// The example displays the following output:
//       2,147,483,647 \ 2,000 = 1,073,741, remainder 1,647
//       13,952 \ 2,000 = 6, remainder 1,952
//       0 \ 2,000 = 0, remainder 0
//       -14,032 \ 2,000 = -7, remainder -32
//       -2,147,483,648 \ 2,000 = -1,073,741, remainder -1,648
//       2,147,483,647 \ -2,000 = -1,073,741, remainder 1,647
//       13,952 \ -2,000 = -6, remainder 1,952
//       0 \ -2,000 = 0, remainder 0
//       -14,032 \ -2,000 = 7, remainder -32
//       -2,147,483,648 \ -2,000 = 1,073,741, remainder -1,648
open System

// Define several positive and negative dividends.
let dividends = 
    [ Int32.MaxValue; 13952; 0; -14032; Int32.MinValue ]
// Define one positive and one negative divisor.
let divisors = [ 2000; -2000 ]

for divisor in divisors do
    for dividend in dividends do
        let quotient, remainder = Math.DivRem(dividend, divisor)
        printfn $@"{dividend:N0} \ {divisor:N0} = {quotient:N0}, remainder {remainder:N0}"

// The example displays the following output:
//       2,147,483,647 \ 2,000 = 1,073,741, remainder 1,647
//       13,952 \ 2,000 = 6, remainder 1,952
//       0 \ 2,000 = 0, remainder 0
//       -14,032 \ 2,000 = -7, remainder -32
//       -2,147,483,648 \ 2,000 = -1,073,741, remainder -1,648
//       2,147,483,647 \ -2,000 = -1,073,741, remainder 1,647
//       13,952 \ -2,000 = -6, remainder 1,952
//       0 \ -2,000 = 0, remainder 0
//       -14,032 \ -2,000 = 7, remainder -32
//       -2,147,483,648 \ -2,000 = 1,073,741, remainder -1,648
Module Example
   Public Sub Main()
      ' Define several positive and negative dividends.
      Dim dividends() As Integer = { Int32.MaxValue, 13952, 0, -14032, _
                                     Int32.MinValue }
      ' Define one positive and one negative divisor.
      Dim divisors() As Integer = { 2000, -2000 }
      
      For Each divisor As Integer In divisors
         For Each dividend As Integer In dividends
            Dim remainder As Integer 
            Dim quotient As Integer = Math.DivRem(dividend, divisor, remainder)
            Console.WriteLine("{0:N0} \ {1:N0} = {2:N0}, remainder {3:N0}", _
                              dividend, divisor, quotient, remainder)
         Next
      Next                                
   End Sub
End Module
' The example displays the following output:
'       2,147,483,647 \ 2,000 = 1,073,741, remainder 1,647
'       13,952 \ 2,000 = 6, remainder 1,952
'       0 \ 2,000 = 0, remainder 0
'       -14,032 \ 2,000 = -7, remainder -32
'       -2,147,483,648 \ 2,000 = -1,073,741, remainder -1,648
'       2,147,483,647 \ -2,000 = -1,073,741, remainder 1,647
'       13,952 \ -2,000 = -6, remainder 1,952
'       0 \ -2,000 = 0, remainder 0
'       -14,032 \ -2,000 = 7, remainder -32
'       -2,147,483,648 \ -2,000 = 1,073,741, remainder -1,648

Комментарии

Оставшееся значение равно результату оператора остатка.

См. также раздел

Применяется к

DivRem(UIntPtr, UIntPtr)

Важно!

Этот API несовместим с CLS.

Создает цитент и оставшуюся часть двух неподписанных номеров собственного размера.

public:
 static ValueTuple<UIntPtr, UIntPtr> DivRem(UIntPtr left, UIntPtr right);
[System.CLSCompliant(false)]
public static (nuint Quotient, nuint Remainder) DivRem (nuint left, nuint right);
[System.CLSCompliant(false)]
public static (UIntPtr Quotient, UIntPtr Remainder) DivRem (UIntPtr left, UIntPtr right);
[<System.CLSCompliant(false)>]
static member DivRem : unativeint * unativeint -> ValueTuple<unativeint, unativeint>
Public Shared Function DivRem (left As UIntPtr, right As UIntPtr) As ValueTuple(Of UIntPtr, UIntPtr)

Параметры

left
UIntPtr

nuint

unativeint

Делимое.

right
UIntPtr

nuint

unativeint

Делитель.

Возвращаемое значение

ValueTuple<UIntPtr,UIntPtr>

ValueTuple<nuint,nuint>

ValueTuple<unativeint,unativeint>

Цитент и остальная часть указанных чисел.

Атрибуты

Применяется к

DivRem(UInt64, UInt64)

Важно!

Этот API несовместим с CLS.

Создает 64-разрядные числа без знака и оставшуюся часть 64-разрядных чисел.

public:
 static ValueTuple<System::UInt64, System::UInt64> DivRem(System::UInt64 left, System::UInt64 right);
[System.CLSCompliant(false)]
public static (ulong Quotient, ulong Remainder) DivRem (ulong left, ulong right);
[<System.CLSCompliant(false)>]
static member DivRem : uint64 * uint64 -> ValueTuple<uint64, uint64>
Public Shared Function DivRem (left As ULong, right As ULong) As ValueTuple(Of ULong, ULong)

Параметры

left
UInt64

Делимое.

right
UInt64

Делитель.

Возвращаемое значение

ValueTuple<UInt64,UInt64>

Цитент и остальная часть указанных чисел.

Атрибуты

Применяется к

DivRem(UInt32, UInt32)

Важно!

Этот API несовместим с CLS.

Создает цитент и оставшуюся часть двух 32-разрядных чисел без знака.

public:
 static ValueTuple<System::UInt32, System::UInt32> DivRem(System::UInt32 left, System::UInt32 right);
[System.CLSCompliant(false)]
public static (uint Quotient, uint Remainder) DivRem (uint left, uint right);
[<System.CLSCompliant(false)>]
static member DivRem : uint32 * uint32 -> ValueTuple<uint32, uint32>
Public Shared Function DivRem (left As UInteger, right As UInteger) As ValueTuple(Of UInteger, UInteger)

Параметры

left
UInt32

Делимое.

right
UInt32

Делитель.

Возвращаемое значение

ValueTuple<UInt32,UInt32>

Цитент и остальная часть указанных чисел.

Атрибуты

Применяется к

DivRem(Int64, Int64)

Создает 64-разрядные цифры со знаком и оставшуюся часть 64-разрядных чисел.

public:
 static ValueTuple<long, long> DivRem(long left, long right);
public static (long Quotient, long Remainder) DivRem (long left, long right);
static member DivRem : int64 * int64 -> ValueTuple<int64, int64>
Public Shared Function DivRem (left As Long, right As Long) As ValueTuple(Of Long, Long)

Параметры

left
Int64

Делимое.

right
Int64

Делитель.

Возвращаемое значение

ValueTuple<Int64,Int64>

Цитент и остальная часть указанных чисел.

Применяется к

DivRem(SByte, SByte)

Важно!

Этот API несовместим с CLS.

Создает цитиент и оставшуюся часть двух подписанных 8-разрядных чисел.

public:
 static ValueTuple<System::SByte, System::SByte> DivRem(System::SByte left, System::SByte right);
[System.CLSCompliant(false)]
public static (sbyte Quotient, sbyte Remainder) DivRem (sbyte left, sbyte right);
[<System.CLSCompliant(false)>]
static member DivRem : sbyte * sbyte -> ValueTuple<sbyte, sbyte>
Public Shared Function DivRem (left As SByte, right As SByte) As ValueTuple(Of SByte, SByte)

Параметры

left
SByte

Делимое.

right
SByte

Делитель.

Возвращаемое значение

ValueTuple<SByte,SByte>

Цитент и остальная часть указанных чисел.

Атрибуты

Применяется к

DivRem(Int32, Int32)

Создает цитент и оставшуюся часть двух подписанных 32-разрядных чисел.

public:
 static ValueTuple<int, int> DivRem(int left, int right);
public static (int Quotient, int Remainder) DivRem (int left, int right);
static member DivRem : int * int -> ValueTuple<int, int>
Public Shared Function DivRem (left As Integer, right As Integer) As ValueTuple(Of Integer, Integer)

Параметры

left
Int32

Делимое.

right
Int32

Делитель.

Возвращаемое значение

ValueTuple<Int32,Int32>

Цитент и остальная часть указанных чисел.

Применяется к

DivRem(Int16, Int16)

Создает цитент и оставшуюся часть двух подписанных 16-разрядных чисел.

public:
 static ValueTuple<short, short> DivRem(short left, short right);
public static (short Quotient, short Remainder) DivRem (short left, short right);
static member DivRem : int16 * int16 -> ValueTuple<int16, int16>
Public Shared Function DivRem (left As Short, right As Short) As ValueTuple(Of Short, Short)

Параметры

left
Int16

Делимое.

right
Int16

Делитель.

Возвращаемое значение

ValueTuple<Int16,Int16>

Цитент и остальная часть указанных чисел.

Применяется к

DivRem(Byte, Byte)

Создает цитиент и оставшуюся часть двух неназначенных 8-разрядных чисел.

public:
 static ValueTuple<System::Byte, System::Byte> DivRem(System::Byte left, System::Byte right);
public static (byte Quotient, byte Remainder) DivRem (byte left, byte right);
static member DivRem : byte * byte -> ValueTuple<byte, byte>
Public Shared Function DivRem (left As Byte, right As Byte) As ValueTuple(Of Byte, Byte)

Параметры

left
Byte

Делимое.

right
Byte

Делитель.

Возвращаемое значение

ValueTuple<Byte,Byte>

Цитент и остальная часть указанных чисел.

Применяется к

DivRem(UInt16, UInt16)

Важно!

Этот API несовместим с CLS.

Создает цитиент и оставшуюся часть двух 16-разрядных чисел без знака.

public:
 static ValueTuple<System::UInt16, System::UInt16> DivRem(System::UInt16 left, System::UInt16 right);
[System.CLSCompliant(false)]
public static (ushort Quotient, ushort Remainder) DivRem (ushort left, ushort right);
[<System.CLSCompliant(false)>]
static member DivRem : uint16 * uint16 -> ValueTuple<uint16, uint16>
Public Shared Function DivRem (left As UShort, right As UShort) As ValueTuple(Of UShort, UShort)

Параметры

left
UInt16

Делимое.

right
UInt16

Делитель.

Возвращаемое значение

ValueTuple<UInt16,UInt16>

Цитент и остальная часть указанных чисел.

Атрибуты

Применяется к