Skip to content

Commit 183a419

Browse files
committed
[Term Entry] C# Math-functions: IEEERemainder()
Added documentation for Math.IEEERemainder() method including: - Description of IEEE remainder calculation - Syntax and parameters - Examples showing difference from standard remainder operator - Codebyte example for interactive testing Resolves #7987
1 parent 95ccd9d commit 183a419

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
Title: 'IEEERemainder()'
3+
Description: 'Returns the IEEE remainder resulting from the division of two specified numbers.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Arithmetic'
9+
- 'Methods'
10+
- 'Numbers'
11+
CatalogContent:
12+
- 'learn-c-sharp'
13+
- 'paths/computer-science'
14+
---
15+
16+
The **`Math.IEEERemainder()`** [method](https://www.codecademy.com/resources/docs/c-sharp/methods) in C# returns the IEEE remainder resulting from the division of a specified number by another specified number. This method differs from the standard remainder operator (`%`) as it uses rounding rather than floor division.
17+
18+
## Syntax
19+
20+
```pseudo
21+
Math.IEEERemainder(double x, double y)
22+
```
23+
24+
**Parameters:**
25+
26+
- `x` (double): The dividend.
27+
- `y` (double): The divisor.
28+
29+
**Return value:**
30+
31+
The method will return a value of [type](https://www.codecademy.com/resources/docs/c-sharp/data-types) `double` calculated using the formula `x - (y * Q)`, where `Q` is the quotient of `x / y` rounded to the nearest integer (using banker's rounding for ties).
32+
33+
Special cases:
34+
35+
- If the result is zero, `+0` is returned if `x` is positive, or `-0` if `x` is negative.
36+
- If `y` is zero, the method will return `NaN`.
37+
- If `x` is `NaN`, the method will return `NaN`.
38+
- If `y` is `NaN`, the method will return `NaN`.
39+
40+
## Example
41+
42+
In this example, different numeric values are passed to `Math.IEEERemainder()` to demonstrate how it differs from the standard remainder operator:
43+
44+
```cs
45+
using System;
46+
47+
namespace MyIEEERemainder {
48+
public class Example {
49+
public static void Main(string[] args) {
50+
double a = Math.IEEERemainder(17, 4);
51+
double b = Math.IEEERemainder(11, 3);
52+
double c = Math.IEEERemainder(27.7, 4.1);
53+
double d = Math.IEEERemainder(-16, 5);
54+
55+
Console.WriteLine(a);
56+
Console.WriteLine(b);
57+
Console.WriteLine(c);
58+
Console.WriteLine(d);
59+
}
60+
}
61+
}
62+
```
63+
64+
This example results in the following output:
65+
66+
```shell
67+
1
68+
-1
69+
-0.6999999999999993
70+
-1
71+
```
72+
73+
## Codebyte Example
74+
75+
In this example, `Math.IEEERemainder()` is used to calculate the IEEE remainder and compare it with the standard remainder operator:
76+
77+
```codebyte/csharp
78+
using System;
79+
80+
public class Example {
81+
public static void Main() {
82+
double x = 17;
83+
double y = 5;
84+
85+
double ieeeRemainder = Math.IEEERemainder(x, y);
86+
double standardRemainder = x % y;
87+
88+
Console.WriteLine("IEEE Remainder: " + ieeeRemainder);
89+
Console.WriteLine("Standard Remainder: " + standardRemainder);
90+
}
91+
}
92+
```

0 commit comments

Comments
 (0)