Skip to content

Commit a902d60

Browse files
authored
Use xref links and clarify precision caveats in MidpointRounding docs
1 parent 25e511d commit a902d60

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

xml/System/MidpointRounding.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
5656
Use the <xref:System.MidpointRounding> enumeration with appropriate overloads of <xref:System.Math.Round*?displayProperty=nameWithType>, <xref:System.MathF.Round*?displayProperty=nameWithType>, and <xref:System.Decimal.Round*?displayProperty=nameWithType> to provide more control of the rounding process.
5757
58-
Despite the enumeration's name, not every mode is only about how midpoints are handled. `MidpointRounding` defines two overall rounding strategies&mdash;*round to nearest* and *directed rounding*&mdash;and each enumeration field participates in exactly one of these strategies:
58+
Despite the enumeration's name, not every mode is only about how midpoints are handled. <xref:System.MidpointRounding> defines two overall rounding strategies&mdash;*round to nearest* and *directed rounding*&mdash;and each enumeration field participates in exactly one of these strategies:
5959
6060
- The *round-to-nearest* modes (<xref:System.MidpointRounding.AwayFromZero> and <xref:System.MidpointRounding.ToEven>) always round to the nearest representable value. They only differ from each other when the input is exactly halfway between two values (a *midpoint*), which is what the enumeration's name refers to.
6161
- The *directed rounding* modes (<xref:System.MidpointRounding.ToNegativeInfinity>, <xref:System.MidpointRounding.ToPositiveInfinity>, and <xref:System.MidpointRounding.ToZero>) always round every value&mdash;not just midpoints&mdash;in a fixed direction. The result is the nearest representable value in that direction, even when the input isn't a midpoint.
@@ -69,9 +69,9 @@ Fields:
6969
7070
A round-to-nearest operation takes an original number with an implicit or specified precision; examines the next digit, which is at that precision plus one; and returns the nearest number with the same precision as the original number. For positive numbers, if the next digit is from 0 through 4, the nearest number is toward negative infinity. If the next digit is from 6 through 9, the nearest number is toward positive infinity. For negative numbers, if the next digit is from 0 through 4, the nearest number is toward positive infinity. If the next digit is from 6 through 9, the nearest number is toward negative infinity.
7171
72-
If the next digit is from 0 through 4 or 6 through 9, the choice between `MidpointRounding.AwayFromZero` and `MidpointRounding.ToEven` doesn't affect the result of the rounding operation. However, if the next digit is 5, which is the midpoint between two possible results, and all remaining digits are zero or there are no remaining digits, the nearest number is ambiguous. In this case, the round-to-nearest modes in `MidpointRounding` enable you to specify whether the rounding operation returns the nearest number away from zero or the nearest even number.
72+
If the next digit is from 0 through 4 or 6 through 9, the choice between <xref:System.MidpointRounding.AwayFromZero> and <xref:System.MidpointRounding.ToEven> doesn't affect the result of the rounding operation. However, if the next digit is 5, which is the midpoint between two possible results, and all remaining digits are zero or there are no remaining digits, the nearest number is ambiguous. In this case, the round-to-nearest modes in <xref:System.MidpointRounding> enable you to specify whether the rounding operation returns the nearest number away from zero or the nearest even number.
7373
74-
The following table demonstrates the results of rounding some negative and positive numbers in conjunction with round-to-nearest modes. The precision used to round the numbers is zero, which means the number after the decimal point affects the rounding operation. For example, for the number -2.5, the digit after the decimal point is 5. Because that digit is the midpoint, you can use a `MidpointRounding` value to determine the result of rounding. If `AwayFromZero` is specified, -3 is returned because it is the nearest number away from zero with a precision of zero. If `ToEven` is specified, -2 is returned because it is the nearest even number with a precision of zero.
74+
The following table demonstrates the results of rounding some negative and positive numbers in conjunction with round-to-nearest modes. The precision used to round the numbers is zero, which means the number after the decimal point affects the rounding operation. For example, for the number -2.5, the digit after the decimal point is 5. Because that digit is the midpoint, you can use a <xref:System.MidpointRounding> value to determine the result of rounding. If <xref:System.MidpointRounding.AwayFromZero> is specified, -3 is returned because it is the nearest number away from zero with a precision of zero. If <xref:System.MidpointRounding.ToEven> is specified, -2 is returned because it is the nearest even number with a precision of zero.
7575
7676
| Original number | AwayFromZero | ToEven |
7777
|-----------------|--------------|--------|
@@ -92,7 +92,7 @@ Fields:
9292
- <xref:System.MidpointRounding.ToPositiveInfinity>
9393
- <xref:System.MidpointRounding.ToZero>
9494
95-
A directed-rounding operation takes an original number with an implicit or specified precision and returns the next closest number in a specific direction with the same precision as the original number. Directed modes on `MidpointRounding` control the direction toward which every value is rounded. Unlike the round-to-nearest modes, these modes apply to every input value, not just midpoints; for example, `ToPositiveInfinity` rounds 2.1, 2.5, and 2.8 all up to 3.
95+
A directed-rounding operation takes an original number with an implicit or specified precision and returns the next closest number in a specific direction with the same precision as the original number. Directed modes on <xref:System.MidpointRounding> control the direction toward which every value is rounded. Unlike the round-to-nearest modes, these modes apply to every input value, not just midpoints; for example, <xref:System.MidpointRounding.ToPositiveInfinity> rounds 2.1, 2.5, and 2.8 all up to 3.
9696
9797
The following table demonstrates the results of rounding some negative and positive numbers in conjunction with directed-rounding modes. The precision used to round the numbers is zero, which means the number before the decimal point is affected by the rounding operation.
9898
@@ -225,7 +225,7 @@ The following table demonstrates the results of rounding some negative and posit
225225
</ReturnValue>
226226
<MemberValue>3</MemberValue>
227227
<Docs>
228-
<summary>The strategy of downwards-directed rounding, where every value&mdash;not just midpoints&mdash;is rounded toward negative infinity. The result is the value closest to and no greater than the infinitely precise result. Equivalent to the mathematical floor function.</summary>
228+
<summary>The strategy of downwards-directed rounding, where every value&mdash;not just midpoints&mdash;is rounded toward negative infinity. The result is the value closest to and no greater than the infinitely precise result. When rounding to zero digits, this is equivalent to the mathematical floor function; when rounding to a non-zero number of digits, it applies the same behavior at the specified precision.</summary>
229229
</Docs>
230230
</Member>
231231
<Member MemberName="ToPositiveInfinity">
@@ -254,7 +254,7 @@ The following table demonstrates the results of rounding some negative and posit
254254
</ReturnValue>
255255
<MemberValue>4</MemberValue>
256256
<Docs>
257-
<summary>The strategy of upwards-directed rounding, where every value&mdash;not just midpoints&mdash;is rounded toward positive infinity. The result is the value closest to and no less than the infinitely precise result. Equivalent to the mathematical ceiling function.</summary>
257+
<summary>The strategy of upwards-directed rounding, where every value&mdash;not just midpoints&mdash;is rounded toward positive infinity. The result is the value closest to and no less than the infinitely precise result. When rounding to zero digits, this is equivalent to the mathematical ceiling function; when rounding to a non-zero number of digits, it applies the same behavior at the specified precision.</summary>
258258
</Docs>
259259
</Member>
260260
<Member MemberName="ToZero">
@@ -283,7 +283,7 @@ The following table demonstrates the results of rounding some negative and posit
283283
</ReturnValue>
284284
<MemberValue>2</MemberValue>
285285
<Docs>
286-
<summary>The strategy of directed rounding toward zero, where every value&mdash;not just midpoints&mdash;is rounded toward zero. The result is the value closest to and no greater in magnitude than the infinitely precise result. Equivalent to truncation.</summary>
286+
<summary>The strategy of directed rounding toward zero, where every value&mdash;not just midpoints&mdash;is rounded toward zero. The result is the value closest to and no greater in magnitude than the infinitely precise result. When rounding to zero digits, this is equivalent to truncation; when rounding to a non-zero number of digits, it truncates toward zero at the specified precision.</summary>
287287
</Docs>
288288
</Member>
289289
</Members>

0 commit comments

Comments
 (0)