Math.IEEERemainder(Double, Double) 메서드

정의

지정된 수를 지정된 다른 수로 나눈 나머지를 반환합니다.Returns the remainder resulting from the division of a specified number by another specified number.

public:
 static double IEEERemainder(double x, double y);
public static double IEEERemainder (double x, double y);
static member IEEERemainder : double * double -> double
Public Shared Function IEEERemainder (x As Double, y As Double) As Double

매개 변수

x
Double

피제수입니다.A dividend.

y
Double

제수입니다.A divisor.

반환

Double

x - (y Q)와 같은 숫자입니다. 여기서 Q는 가장 가까운 정수로 반올림된 x / y의 몫입니다. x / y가 두 수의 중간이면, 짝수가 반환됩니다.A number equal to x - (y Q), where Q is the quotient of x / y rounded to the nearest integer (if x / y falls halfway between two integers, the even integer is returned).

x - (y Q)가 0인 경우 x가 양수이면 값 +0이, x가 음수이면 값 -0이 반환됩니다.If x - (y Q) is zero, the value +0 is returned if x is positive, or -0 if x is negative.

y = 0인 경우 NaN이 반환됩니다.If y = 0, NaN is returned.

예제

다음 예제에서는 메서드에서 반환 된 나머지를 IEEERemainder 나머지 연산자가 반환한 나머지와 대조 합니다.The following example contrasts the remainder returned by the IEEERemainder method with the remainder returned by the remainder operator.

using System;

public class Example
{
   public static void Main()
   {
      Console.WriteLine($"{"IEEERemainder",35} {"Remainder operator",20}");
      ShowRemainders(3, 2);
      ShowRemainders(4, 2);
      ShowRemainders(10, 3);
      ShowRemainders(11, 3);
      ShowRemainders(27, 4);
      ShowRemainders(28, 5);
      ShowRemainders(17.8, 4);
      ShowRemainders(17.8, 4.1);
      ShowRemainders(-16.3, 4.1);
      ShowRemainders(17.8, -4.1);
      ShowRemainders(-17.8, -4.1);
   }

   private static void ShowRemainders(double number1, double number2)
   {
      var formula = $"{number1} / {number2} = ";
      var ieeeRemainder = Math.IEEERemainder(number1, number2);
      var remainder = number1 % number2;
      Console.WriteLine($"{formula,-16} {ieeeRemainder,18} {remainder,20}");
   }
}
// The example displays the following output:
//
//
//                       IEEERemainder   Remainder operator
// 3 / 2 =                          -1                    1
// 4 / 2 =                           0                    0
// 10 / 3 =                          1                    1
// 11 / 3 =                         -1                    2
// 27 / 4 =                         -1                    3
// 28 / 5 =                         -2                    3
// 17.8 / 4 =                      1.8                  1.8
// 17.8 / 4.1 =                    1.4                  1.4
// -16.3 / 4.1 =    0.0999999999999979                   -4
// 17.8 / -4.1 =                   1.4                  1.4
// -17.8 / -4.1 =                 -1.4                 -1.4
Module Example
    Public Sub Main()
        Console.WriteLine($"{"IEEERemainder",35} {"Remainder operator",20}")
        ShowRemainders(3, 2)
        ShowRemainders(4, 2)
        ShowRemainders(10, 3)
        ShowRemainders(11, 3)
        ShowRemainders(27, 4)
        ShowRemainders(28, 5)
        ShowRemainders(17.8, 4)
        ShowRemainders(17.8, 4.1)
        ShowRemainders(-16.3, 4.1)
        ShowRemainders(17.8, -4.1)
        ShowRemainders(-17.8, -4.1)
    End Sub

    Private Sub ShowRemainders(number1 As Double, number2 As Double)
        Dim formula As String = $"{number1} / {number2} = "
        Dim ieeeRemainder As Double = Math.IEEERemainder(number1, number2)
        Dim remainder As Double = number1 Mod number2
        Console.WriteLine($"{formula,-16} {ieeeRemainder,18} {remainder,20}")
    End Sub
End Module
' The example displays the following output:
'       
'                       IEEERemainder   Remainder operator
' 3 / 2 =                          -1                    1
' 4 / 2 =                           0                    0
' 10 / 3 =                          1                    1
' 11 / 3 =                         -1                    2
' 27 / 4 =                         -1                    3
' 28 / 5 =                         -2                    3
' 17.8 / 4 =                      1.8                  1.8
' 17.8 / 4.1 =                    1.4                  1.4
' -16.3 / 4.1 =    0.0999999999999979                   -4
' 17.8 / -4.1 =                   1.4                  1.4
' -17.8 / -4.1 =                 -1.4                 -1.4

설명

이 작업은 ANSI/IEEE Std 754-1985의 섹션 5.1에 정의 된 나머지 작업을 준수 합니다. 이진 Floating-Point 산술의 경우 IEEE Standard 전기 및 전자 제품 엔지니어, i n c;의 협회 1985.This operation complies with the remainder operation defined in Section 5.1 of ANSI/IEEE Std 754-1985; IEEE Standard for Binary Floating-Point Arithmetic; Institute of Electrical and Electronics Engineers, Inc; 1985.

IEEERemainder메서드는 나머지 연산자와 동일 하지 않습니다.The IEEERemainder method is not the same as the remainder operator. 나눗셈 후에 나머지를 반환 하지만 사용 하는 수식은 다릅니다.Although both return the remainder after division, the formulas they use are different. IEEERemainder메서드의 수식은 다음과 같습니다.The formula for the IEEERemainder method is:

IEEERemainder = dividend - (divisor * Math.Round(dividend / divisor))  

반대로 나머지 연산자의 수식은 다음과 같습니다.In contrast, the formula for the remainder operator is:

Remainder = (Math.Abs(dividend) - (Math.Abs(divisor) *   
            (Math.Floor(Math.Abs(dividend) / Math.Abs(divisor))))) *   
            Math.Sign(dividend)  

적용 대상