diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison2.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison2.cs
index 327bc18593301..3282246945f96 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison2.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison2.cs
@@ -1,21 +1,20 @@
-//
using System;
public class Example1
{
public static void Main()
{
+ //
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
+ //
}
}
-// The example displays the following output:
-// 10.20144 = 10.20144: False
-//
-// 10.201438 = 10.2014389
-//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison3.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison3.cs
index b5d19a7fb0dd5..4f82ff0c2ea5c 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison3.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison3.cs
@@ -1,18 +1,19 @@
-//
using System;
public class Example2
{
public static void Main()
{
+ //
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
+ //
}
}
-// The example displays the following output:
-// 0.3333333 = 0.3333333: True
-//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison4.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison4.cs
index 4513de285b1f8..ded666dc51494 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison4.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/comparison4.cs
@@ -1,8 +1,8 @@
-//
using System;
public class Example3
{
+ //
public static void Main()
{
float one1 = .1f * 10;
@@ -13,7 +13,7 @@ public static void Main()
Console.WriteLine($"{one1:R} = {one2:R}: {one1.Equals(one2)}");
Console.WriteLine($"{one1:R} is approximately equal to {one2:R}: " +
$"{IsApproximatelyEqual(one1, one2, .000001f)}");
-
+
float negativeOne1 = -1 * one1;
float negativeOne2 = -1 * one2;
@@ -34,16 +34,18 @@ static bool IsApproximatelyEqual(float value1, float value2, float epsilon)
else if (Double.IsInfinity(value2) | Double.IsNaN(value2))
return value1.Equals(value2);
- // Handle zero to avoid division by zero
+ // Handle zero to avoid division by zero.
double divisor = Math.Max(value1, value2);
if (divisor.Equals(0))
divisor = Math.Min(value1, value2);
return Math.Abs((value1 - value2) / divisor) <= epsilon;
}
+
+ // The example displays the following output on .NET:
+ // 1 = 1.0000001: False
+ // 1 is approximately equal to 1.0000001: True
+ // -1 = -1.0000001: False
+ // -1 is approximately equal to -1.0000001: True
+ //
}
-// The example displays the following output:
-// 1 = 1.00000012: False
-// 1 is approximately equal to 1.00000012: True
-// -1 is approximately equal to -1.00000012: True
-//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/convert2.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/convert2.cs
index 6115fe2068629..d9a17fb336cf5 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/convert2.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/convert2.cs
@@ -1,10 +1,10 @@
-//
using System;
public class Example5
{
public static void Main()
{
+ //
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)
+ //
}
}
-// 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 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)
-// The example displays the following output for conversions performed
-// in an unchecked context:
-// -3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// -3.402823E+38 (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
-// Unable to convert -3.402823E+38 to Decimal.
-// -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double)
-//
-// -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
-// -67890.13 (Single) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
-// -67890.13 (Single) --> -67890.12 (Decimal)
-// -67890.13 (Single) --> -67890.125 (Double)
-//
-// -12345.68 (Single) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
-// -12345.68 (Single) --> 18446744073709539271 (0xFFFFFFFFFFFFCFC7) (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)
-//
-// 3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// 3.402823E+38 (Single) --> 0 (0x0000000000000000) (UInt64)
-// Unable to convert 3.402823E+38 to Decimal.
-// 3.402823E+38 (Single) --> 3.40282346638529E+38 (Double)
-//
-// NaN (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// NaN (Single) --> 0 (0x0000000000000000) (UInt64)
-// Unable to convert NaN to Decimal.
-// NaN (Single) --> NaN (Double)
-//
-// Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// Infinity (Single) --> 0 (0x0000000000000000) (UInt64)
-// Unable to convert Infinity to Decimal.
-// Infinity (Single) --> Infinity (Double)
-//
-// -Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// -Infinity (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
-// Unable to convert -Infinity to Decimal.
-// -Infinity (Single) --> -Infinity (Double)
-//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/exceptional1.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/exceptional1.cs
index 50d367bb20202..5f914834675b9 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/exceptional1.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/exceptional1.cs
@@ -1,18 +1,19 @@
-//
using System;
public class Example6
{
public static void Main()
{
+ //
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
+ //
}
}
-// The example displays the following output:
-// 1.163287E-36 * 9.164234E-25 = 0
-// 0 = 0: True
-//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/exceptional2.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/exceptional2.cs
index 6f2e02dfb0df1..6c0cf45b151f6 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/exceptional2.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/exceptional2.cs
@@ -1,10 +1,10 @@
-//
using System;
public class Example7
{
public static void Main()
{
+ //
float value1 = 3.065e35f;
float value2 = 6.9375e32f;
float result = value1 * value2;
@@ -16,13 +16,13 @@ public static void Main()
result = value1 * value2;
Console.WriteLine($"PositiveInfinity: {Single.IsPositiveInfinity(result)}");
Console.WriteLine($"NegativeInfinity: {Single.IsNegativeInfinity(result)}");
+
+ // The example displays the following output:
+ // PositiveInfinity: True
+ // NegativeInfinity: False
+ //
+ // PositiveInfinity: False
+ // NegativeInfinity: True
+ //
}
}
-
-// The example displays the following output:
-// PositiveInfinity: True
-// NegativeInfinity: False
-//
-// PositiveInfinity: False
-// NegativeInfinity: True
-//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist1.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist1.cs
index badd8b5697673..c42b4fc898f78 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist1.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist1.cs
@@ -1,16 +1,17 @@
-//
using System;
-public class Example8
+public class Example9
{
public static void Main()
{
+ //
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
+ //
}
}
-// The example displays the following output:
-// 0.33333333333333331 = 0.3333333432674408: False
-//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist3.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist3.cs
index ac73f8afb67be..d05493e8b9369 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist3.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist3.cs
@@ -1,7 +1,7 @@
-//
+//
using System;
-public class Example9
+public class PrecisionList3Example
{
public static void Main()
{
@@ -17,10 +17,9 @@ public static void Main()
Console.WriteLine($"The sum of the values ({total}) does not equal the total ({result}).");
}
}
-// The example displays the following output:
-// The sum of the values (27.65) does not equal the total (27.65).
-//
-// If the index items in the Console.WriteLine statement are changed to {0:R},
-// the example displays the following output:
-// The sum of the values (27.6500015) does not equal the total (27.65).
+
+// The example displays the following output on .NET:
+// The sum of the values (27.650002) does not equal the total (27.65).
+// The example displays the following output on .NET Framework:
+// The sum of the values (27.65) does not equal the total (27.65).
//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist4a.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist4a.cs
index cb1dcc9201b29..299b38273f907 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist4a.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/precisionlist4a.cs
@@ -26,7 +26,7 @@ public static void Main()
for (int ctr = 0; ctr < values.Length; ctr++)
Console.WriteLine($"{values[ctr]} {(values[ctr].Equals(restoredValues[ctr]) ? "=" : "<>")} {restoredValues[ctr]}");
- // The example displays the following output:
+ // The example displays the following output on .NET Framework:
// 2.882883 <> 2.882883
// 0.3333333 <> 0.3333333
// 3.141593 <> 3.141593
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/representation1.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/representation1.cs
index 144b29306b7cb..6ea38e68a79ca 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/representation1.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/representation1.cs
@@ -17,5 +17,5 @@ public static void Main()
}
// The example displays the following output:
// .2 * 10: 2
-// .2 Added 10 times: 2.00000024
+// .2 Added 10 times: 2.0000002
//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/representation2.cs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/representation2.cs
index 14a18d2329639..a3a072bdb3b77 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/representation2.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/csharp/representation2.cs
@@ -10,6 +10,7 @@ public static void Main()
Console.WriteLine($"{value} + {additional} = {value + additional}");
}
}
+
// The example displays the following output:
// 123.456 + 1.401298E-30 = 123.456
//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/Project.fsproj b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/Project.fsproj
new file mode 100644
index 0000000000000..55b62720a6340
--- /dev/null
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/Project.fsproj
@@ -0,0 +1,22 @@
+
+
+ Library
+ net10.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison1.fs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison1.fs
index ea11b42f152e0..bec80ce7f3c7e 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison1.fs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison1.fs
@@ -6,4 +6,4 @@ let value2 = 1f / 3f
printfn $"{value1:R} = {value2:R}: {value1.Equals value2}"
// The example displays the following output:
// 0.3333333 = 0.333333343: False
-//
\ No newline at end of file
+//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison2.fs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison2.fs
index 9d626dd544633..451e5a5c46027 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison2.fs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison2.fs
@@ -1,17 +1,17 @@
module comparison2
//
-let value1 =
+let value1 =
10.201438f ** 2f
|> sqrt
let value2 =
((value1 * 3.51f) ** 2f |> sqrt) / 3.51f
-printfn $"{value1} = {value2}: {value1.Equals value2}\n"
-printfn $"{value1:G9} = {value2:G9}"
-// The example displays the following output:
+printfn $"{value1} = {value2}: {value1.Equals value2}"
+
+// 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
-//
-// 10.201438 = 10.2014389
-//
\ No newline at end of file
+//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison4.fs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison4.fs
index 8bcc671e48d57..c64ce04e3dfe7 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison4.fs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/comparison4.fs
@@ -5,7 +5,7 @@ open System
let isApproximatelyEqual value1 value2 epsilon =
// If they are equal anyway, just return True.
- if value1.Equals value2 then
+ if value1.Equals value2 then
true
// Handle NaN, Infinity.
elif Single.IsInfinity value1 || Single.IsNaN value1 then
@@ -15,11 +15,11 @@ let isApproximatelyEqual value1 value2 epsilon =
else
// Handle zero to avoid division by zero
let divisor = max value1 value2
- let divisor =
+ let divisor =
if divisor.Equals 0 then
min value1 value2
else divisor
- abs (value1 - value2) / divisor <= epsilon
+ abs (value1 - value2) / divisor <= epsilon
let one1 = 0.1f * 10f
@@ -28,8 +28,8 @@ for _ = 1 to 10 do
one2 <- one2 + 0.1f
printfn $"{one1:R} = {one2:R}: {one1.Equals one2}"
-printfn $"{one1:R} is approximately equal to {one2:R}: {isApproximatelyEqual one1 one2 0.000001f}"
+printfn $"{one1:R} is approximately equal to {one2:R}: {isApproximatelyEqual one1 one2 0.000001f}"
// The example displays the following output:
-// 1 = 1.00000012: False
-// 1 is approximately equal to 1.00000012: True
-//
\ No newline at end of file
+// 1 = 1.0000001: False
+// 1 is approximately equal to 1.0000001: True
+//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/convert2.fs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/convert2.fs
index 5bcf93a4fcd11..0556232e8922c 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/convert2.fs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/convert2.fs
@@ -4,7 +4,7 @@
open System
open Checked
-let values =
+let values =
[ Single.MinValue; -67890.1234f; -12345.6789f
12345.6789f; 67890.1234f; Single.MaxValue
Single.NaN; Single.PositiveInfinity
@@ -29,6 +29,7 @@ for value in values do
let dblValue = double value
printfn $"{value} ({value.GetType().Name}) --> {dblValue} ({dblValue.GetType().Name})\n"
+
// The example displays the following output for conversions performed
// in a checked context:
// Unable to convert -3.402823E+38 to Int64.
@@ -66,59 +67,13 @@ for value in values do
// Unable to convert NaN to Decimal.
// NaN (Single) --> NaN (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)
-// The example displays the following output for conversions performed
-// in an unchecked context:
-// -3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// -3.402823E+38 (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
-// Unable to convert -3.402823E+38 to Decimal.
-// -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double)
-//
-// -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
-// -67890.13 (Single) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
-// -67890.13 (Single) --> -67890.12 (Decimal)
-// -67890.13 (Single) --> -67890.125 (Double)
-//
-// -12345.68 (Single) --> -12345 (0xFFFFFFFFFFFFCFC7) (Int64)
-// -12345.68 (Single) --> 18446744073709539271 (0xFFFFFFFFFFFFCFC7) (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)
-//
-// 3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// 3.402823E+38 (Single) --> 0 (0x0000000000000000) (UInt64)
-// Unable to convert 3.402823E+38 to Decimal.
-// 3.402823E+38 (Single) --> 3.40282346638529E+38 (Double)
-//
-// NaN (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// NaN (Single) --> 0 (0x0000000000000000) (UInt64)
-// Unable to convert NaN to Decimal.
-// NaN (Single) --> NaN (Double)
-//
-// Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// Infinity (Single) --> 0 (0x0000000000000000) (UInt64)
-// Unable to convert Infinity to Decimal.
-// Infinity (Single) --> Infinity (Double)
+// Unable to convert ∞ to Int64.
+// Unable to convert ∞ to UInt64.
+// Unable to convert ∞ to Decimal.
+// ∞ (Single) --> ∞ (Double)
//
-// -Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-// -Infinity (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
-// Unable to convert -Infinity to Decimal.
-// -Infinity (Single) --> -Infinity (Double)
-//
\ No newline at end of file
+// Unable to convert -∞ to Int64.
+// Unable to convert -∞ to UInt64.
+// Unable to convert -∞ to Decimal.
+// -∞ (Single) --> -∞ (Double)
+//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/exceptional1.fs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/exceptional1.fs
index f4ff254e403af..489213da8470f 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/exceptional1.fs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/exceptional1.fs
@@ -6,7 +6,8 @@ let value2 = 9.164234e-25f
let result = value1 * value2
printfn $"{value1} * {value2} = {result}"
printfn $"{result} = 0: {result.Equals(0f)}"
+
// The example displays the following output:
// 1.163287E-36 * 9.164234E-25 = 0
// 0 = 0: True
-//
\ No newline at end of file
+//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist1.fs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist1.fs
index d727f9fbd18f3..1ebcff2eae33d 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist1.fs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist1.fs
@@ -5,6 +5,7 @@ let value1 = 1. / 3.
let sValue2 = 1f / 3f
let value2 = double sValue2
printfn $"{value1:R} = {value2:R}: {value1.Equals value2}"
-// The example displays the following output:
-// 0.33333333333333331 = 0.3333333432674408: False
-//
\ No newline at end of file
+
+// The example displays the following output on .NET:
+// 0.3333333333333333 = 0.3333333432674408: False
+//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist3.fs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist3.fs
index a9ed62e7ebc17..5d888f85833cf 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist3.fs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist3.fs
@@ -10,11 +10,10 @@ for value in values do
if total.Equals result then
printfn "The sum of the values equals the total."
else
- printfn "The sum of the values ({total}) does not equal the total ({result})."
-// The example displays the following output:
-// The sum of the values (27.65) does not equal the total (27.65).
-//
-// If the index items in the Console.WriteLine statement are changed to {0:R},
-// the example displays the following output:
-// The sum of the values (27.6500015) does not equal the total (27.65).
-//
\ No newline at end of file
+ printfn $"The sum of the values ({total}) does not equal the total ({result})."
+
+// The example displays the following output on .NET:
+// The sum of the values (27.650002) does not equal the total (27.65).
+// The example displays the following output on .NET Framework:
+// The sum of the values (27.65) does not equal the total (27.65).
+//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist4a.fs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist4a.fs
index 1893a42186aa7..c45aeff493576 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist4a.fs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/precisionlist4a.fs
@@ -20,9 +20,9 @@ let restoredValues =
for i = 0 to values.Length - 1 do
printfn $"""{values[i]} {if values[i].Equals restoredValues[i] then "=" else "<>"} {restoredValues[i]}"""
-
-// The example displays the following output:
+
+// The example displays the following output on .NET Framework:
// 2.882883 <> 2.882883
// 0.3333333 <> 0.3333333
// 3.141593 <> 3.141593
-//
\ No newline at end of file
+//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/representation1.fs b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/representation1.fs
index 5a93ebb1e182d..e29c56539bc9b 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/representation1.fs
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/fsharp/representation1.fs
@@ -9,7 +9,8 @@ for _ = 1 to 10 do
printfn $".2 * 10: {result1:R}"
printfn $".2 Added 10 times: {result2:R}"
+
// The example displays the following output:
// .2 * 10: 2
-// .2 Added 10 times: 2.00000024
-//
\ No newline at end of file
+// .2 Added 10 times: 2.0000002
+//
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/PrecisionList4a.vb b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/PrecisionList4a.vb
index 3a60065123303..7e9692ec3f73c 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/PrecisionList4a.vb
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/PrecisionList4a.vb
@@ -1,11 +1,11 @@
' Visual Basic .NET Document
Option Strict On
-'
Imports System.IO
Module Example11
Public Sub Main()
+ '
Dim sw As New StreamWriter(".\Singles.dat")
Dim values() As Single = {3.2 / 1.11, 1.0 / 3, CSng(Math.PI)}
For ctr As Integer = 0 To values.Length - 1
@@ -27,10 +27,11 @@ Module Example11
restoredValues(ctr),
If(values(ctr).Equals(restoredValues(ctr)), "=", "<>"))
Next
+
+ ' The example displays the following output on .NET Framework:
+ ' 2.882883 <> 2.882883
+ ' 0.3333333 <> 0.3333333
+ ' 3.141593 <> 3.141593
+ '
End Sub
End Module
-' The example displays the following output:
-' 2.882883 <> 2.882883
-' 0.3333333 <> 0.3333333
-' 3.141593 <> 3.141593
-'
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/comparison2.vb b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/comparison2.vb
index f667ec52ed7c7..d56467bdaa7b9 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/comparison2.vb
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/comparison2.vb
@@ -1,21 +1,20 @@
' Visual Basic .NET Document
Option Strict On
-'
Module Example2
Public Sub Main()
+ '
Dim value1 As Single = 10.201438
value1 = CSng(Math.Sqrt(CSng(Math.Pow(value1, 2))))
Dim value2 As Single = CSng(Math.Pow(value1 * CSng(3.51), 2))
value2 = CSng(Math.Sqrt(value2) / CSng(3.51))
Console.WriteLine("{0} = {1}: {2}",
value1, value2, value1.Equals(value2))
- Console.WriteLine()
- Console.WriteLine("{0:G9} = {1:G9}", value1, value2)
+
+ ' 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
+ '
End Sub
End Module
-' The example displays the following output:
-' 10.20144 = 10.20144: False
-'
-' 10.201438 = 10.2014389
-'
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/comparison4.vb b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/comparison4.vb
index d474f3cc4f57e..f05888920eaf5 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/comparison4.vb
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/comparison4.vb
@@ -1,8 +1,8 @@
' Visual Basic .NET Document
Option Strict On
-'
Module Example4
+ '
Public Sub Main()
Dim one1 As Single = 0.1 * 10
Dim one2 As Single = 0
@@ -27,7 +27,7 @@ Module Example4
Return value1.Equals(value2)
End If
- ' Handle zero to avoid division by zero
+ ' Handle zero to avoid division by zero.
Dim divisor As Single = Math.Max(value1, value2)
If divisor.Equals(0) Then
divisor = Math.Min(value1, value2)
@@ -35,8 +35,9 @@ Module Example4
Return Math.Abs(value1 - value2) / divisor <= epsilon
End Function
+
+ ' The example displays the following output:
+ ' 1 = 1.0000001: False
+ ' 1 is approximately equal to 1.0000001: True
+ '
End Module
-' The example displays the following output:
-' 1 = 1.00000012: False
-' 1 is approximately equal to 1.00000012: True
-'
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/convert2.vb b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/convert2.vb
index 402ccb91d1f9e..c2192caf9cd16 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/convert2.vb
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/convert2.vb
@@ -42,6 +42,7 @@ Module Example6
Next
End Sub
End Module
+
' The example displays the following output for conversions performed
' in a checked context:
' Unable to convert -3.402823E+38 to Int64.
@@ -79,59 +80,13 @@ End Module
' Unable to convert NaN to Decimal.
' NaN (Single) --> NaN (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)
-' The example displays the following output for conversions performed
-' in an unchecked context:
-' -3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-' -3.402823E+38 (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
-' Unable to convert -3.402823E+38 to Decimal.
-' -3.402823E+38 (Single) --> -3.40282346638529E+38 (Double)
-'
-' -67890.13 (Single) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
-' -67890.13 (Single) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
-' -67890.13 (Single) --> -67890.12 (Decimal)
-' -67890.13 (Single) --> -67890.125 (Double)
-'
-' -12345.68 (Single) --> -12346 (0xFFFFFFFFFFFFCFC6) (Int64)
-' -12345.68 (Single) --> 18446744073709539270 (0xFFFFFFFFFFFFCFC6) (UInt64)
-' -12345.68 (Single) --> -12345.68 (Decimal)
-' -12345.68 (Single) --> -12345.6787109375 (Double)
-'
-' 12345.68 (Single) --> 12346 (0x000000000000303A) (Int64)
-' 12345.68 (Single) --> 12346 (0x000000000000303A) (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)
-'
-' 3.402823E+38 (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-' 3.402823E+38 (Single) --> 0 (0x0000000000000000) (UInt64)
-' Unable to convert 3.402823E+38 to Decimal.
-' 3.402823E+38 (Single) --> 3.40282346638529E+38 (Double)
-'
-' NaN (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-' NaN (Single) --> 0 (0x0000000000000000) (UInt64)
-' Unable to convert NaN to Decimal.
-' NaN (Single) --> NaN (Double)
-'
-' Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-' Infinity (Single) --> 0 (0x0000000000000000) (UInt64)
-' Unable to convert Infinity to Decimal.
-' Infinity (Single) --> Infinity (Double)
+' Unable to convert ∞ to Int64.
+' Unable to convert ∞ to UInt64.
+' Unable to convert ∞ to Decimal.
+' ∞ (Single) --> ∞ (Double)
'
-' -Infinity (Single) --> -9223372036854775808 (0x8000000000000000) (Int64)
-' -Infinity (Single) --> 9223372036854775808 (0x8000000000000000) (UInt64)
-' Unable to convert -Infinity to Decimal.
-' -Infinity (Single) --> -Infinity (Double)
+' Unable to convert -∞ to Int64.
+' Unable to convert -∞ to UInt64.
+' Unable to convert -∞ to Decimal.
+' -∞ (Single) --> -∞ (Double)
'
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/precisionlist1.vb b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/precisionlist1.vb
index 1f554965ce70c..a581242965627 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/precisionlist1.vb
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/precisionlist1.vb
@@ -1,16 +1,13 @@
-' Visual Basic .NET Document
-Option Strict On
-
-'
-Module Example9
+Module Example10
Public Sub Main()
+ '
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
+ '
End Sub
End Module
-' The example displays the following output:
-' 0.33333333333333331 = 0.3333333432674408: False
-'
-
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/precisionlist3.vb b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/precisionlist3.vb
index 623f9bc328ada..c859ea1c29a2f 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/precisionlist3.vb
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/precisionlist3.vb
@@ -1,9 +1,9 @@
' Visual Basic .NET Document
Option Strict On
-'
-Module Example10
+Module PrecisionList3
Public Sub Main()
+ '
Dim values() As Single = {10.01, 2.88, 2.88, 2.88, 9.0}
Dim result As Single = 27.65
Dim total As Single
@@ -13,15 +13,13 @@ Module Example10
If total.Equals(result) Then
Console.WriteLine("The sum of the values equals the total.")
Else
- Console.WriteLine("The sum of the values ({0}) does not equal the total ({1}).",
- total, result)
+ Console.WriteLine($"The sum of the values ({total}) does not equal the total ({result}).")
End If
End Sub
+
+ ' The example displays the following output on .NET:
+ ' The sum of the values (27.650002) does not equal the total (27.65).
+ ' The example displays the following output on .NET Framework:
+ ' The sum of the values (27.65) does not equal the total (27.65).
+ '
End Module
-' The example displays the following output:
-' The sum of the values (27.65) does not equal the total (27.65).
-'
-' If the index items in the Console.WriteLine statement are changed to {0:R},
-' the example displays the following output:
-' The sum of the values (27.639999999999997) does not equal the total (27.64).
-'
diff --git a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/representation1.vb b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/representation1.vb
index 48c28b62606b1..fe77569fa9a02 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/representation1.vb
+++ b/docs/fundamentals/runtime-libraries/snippets/System/Single/Overview/vb/representation1.vb
@@ -14,8 +14,9 @@ Module Example13
Console.WriteLine(".2 Added 10 times: {0:R}", result2)
End Sub
End Module
+
' The example displays the following output:
' .2 * 10: 2
-' .2 Added 10 times: 2.00000024
+' .2 Added 10 times: 2.0000002
'
diff --git a/docs/fundamentals/runtime-libraries/system-single.md b/docs/fundamentals/runtime-libraries/system-single.md
index 9bc7c58c523f4..dfda8ed0f1311 100644
--- a/docs/fundamentals/runtime-libraries/system-single.md
+++ b/docs/fundamentals/runtime-libraries/system-single.md
@@ -1,7 +1,7 @@
---
title: System.Single struct
description: Learn about the System.Single struct.
-ms.date: 12/31/2023
+ms.date: 01/23/2026
dev_langs:
- CSharp
- FSharp
@@ -41,13 +41,13 @@ All floating-point numbers have a limited number of significant digits, which al
The limited precision of a floating-point number has several consequences:
-- Two floating-point numbers that appear equal for a particular precision might not compare equal because their least significant digits are different. In the following example, a series of numbers are added together, and their total is compared with their expected total. Although the two values appear to be the same, a call to the `Equals` method indicates that they are not.
+- Two floating-point numbers that appear equal for a particular precision might not compare equal because their least significant digits are different. In the following example, a series of numbers are added together, and their total is compared with their expected total. A call to the `Equals` method indicates that the values aren't equal.
:::code language="csharp" source="./snippets/System/Single/Overview/csharp/precisionlist3.cs" id="Snippet6":::
:::code language="fsharp" source="./snippets/System/Single/Overview/fsharp/precisionlist3.fs" id="Snippet6":::
:::code language="vb" source="./snippets/System/Single/Overview/vb/precisionlist3.vb" id="Snippet6":::
- If you change the format items in the statement from `{0}` and `{1}` to `{0:R}` and `{1:R}` to display all significant digits of the two values, it is clear that the two values are unequal because of a loss of precision during the addition operations. In this case, the issue can be resolved by calling the method to round the values to the desired precision before performing the comparison.
+ The two values are unequal because of a loss of precision during the addition operations. In this case, the issue can be resolved by calling the method to round the values to the desired precision before performing the comparison.
- A mathematical or comparison operation that uses a floating-point number might not yield the same result if a decimal number is used, because the binary floating-point number might not equal the decimal number. A previous example illustrated this by displaying the result of multiplying .3 by 10 and adding .3 to .3 nine times.
@@ -79,7 +79,7 @@ To be considered equal, two values must represent identical
:::code language="fsharp" source="./snippets/System/Single/Overview/fsharp/comparison1.fs" id="Snippet9":::
:::code language="vb" source="./snippets/System/Single/Overview/vb/comparison1.vb" id="Snippet9":::
-Calculated values that follow different code paths and that are manipulated in different ways often prove to be unequal. In the following example, one value is squared, and then the square root is calculated to restore the original value. A second is multiplied by 3.51 and squared before the square root of the result is divided by 3.51 to restore the original value. Although the two values appear to be identical, a call to the method indicates that they are not equal. Using the "G9" standard format string to return a result string that displays all the significant digits of each value shows that the second value is .0000000000001 less than the first.
+Calculated values that follow different code paths and that are manipulated in different ways often prove to be unequal. In the following example, one value is squared, and then the square root is calculated to restore the original value. A second is multiplied by 3.51 and squared before the square root of the result is divided by 3.51 to restore the original value. Although the two values appear to be identical, a call to the method indicates that they are not equal.
:::code language="csharp" source="./snippets/System/Single/Overview/csharp/comparison2.cs" id="Snippet10":::
:::code language="fsharp" source="./snippets/System/Single/Overview/fsharp/comparison2.fs" id="Snippet10":::
@@ -93,14 +93,14 @@ In cases where a loss of precision is likely to affect the result of a compariso
:::code language="fsharp" source="./snippets/System/Single/Overview/fsharp/comparison3.fs" id="Snippet11":::
:::code language="vb" source="./snippets/System/Single/Overview/vb/comparison3.vb" id="Snippet11":::
- The problem of precision still applies to rounding of midpoint values. For more information, see the method.
+ The problem of precision still applies to rounding of midpoint values. For more information, see the method.
- Test for approximate equality instead of equality. This technique requires that you define either an absolute amount by which the two values can differ but still be equal, or that you define a relative amount by which the smaller value can diverge from the larger value.
> [!WARNING]
> is sometimes used as an absolute measure of the distance between two values when testing for equality. However, measures the smallest possible value that can be added to, or subtracted from, a whose value is zero. For most positive and negative values, the value of is too small to be detected. Therefore, except for values that are zero, we do not recommend its use in tests for equality.
- The following example uses the latter approach to define an `IsApproximatelyEqual` method that tests the relative difference between two values. It also contrasts the result of calls to the `IsApproximatelyEqual` method and the method.
+ The following example uses the latter approach to define an `IsApproximatelyEqual` method that tests the relative difference between two values. It also contrasts the result of calls to the `IsApproximatelyEqual` method and the method.
:::code language="csharp" source="./snippets/System/Single/Overview/csharp/comparison4.cs" id="Snippet12":::
:::code language="fsharp" source="./snippets/System/Single/Overview/fsharp/comparison4.fs" id="Snippet12":::
@@ -122,7 +122,7 @@ Operations with floating-point values do not throw exceptions, unlike operations
:::code language="fsharp" source="./snippets/System/Single/Overview/fsharp/exceptional2.fs" id="Snippet2":::
:::code language="vb" source="./snippets/System/Single/Overview/vb/exceptional2.vb" id="Snippet2":::
- also results from a division by zero with a positive dividend, and results from a division by zero with a negative dividend.
+ also results from a division by zero with a positive dividend, and results from a division by zero with a negative dividend.
- If a floating-point operation is invalid, the result of the operation is . For example, results from the following operations:
@@ -134,14 +134,14 @@ Operations with floating-point values do not throw exceptions, unlike operations
The structure does not define any explicit or implicit conversion operators; instead, conversions are implemented by the compiler.
-The following table lists the possible conversions of a value of the other primitive numeric types to a value, It also indicates whether the conversion is widening or narrowing and whether the resulting may have less precision than the original value.
+The following table lists the possible conversions of a value of the other primitive numeric types to a value. It also indicates whether the conversion is widening or narrowing and whether the resulting may have less precision than the original value.
-|Conversion from|Widening/narrowing|Possible loss of precision|
-|---------------------|-------------------------|--------------------------------|
-||Widening|No|
+| Conversion from | Widening/narrowing | Possible loss of precision |
+|---------------------|--------------------|----------------------------|
+| | Widening | No |
||Widening
Note that C# requires a cast operator.|Yes. supports 29 decimal digits of precision; supports 9.|
||Narrowing; out-of-range values are converted to or .|Yes. supports 17 decimal digits of precision; supports 9.|
-||Widening|No|
+| | Widening | No |
||Widening|Yes. supports 10 decimal digits of precision; supports 9.|
||Widening|Yes. supports 19 decimal digits of precision; supports 9.|
||Widening|No|
@@ -163,10 +163,10 @@ The conversion of a value to a is a wi
The conversion of a value to a value of any primitive numeric data type other than a is a narrowing conversion and requires a cast operator (in C#) or a conversion method (in Visual Basic). Values that are outside the range of the target data type, which are defined by the target type's `MinValue` and `MaxValue` properties, behave as shown in the following table.
-|Target type|Result|
-|-----------------|------------|
-|Any integral type|An exception if the conversion occurs in a checked context.
If the conversion occurs in an unchecked context (the default in C#), the conversion operation succeeds but the value overflows.|
-||An exception,|
+| Target type | Result |
+|-----------------------|-----------------------------------------------|
+| Any integral type | An exception if the conversion occurs in a checked context.
If the conversion occurs in an unchecked context (the default in C#), the conversion operation succeeds but the value overflows. |
+| | An exception. |
In addition, , , and throw an for conversions to integers in a checked context, but these values overflow when converted to integers in an unchecked context. For conversions to , they always throw an . For conversions to , they convert to , , and , respectively.
@@ -197,7 +197,7 @@ The structure and related types provide methods to perform
You can perform other mathematical operations by calling `static` (`Shared` in Visual Basic) methods in the class. These include additional methods commonly used for arithmetic (such as , , and ), geometry (such as and ), and calculus (such as ). In all cases, the value is converted to a .
- You can also manipulate the individual bits in a value. The method returns its bit pattern in a byte array. By passing that byte array to the method, you can also preserve the value's bit pattern in a 32-bit integer.
+ You can also manipulate the individual bits in a value. The method returns its bit pattern in a byte array. By passing that byte array to the method, you can also preserve the value's bit pattern in a 32-bit integer.
- **Rounding**. Rounding is often used as a technique for reducing the impact of differences between values caused by problems of floating-point representation and precision. You can round a value by calling the method. However, note that the value is converted to a before the method is called, and the conversion can involve a loss of precision.
@@ -209,12 +209,12 @@ The structure and related types provide methods to perform
However, conversion of 32-bit and 64-bit integer values can involve a loss of precision. The following table lists the differences in precision for 32-bit, 64-bit, and types:
- |Type|Maximum precision (in decimal digits)|Internal precision (in decimal digits)|
- |----------|---------------------------------------------|----------------------------------------------|
- ||15|17|
- | and |10|10|
- | and |19|19|
- ||7|9|
+ | Type | Maximum precision (decimal digits) | Internal precision (decimal digits) |
+ |----------------------|------------------------------------|-------------------------------------|
+ | | 15 | 17 |
+ | and | 10 | 10 |
+ | and | 19 | 19 |
+ | | 7 | 9 |
The problem of precision most frequently affects values that are converted to values. In the following example, two values produced by identical division operations are unequal, because one of the values is a single-precision floating point value that is converted to a .