-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Update example output for .NET (10) #51304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| // <Snippet5> | ||
| using System; | ||
|
|
||
| public class Example9 | ||
| { | ||
| public static void Main() | ||
| { | ||
| // <Snippet5> | ||
| Double value1 = 1 / 3.0; | ||
| Single sValue2 = 1 / 3.0f; | ||
| Double value2 = (Double)sValue2; | ||
| Console.WriteLine($"{value1:R} = {value2:R}: {value1.Equals(value2)}"); | ||
|
|
||
| // The example displays the following output: | ||
| // 0.3333333333333333 = 0.3333333432674408: False | ||
| // </Snippet5> | ||
| } | ||
| } | ||
| // The example displays the following output: | ||
| // 0.33333333333333331 = 0.3333333432674408: False | ||
| // </Snippet5> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| ' Visual Basic .NET Document | ||
| Option Strict On | ||
|
|
||
| ' <Snippet5> | ||
| Module Example10 | ||
| Public Sub Main() | ||
| ' <Snippet5> | ||
| Dim value1 As Double = 1 / 3 | ||
| Dim sValue2 As Single = 1 / 3 | ||
| Dim value2 As Double = CDbl(sValue2) | ||
| Console.WriteLine("{0} = {1}: {2}", value1, value2, value1.Equals(value2)) | ||
|
|
||
| ' The example displays the following output: | ||
| ' 0.3333333333333333 = 0.3333333432674408: False | ||
| ' </Snippet5> | ||
| End Sub | ||
| End Module | ||
| ' The example displays the following output: | ||
| ' 0.33333333333333331 = 0.3333333432674408: False | ||
| ' </Snippet5> | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,20 @@ | ||
| // <Snippet10> | ||
| using System; | ||
|
|
||
| public class Example1 | ||
| { | ||
| public static void Main() | ||
| { | ||
| // <Snippet10> | ||
| float value1 = 10.201438f; | ||
| value1 = (float)Math.Sqrt((float)Math.Pow(value1, 2)); | ||
| float value2 = (float)Math.Pow((float)value1 * 3.51f, 2); | ||
| value2 = ((float)Math.Sqrt(value2)) / 3.51f; | ||
| Console.WriteLine($"{value1} = {value2}: {value1.Equals(value2)}"); | ||
| Console.WriteLine(); | ||
| Console.WriteLine($"{value1:G9} = {value2:G9}"); | ||
|
|
||
| // The example displays the following output on .NET: | ||
| // 10.201438 = 10.201439: False | ||
| // The example displays the following output on .NET Framework: | ||
| // 10.20144 = 10.20144: False | ||
| // </Snippet10> | ||
| } | ||
| } | ||
| // The example displays the following output: | ||
| // 10.20144 = 10.20144: False | ||
| // | ||
| // 10.201438 = 10.2014389 | ||
| // </Snippet10> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,19 @@ | ||
| // <Snippet11> | ||
| using System; | ||
|
|
||
| public class Example2 | ||
| { | ||
| public static void Main() | ||
| { | ||
| // <Snippet11> | ||
| float value1 = .3333333f; | ||
| float value2 = 1.0f / 3; | ||
| int precision = 7; | ||
| value1 = (float)Math.Round(value1, precision); | ||
| value2 = (float)Math.Round(value2, precision); | ||
| Console.WriteLine($"{value1:R} = {value2:R}: {value1.Equals(value2)}"); | ||
|
|
||
| // The example displays the following output: | ||
| // 0.3333333 = 0.3333333: True | ||
| // </Snippet11> | ||
| } | ||
| } | ||
| // The example displays the following output: | ||
| // 0.3333333 = 0.3333333: True | ||
| // </Snippet11> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,10 @@ | ||||||||||||||||||||||||||||||||||||||
| // <Snippet21> | ||||||||||||||||||||||||||||||||||||||
| using System; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public class Example5 | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| public static void Main() | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| // <Snippet21> | ||||||||||||||||||||||||||||||||||||||
| float[] values = { Single.MinValue, -67890.1234f, -12345.6789f, | ||||||||||||||||||||||||||||||||||||||
| 12345.6789f, 67890.1234f, Single.MaxValue, | ||||||||||||||||||||||||||||||||||||||
| Single.NaN, Single.PositiveInfinity, | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -46,98 +46,53 @@ public static void Main() | |||||||||||||||||||||||||||||||||||||
| Console.WriteLine(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // The example displays the following output for conversions performed | ||||||||||||||||||||||||||||||||||||||
| // in a checked context: | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert -3.402823E+38 to Int64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert -3.402823E+38 to UInt64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert -3.402823E+38 to Decimal. | ||||||||||||||||||||||||||||||||||||||
| // -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double) | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64) | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert -67890.13 to UInt64. | ||||||||||||||||||||||||||||||||||||||
| // -67890.13 (Single) --> -67890.12 (Decimal) | ||||||||||||||||||||||||||||||||||||||
| // -67890.13 (Single) --> -67890.125 (Double) | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // -12345.68 (Single) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64) | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert -12345.68 to UInt64. | ||||||||||||||||||||||||||||||||||||||
| // -12345.68 (Single) --> -12345.68 (Decimal) | ||||||||||||||||||||||||||||||||||||||
| // -12345.68 (Single) --> -12345.6787109375 (Double) | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // 12345.68 (Single) --> 12345 (0x0000000000003039) (Int64) | ||||||||||||||||||||||||||||||||||||||
| // 12345.68 (Single) --> 12345 (0x0000000000003039) (UInt64) | ||||||||||||||||||||||||||||||||||||||
| // 12345.68 (Single) --> 12345.68 (Decimal) | ||||||||||||||||||||||||||||||||||||||
| // 12345.68 (Single) --> 12345.6787109375 (Double) | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // 67890.13 (Single) --> 67890 (0x0000000000010932) (Int64) | ||||||||||||||||||||||||||||||||||||||
| // 67890.13 (Single) --> 67890 (0x0000000000010932) (UInt64) | ||||||||||||||||||||||||||||||||||||||
| // 67890.13 (Single) --> 67890.12 (Decimal) | ||||||||||||||||||||||||||||||||||||||
| // 67890.13 (Single) --> 67890.125 (Double) | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert 3.402823E+38 to Int64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert 3.402823E+38 to UInt64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert 3.402823E+38 to Decimal. | ||||||||||||||||||||||||||||||||||||||
| // 3.402823E+38 (Single) --> 3.40282346638529E+38 (Double) | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert NaN to Int64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert NaN to UInt64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert NaN to Decimal. | ||||||||||||||||||||||||||||||||||||||
| // NaN (Single) --> NaN (Double) | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert ∞ to Int64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert ∞ to UInt64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert ∞ to Decimal. | ||||||||||||||||||||||||||||||||||||||
| // ∞ (Single) --> ∞ (Double) | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert -∞ to Int64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert -∞ to UInt64. | ||||||||||||||||||||||||||||||||||||||
| // Unable to convert -∞ to Decimal. | ||||||||||||||||||||||||||||||||||||||
| // -∞ (Single) --> -∞ (Double) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+87
to
+95
|
||||||||||||||||||||||||||||||||||||||
| // Unable to convert ∞ to Int64. | |
| // Unable to convert ∞ to UInt64. | |
| // Unable to convert ∞ to Decimal. | |
| // ∞ (Single) --> ∞ (Double) | |
| // | |
| // Unable to convert -∞ to Int64. | |
| // Unable to convert -∞ to UInt64. | |
| // Unable to convert -∞ to Decimal. | |
| // -∞ (Single) --> -∞ (Double) | |
| // Unable to convert Infinity to Int64. | |
| // Unable to convert Infinity to UInt64. | |
| // Unable to convert Infinity to Decimal. | |
| // Infinity (Single) --> Infinity (Double) | |
| // | |
| // Unable to convert -Infinity to Int64. | |
| // Unable to convert -Infinity to UInt64. | |
| // Unable to convert -Infinity to Decimal. | |
| // -Infinity (Single) --> -Infinity (Double) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,19 @@ | ||
| // <Snippet1> | ||
| using System; | ||
|
|
||
| public class Example6 | ||
| { | ||
| public static void Main() | ||
| { | ||
| // <Snippet1> | ||
| float value1 = 1.163287e-36f; | ||
| float value2 = 9.164234e-25f; | ||
| float result = value1 * value2; | ||
| Console.WriteLine($"{value1} * {value2} = {result}"); | ||
| Console.WriteLine($"{result} = 0: {result.Equals(0.0f)}"); | ||
|
|
||
| // The example displays the following output: | ||
| // 1.163287E-36 * 9.164234E-25 = 0 | ||
| // 0 = 0: True | ||
| // </Snippet1> | ||
| } | ||
| } | ||
| // The example displays the following output: | ||
| // 1.163287E-36 * 9.164234E-25 = 0 | ||
| // 0 = 0: True | ||
| // </Snippet1> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| // <Snippet5> | ||
| using System; | ||
|
|
||
| public class Example8 | ||
| { | ||
| public static void Main() | ||
| { | ||
| // <Snippet5> | ||
| Double value1 = 1 / 3.0; | ||
| Single sValue2 = 1 / 3.0f; | ||
| Double value2 = (Double)sValue2; | ||
| Console.WriteLine($"{value1:R} = {value2:R}: {value1.Equals(value2)}"); | ||
|
|
||
| // The example displays the following output on .NET: | ||
| // 0.3333333333333333 = 0.3333333432674408: False | ||
| // </Snippet5> | ||
| } | ||
| } | ||
| // The example displays the following output: | ||
| // 0.33333333333333331 = 0.3333333432674408: False | ||
| // </Snippet5> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documented output has an extra space after the minus sign ("- 1.0000001"), but the code will print "-1.0000001". Update the output comment so it matches the actual formatted output.