次の方法で共有


Math.DivRem メソッド (Int64, Int64, Int64)

メモ : この名前空間、クラス、およびメンバは、.NET Framework Version 1.1 だけでサポートされています。

2 つの 64 ビット符号付き整数の商を返し、出力パラメータとして剰余を渡します。

Overloads Public Shared Function DivRem( _
   ByVal a As Long, _   ByVal b As Long, _   <Out()> ByRef result As Long _) As Long
[C#]
public static long DivRem(longa,longb,   out longresult);
[C++]
public: static __int64 DivRem(__int64a,__int64b,   [   Out] __int64* result);
[JScript]
public static function DivRem(
   a : long,b : long,result : long) : long;

パラメータ

戻り値

指定した数値の商を格納している System.Int64

使用例

 
' This example demonstrates Math.DivRem()
'                           Math.IEEERemainder()
Imports System

Class Sample
   Public Shared Sub Main()
      Dim int1 As Integer = Int32.MaxValue
      Dim int2 As Integer = Int32.MaxValue
      Dim intResult As Integer
      Dim long1 As Long = Int64.MaxValue
      Dim long2 As Long = Int64.MaxValue
      Dim longResult As Long
      Dim doubleResult As Double
      Dim divisor As Double
      Dim nl As [String] = Environment.NewLine
      '
      Console.WriteLine("{0}Calculate the quotient and remainder of two Int32 values:", nl)
      intResult = Math.DivRem(int1, 2, int2)
      Console.WriteLine("{0}/{1} = {2}, with a remainder of {3}.", int1, 2, intResult, int2)
      '
      Console.WriteLine("{0}Calculate the quotient and remainder of two Int64 values:", nl)
      longResult = Math.DivRem(long1, 4, long2)
      Console.WriteLine("{0}/{1} = {2}, with a remainder of {3}.", long1, 4, longResult, long2)
      '
      Dim str1 As [String] = "The IEEE remainder of {0:e}/{1:f} is {2:e}"
      divisor = 2.0
      Console.WriteLine("{0}Divide two double-precision floating-point values:", nl)
      doubleResult = Math.IEEERemainder([Double].MaxValue, divisor)
      Console.Write("1) ")
      Console.WriteLine(str1, [Double].MaxValue, divisor, doubleResult)
      
      divisor = 3.0
      doubleResult = Math.IEEERemainder([Double].MaxValue, divisor)
      Console.Write("2) ")
      Console.WriteLine(str1, [Double].MaxValue, divisor, doubleResult)
      Console.WriteLine("Note that two positive numbers can yield a negative remainder.")
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'Calculate the quotient and remainder of two Int32 values:
'2147483647/2 = 1073741823, with a remainder of 1.
'
'Calculate the quotient and remainder of two Int64 values:
'9223372036854775807/4 = 2305843009213693951, with a remainder of 3.
'
'Divide two double-precision floating-point values:
'1) The IEEE remainder of 1.797693e+308/2.00 is 0.000000e+000
'2) The IEEE remainder of 1.797693e+308/3.00 is -1.995840e+292
'Note that two positive numbers can yield a negative remainder.
'

[C#] 
// This example demonstrates Math.DivRem()
//                           Math.IEEERemainder()
using System;

class Sample 
{
    public static void Main() 
    {
    int int1 = Int32.MaxValue;
    int int2 = Int32.MaxValue;
    int intResult;
    long long1 = Int64.MaxValue;
    long long2 = Int64.MaxValue;
    long longResult;
    double doubleResult;
    double divisor;
    String nl = Environment.NewLine;
//
    Console.WriteLine("{0}Calculate the quotient and remainder of two Int32 values:", nl);
    intResult = Math.DivRem(int1, 2, out int2);
    Console.WriteLine("{0}/{1} = {2}, with a remainder of {3}.", int1, 2, intResult, int2);
//
    Console.WriteLine("{0}Calculate the quotient and remainder of two Int64 values:", nl);
    longResult = Math.DivRem(long1, 4, out long2);
    Console.WriteLine("{0}/{1} = {2}, with a remainder of {3}.", long1, 4, longResult, long2);
//
    String str1 = "The IEEE remainder of {0:e}/{1:f} is {2:e}";
    divisor = 2.0;
    Console.WriteLine("{0}Divide two double-precision floating-point values:", nl);
    doubleResult = Math.IEEERemainder(Double.MaxValue, divisor);
    Console.Write("1) ");
    Console.WriteLine(str1, Double.MaxValue, divisor, doubleResult);

    divisor = 3.0;
    doubleResult = Math.IEEERemainder(Double.MaxValue, divisor);
    Console.Write("2) ");
    Console.WriteLine(str1, Double.MaxValue, divisor, doubleResult);
    Console.WriteLine("Note that two positive numbers can yield a negative remainder.");
    }
}
/*
This example produces the following results:

Calculate the quotient and remainder of two Int32 values:
2147483647/2 = 1073741823, with a remainder of 1.

Calculate the quotient and remainder of two Int64 values:
9223372036854775807/4 = 2305843009213693951, with a remainder of 3.

Divide two double-precision floating-point values:
1) The IEEE remainder of 1.797693e+308/2.00 is 0.000000e+000
2) The IEEE remainder of 1.797693e+308/3.00 is -1.995840e+292
Note that two positive numbers can yield a negative remainder.
*/

[C++] 
// This example demonstrates Math.DivRem()
//                           Math.IEEERemainder()
#using <mscorlib.dll>
using namespace System;

int main() 
{
    int int1 = Int32::MaxValue;
    int int2 = Int32::MaxValue;
    int intResult;
    Int64 long1 = Int64::MaxValue;
    Int64 long2 = Int64::MaxValue;
    Int64 longResult;
    double doubleResult;
    double divisor;
    String* nl = Environment::NewLine;
//
    Console::WriteLine(S"{0}Calculate the quotient and remainder of two Int32 values:", nl);
    intResult = Math::DivRem(int1, 2, &int2);
    Console::WriteLine(S"{0}/{1} = {2}, with a remainder of {3}.", __box(int1), __box(2), __box(intResult), __box(int2));
//
    Console::WriteLine(S"{0}Calculate the quotient and remainder of two Int64 values:", nl);
    longResult = Math::DivRem(long1, 4, &long2);
    Console::WriteLine(S"{0}/{1} = {2}, with a remainder of {3}.", __box(long1), __box(4), __box(longResult), __box(long2));
//
    String* str1 = S"The IEEE remainder of {0:e}/{1:f} is {2:e}";
    divisor = 2.0;
    Console::WriteLine(S"{0}Divide two double-precision floating-point values:", nl);
    doubleResult = Math::IEEERemainder(Double::MaxValue, divisor);
    Console::Write(S"1) ");
    Console::WriteLine(str1, __box(Double::MaxValue), __box(divisor), __box(doubleResult));

    divisor = 3.0;
    doubleResult = Math::IEEERemainder(Double::MaxValue, divisor);
    Console::Write(S"2) ");
    Console::WriteLine(str1, __box(Double::MaxValue), __box(divisor), __box(doubleResult));
    Console::WriteLine(S"Note that two positive numbers can yield a negative remainder.");
}
/*
This example produces the following results:

Calculate the quotient and remainder of two Int32 values:
2147483647/2 = 1073741823, with a remainder of 1.

Calculate the quotient and remainder of two Int64 values:
9223372036854775807/4 = 2305843009213693951, with a remainder of 3.

Divide two double-precision floating-point values:
1) The IEEE remainder of 1.797693e+308/2.00 is 0.000000e+000
2) The IEEE remainder of 1.797693e+308/3.00 is -1.995840e+292
Note that two positive numbers can yield a negative remainder.
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Math クラス | Math メンバ | System 名前空間 | Math.DivRem オーバーロードの一覧