Skip to content

Commit ac5c1cd

Browse files
authored
Enable .NET Interactive on partially enabled APIs (#4094)
1 parent a9e6bdf commit ac5c1cd

File tree

8 files changed

+87
-85
lines changed

8 files changed

+87
-85
lines changed

samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/midpoint1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static void Main()
2424
// 12.7 13 13 13
2525
// 12.8 13 13 13
2626
// 12.9 13 13 13
27-
// 13.0 13 13 13
27+
// 13 13 13 13
2828
// </Snippet5>
2929
}
3030
}

samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/midpoint2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ public static void Main()
2828
// 12.7 13 13 13
2929
// 12.8 13 13 13
3030
// 12.9 13 13 13
31-
// 13.0 13 13 13
31+
// 13 13 13 13
3232
// </Snippet6>

samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/midpoint1.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ End Module
2626
' 12.7 13 13 13
2727
' 12.8 13 13 13
2828
' 12.9 13 13 13
29-
' 13.0 13 13 13
29+
' 13 13 13 13
3030
' </Snippet5>

samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/midpoint2.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ End Module
2828
' 12.7 13 13 13
2929
' 12.8 13 13 13
3030
' 12.9 13 13 13
31-
' 13.0 13 13 13
31+
' 13 13 13 13
3232
' </Snippet6>

xml/System.Text/StringBuilder.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@
280280
## Examples
281281
The following example shows how to call many of the methods defined by the <xref:System.Text.StringBuilder> class.
282282
283-
[!code-cpp[StringBuilder#1](~/samples/snippets/cpp/VS_Snippets_CLR/StringBuilder/cpp/StringBuilder.cpp#1)]
284-
[!code-csharp[StringBuilder#1](~/samples/snippets/csharp/VS_Snippets_CLR/StringBuilder/CS/StringBuilder.cs#1)]
285-
[!code-vb[StringBuilder#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/StringBuilder/VB/StringBuilder.vb#1)]
283+
:::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/StringBuilder/cpp/StringBuilder.cpp" id="Snippet1":::
284+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/StringBuilder/CS/StringBuilder.cs" interactive="try-dotnet" id="Snippet1":::
285+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/StringBuilder/VB/StringBuilder.vb" id="Snippet1":::
286286
287287
]]></format>
288288
</remarks>

xml/System/Math.xml

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4758,16 +4758,16 @@ Problems of precision in rounding midpoint values are most likely to arise in th
47584758
47594759
- Define a custom rounding algorithm that performs a "nearly equal" test to determine whether the value to be rounded is acceptably close to a midpoint value. The following example defines a `RoundApproximate` method that examines whether a fractional value is sufficiently near to a midpoint value to be subject to midpoint rounding. As the output from the example shows, it corrects the rounding problem shown in the previous example.
47604760
4761-
[!code-csharp[System.Math.Round.Overload#8](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/precision2.cs#8)]
4762-
[!code-vb[System.Math.Round.Overload#8](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/precision2.vb#8)]
4761+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/precision2.cs" interactive="try-dotnet" id="Snippet8":::
4762+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/precision2.vb" id="Snippet8":::
47634763
47644764
#### Rounding and single-precision floating-point values
47654765
47664766
The <xref:System.Math.Round%2A> method includes overloads that accept arguments of type <xref:System.Decimal> and <xref:System.Double>. There are no methods that round values of type <xref:System.Single>. If you pass a <xref:System.Single> value to one of the overloads of the <xref:System.Math.Round%2A> method, it is cast (in C#) or converted (in Visual Basic) to a <xref:System.Double>, and the corresponding <xref:System.Math.Round%2A> overload with a <xref:System.Double> parameter is called. Although this is a widening conversion, it often involves a loss of precision, as the following example illustrates. When a <xref:System.Single> value of 16.325 is passed to the <xref:System.Math.Round%2A> method and rounded to two decimal places using the rounding to nearest convention, the result is 16.33 and not the expected result of 16.32.
4767-
4768-
[!code-csharp[System.Math.Round.Overload#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/single1.cs#1)]
4769-
[!code-vb[System.Math.Round.Overload#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/single1.vb#1)]
4770-
4767+
4768+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/single1.cs" interactive="try-dotnet" id="Snippet1":::
4769+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/single1.vb" id="Snippet1":::
4770+
47714771
This unexpected result is due to a loss of precision in the conversion of the <xref:System.Single> value to a <xref:System.Double>. Because the resulting <xref:System.Double> value of 16.325000762939453 is not a midpoint value and is greater than 16.325, it is always rounded upward.
47724772
47734773
In many cases, as the example illustrates, the loss of precision can be minimized or eliminated by casting or converting the <xref:System.Single> value to a <xref:System.Decimal>. Note that, because this is a narrowing conversion, it requires using a cast operator or calling a conversion method.
@@ -4847,7 +4847,7 @@ This method uses the default rounding convention of <xref:System.MidpointRoundin
48474847
[!INCLUDE[midpoint-rounding](~/includes/floating-point-equality.md)]
48484848
48494849
<a name="Round1_Example"></a>
4850-
## Example
4850+
## Examples
48514851
48524852
The following example demonstrates the <xref:System.Math.Round%28System.Decimal%29> method. Note that the <xref:System.Decimal> value of 4.5 rounds to 4 rather than 5, because this overload uses the default <xref:System.MidpointRounding.ToEven> convention.
48534853
@@ -4944,9 +4944,11 @@ The following example demonstrates rounding to the nearest integer value.
49444944
</remarks>
49454945
<block subset="none" type="usage">
49464946
<para>Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the <see cref="M:System.Math.Round(System.Double)" /> method may not appear to round midpoint values to the nearest even integer. In the following example, because the floating-point value .1 has no finite binary representation, the first call to the <see cref="M:System.Math.Round(System.Double)" /> method with a value of 11.5 returns 11 instead of 12.
4947-
4948-
[!code-csharp[System.Math.Round#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round/cs/round2.cs#1)]
4949-
[!code-vb[System.Math.Round#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round2.vb#1)]</para>
4947+
4948+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round/cs/round2.cs" interactive="try-dotnet" id="Snippet1":::
4949+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round2.vb" id="Snippet1":::
4950+
4951+
</para>
49504952
</block>
49514953
<altmember cref="M:System.Math.Ceiling(System.Double)" />
49524954
<altmember cref="M:System.Math.Floor(System.Double)" />
@@ -5089,9 +5091,9 @@ See [Midpoint values and rounding conventions](#midpoint-values-and-rounding-con
50895091
## Example
50905092
50915093
The following example displays values returned by the <xref:System.Math.Round%28System.Decimal%29> method, the <xref:System.Math.Round%28System.Decimal%2CSystem.MidpointRounding%29> method with a `mode` argument of <xref:System.MidpointRounding.ToEven>, and the <xref:System.Math.Round%28System.Decimal%2CSystem.MidpointRounding%29> method with a `mode` argument of <xref:System.MidpointRounding.AwayFromZero>.
5092-
5093-
[!code-csharp-interactive[System.Math.Round.Overload#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/midpoint1.cs#5)]
5094-
[!code-vb[System.Math.Round.Overload#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/midpoint1.vb#5)]
5094+
5095+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/midpoint1.cs" interactive="try-dotnet" id="Snippet5":::
5096+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/midpoint1.vb" id="Snippet5":::
50955097
50965098
]]></format>
50975099
</remarks>
@@ -5176,9 +5178,11 @@ The following example rounds double values with two fractional digits to doubles
51765178
<paramref name="digits" /> is less than 0 or greater than 15.</exception>
51775179
<block subset="none" type="usage">
51785180
<para>Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the <see cref="M:System.Math.Round(System.Double,System.Int32)" /> method may not appear to round midpoint values to the nearest even value in the <paramref name="digits" /> decimal position. This is illustrated in the following example, where 2.135 is rounded to 2.13 instead of 2.14. This occurs because internally the method multiplies <paramref name="value" /> by 10<sup>digits</sup>, and the multiplication operation in this case suffers from a loss of precision.
5181+
5182+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round/cs/round3.cs" interactive="try-dotnet" id="Snippet2":::
5183+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round3.vb" id="Snippet2":::
51795184

5180-
[!code-csharp[System.Math.Round#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round/cs/round3.cs#2)]
5181-
[!code-vb[System.Math.Round#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round3.vb#2)]</para>
5185+
</para>
51825186
</block>
51835187
<altmember cref="M:System.Math.Ceiling(System.Double)" />
51845188
<altmember cref="M:System.Math.Floor(System.Double)" />
@@ -5244,8 +5248,8 @@ If the value of the `value` argument is <xref:System.Double.NaN?displayProperty=
52445248
## Example
52455249
The following example displays values returned by the <xref:System.Math.Round%28System.Double%29> method, the <xref:System.Math.Round%28System.Double%2CSystem.MidpointRounding%29> method with a `mode` argument of <xref:System.MidpointRounding.ToEven>, and the <xref:System.Math.Round%28System.Double%2CSystem.MidpointRounding%29> method with a `mode` argument of <xref:System.MidpointRounding.AwayFromZero>.
52465250
5247-
[!code-csharp[System.Math.Round.Overload#6](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/midpoint2.cs#6)]
5248-
[!code-vb[System.Math.Round.Overload#6](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/midpoint2.vb#6)]
5251+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/midpoint2.cs" interactive="try-dotnet" id="Snippet6":::
5252+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/midpoint2.vb" id="Snippet6":::
52495253
52505254
]]></format>
52515255
</remarks>
@@ -5254,8 +5258,10 @@ The following example displays values returned by the <xref:System.Math.Round%28
52545258
<block subset="none" type="usage">
52555259
<para>Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the <see cref="M:System.Math.Round(System.Double,System.MidpointRounding)" /> method may not appear to round midpoint values to the nearest even integer. In the following example, because the floating-point value .1 has no finite binary representation, the first call to the <see cref="M:System.Math.Round(System.Double)" /> method with a value of 11.5 returns 11 instead of 12.
52565260

5257-
[!code-csharp[System.Math.Round#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round/cs/round5.cs#4)]
5258-
[!code-vb[System.Math.Round#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round5.vb#4)]</para>
5261+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round/cs/round5.cs" interactive="try-dotnet" id="Snippet4":::
5262+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round5.vb" id="Snippet4":::
5263+
5264+
</para>
52595265
</block>
52605266
<altmember cref="M:System.Math.Ceiling(System.Double)" />
52615267
<altmember cref="M:System.Math.Floor(System.Double)" />
@@ -5409,8 +5415,8 @@ If the value of the `value` argument is <xref:System.Double.NaN?displayProperty=
54095415
54105416
The following example demonstrates how to use the <xref:System.Math.Round%28System.Double%2CSystem.Int32%2CSystem.MidpointRounding%29> method with the <xref:System.MidpointRounding> enumeration.
54115417
5412-
[!code-csharp[System.Math.Round.Overload#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/mpr.cs#4)]
5413-
[!code-vb[System.Math.Round.Overload#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/mpr.vb#4)]
5418+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/mpr.cs" interactive="try-dotnet-method" id="Snippet4":::
5419+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/mpr.vb" id="Snippet4":::
54145420
54155421
]]></format>
54165422
</remarks>
@@ -5420,9 +5426,11 @@ The following example demonstrates how to use the <xref:System.Math.Round%28Syst
54205426
<paramref name="mode" /> is not a valid value of <see cref="T:System.MidpointRounding" />.</exception>
54215427
<block subset="none" type="usage">
54225428
<para>Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the <see cref="M:System.Math.Round(System.Double,System.Int32,System.MidpointRounding)" /> method may not appear to round midpoint values as specified by the <paramref name="mode" /> parameter. This is illustrated in the following example, where 2.135 is rounded to 2.13 instead of 2.14. This occurs because internally the method multiplies <paramref name="value" /> by 10<sup>digits</sup>, and the multiplication operation in this case suffers from a loss of precision.
5423-
5424-
[!code-csharp[System.Math.Round#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round/cs/round4.cs#3)]
5425-
[!code-vb[System.Math.Round#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round4.vb#3)]</para>
5429+
5430+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.math.round/cs/round4.cs" interactive="try-dotnet-method" id="Snippet3":::
5431+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round4.vb" id="Snippet3":::
5432+
5433+
</para>
54265434
</block>
54275435
<altmember cref="M:System.Math.Ceiling(System.Double)" />
54285436
<altmember cref="M:System.Math.Floor(System.Double)" />

0 commit comments

Comments
 (0)