Math.IEEERemainder Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns the remainder resulting from the division of a specified number by another specified number.

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

Syntax

'Declaration
Public Shared Function IEEERemainder ( _
    x As Double, _
    y As Double _
) As Double
public static double IEEERemainder(
    double x,
    double y
)

Parameters

Return Value

Type: System.Double
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).
If x - (y Q) is zero, the value +0 is returned if x is positive, or -0 if x is negative.
If y = 0, NaN (Not-A-Number) is returned.

Remarks

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.

Examples

The following example uses the IEEERemainder method to calculate the remainders of two division operations between a Double variable's maximum value and 2 and 3, respectively. The result is then printed to the console.

' This example demonstrates Math.IEEERemainder()

Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim doubleResult As Double
      Dim divisor As Double

      Dim str1 As [String] = "The IEEE remainder of {0:e}/{1:f} is {2:e}"
      divisor = 2.0
      outputBlock.Text += String.Format("{0}Divide two double-precision floating-point values:", vbCrLf) & vbCrLf
      doubleResult = Math.IEEERemainder([Double].MaxValue, divisor)
      outputBlock.Text &= "1) "
      outputBlock.Text += String.Format(str1, [Double].MaxValue, divisor, doubleResult) & vbCrLf

      divisor = 3.0
      doubleResult = Math.IEEERemainder([Double].MaxValue, divisor)
      outputBlock.Text &= "2) "
      outputBlock.Text += String.Format(str1, [Double].MaxValue, divisor, doubleResult) & vbCrLf
      outputBlock.Text &= "Note that two positive numbers can yield a negative remainder." & vbCrLf
   End Sub 
End Class 
'
'This example produces the following results:
'   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.000000e+000
'   Note that two positive numbers can yield a negative remainder.
// This example demonstrates Math.IEEERemainder()
using System;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      double doubleResult;
      double divisor;

      String str1 = "The IEEE remainder of {0:e}/{1:f} is {2:e}";
      divisor = 2.0;
      outputBlock.Text += "\nDivide two double-precision floating-point values:" + "\n";
      doubleResult = Math.IEEERemainder(Double.MaxValue, divisor);
      outputBlock.Text += "1) ";
      outputBlock.Text += String.Format(str1, Double.MaxValue, divisor, doubleResult) + "\n";

      divisor = 3.0;
      doubleResult = Math.IEEERemainder(Double.MaxValue, divisor);
      outputBlock.Text += "2) ";
      outputBlock.Text += String.Format(str1, Double.MaxValue, divisor, doubleResult) + "\n";
      outputBlock.Text += "Note that two positive numbers can yield a negative remainder." + "\n";
   }
}
/*
This example produces the following results:

   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.000000e+000
   Note that two positive numbers can yield a negative remainder.

*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference