Skip to content

Commit 6f78b67

Browse files
committed
Updating the samples to cover Sign(IntPtr) and SinCos(double)
1 parent c727367 commit 6f78b67

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

samples/snippets/csharp/VS_Snippets_CLR/math.sign/CS/sign.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static void Main()
1515
float xSingle1 = 0.0f;
1616
double xDouble1 = 6.0;
1717
Decimal xDecimal1 = -7m;
18+
nint xIntPtr1 = 8;
1819

1920
// The following type is not CLS-compliant.
2021
sbyte xSbyte1 = -101;
@@ -27,6 +28,7 @@ public static void Main()
2728
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)));
2829
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)));
2930
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)));
31+
Console.WriteLine(str, "IntPtr", xIntPtr1, Test(Math.Sign(xIntPtr1)));
3032

3133
Console.WriteLine($"{nl}The following type is not CLS-compliant.");
3234
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)));
@@ -53,6 +55,7 @@ public static string Test(int compare)
5355
Single : 0 is equal to zero.
5456
Double : 6 is greater than zero.
5557
Decimal: -7 is less than zero.
58+
IntPtr: 8 is greater than zero.
5659
5760
The following type is not CLS-compliant.
5861
SByte : -101 is less than zero.

samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/CS/sincos.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ public static void Main()
99
{
1010
Console.WriteLine(
1111
"This example of trigonometric " +
12-
"Math.Sin( double ) and Math.Cos( double )\n" +
12+
"Math.Sin( double ), Math.Cos( double ), and Math.SinCos( double )\n" +
1313
"generates the following output.\n" );
1414
Console.WriteLine(
1515
"Convert selected values for X to radians \n" +
1616
"and evaluate these trigonometric identities:" );
1717
Console.WriteLine( " sin^2(X) + cos^2(X) == 1\n" +
1818
" sin(2 * X) == 2 * sin(X) * cos(X)" );
1919
Console.WriteLine( " cos(2 * X) == cos^2(X) - sin^2(X)" );
20+
Console.WriteLine( " cos(2 * X) == cos^2(X) - sin^2(X)" );
2021

2122
UseSineCosine(15.0);
2223
UseSineCosine(30.0);
@@ -30,6 +31,32 @@ public static void Main()
3031

3132
UseTwoAngles(15.0, 30.0);
3233
UseTwoAngles(30.0, 45.0);
34+
35+
Console.WriteLine(
36+
"\nWhen you have calls to sin(X) and cos(X) they \n" +
37+
"can be replaced with a single call to sincos(x):" );
38+
39+
UseCombinedSinCosine(15.0);
40+
UseCombinedSinCosine(30.0);
41+
UseCombinedSinCosine(45.0);
42+
}
43+
44+
// Evaluate trigonometric identities with a given angle.
45+
static void UseCombinedSineCosine(double degrees)
46+
{
47+
double angle = Math.PI * degrees / 180.0;
48+
(double sinAngle, double cosAngle) = Math.SinCos(angle);
49+
50+
// Evaluate sin^2(X) + cos^2(X) == 1.
51+
Console.WriteLine(
52+
"\n Math.SinCos({0} deg) == ({1:E16}, {2:E16})",
53+
degrees, sinAngle, cosAngle);
54+
Console.WriteLine(
55+
"(double sin, double cos) = Math.SinCos({0} deg)",
56+
degrees );
57+
Console.WriteLine(
58+
"sin^2 + cos^2 == {0:E16}",
59+
sinAngle * sinAngle + cosAngle * cosAngle );
3360
}
3461

3562
// Evaluate trigonometric identities with a given angle.

xml/System/Math.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7063,9 +7063,7 @@ The following example demonstrates how to use the <xref:System.Math.Round%28Syst
70637063
## Examples
70647064
The following example demonstrates how to use the <xref:System.Math.Sign%28System.IntPtr%29> method to determine the sign of an <xref:System.IntPtr> value and display it to the console.
70657065
7066-
:::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/math.sign/CPP/sign.cpp" id="Snippet1":::
70677066
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/math.sign/CS/sign.cs" interactive="try-dotnet" id="Snippet1":::
7068-
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1":::
70697067
70707068
]]></format>
70717069
</remarks>
@@ -7362,9 +7360,7 @@ The following example demonstrates how to use the <xref:System.Math.Round%28Syst
73627360
## Examples
73637361
The following example uses <xref:System.Math.SinCos%2A> to evaluate certain trigonometric identities for selected angles.
73647362
7365-
:::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Math.SinCos/CPP/sincos.cpp" id="Snippet1":::
73667363
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/CS/sincos.cs" interactive="try-dotnet" id="Snippet1":::
7367-
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.SinCos/VB/sincos.vb" id="Snippet1":::
73687364
73697365
]]></format>
73707366
</remarks>

xml/System/MathF.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,15 +2108,6 @@ If the value of the `x` argument is <xref:System.Single.NaN?displayProperty=name
21082108
21092109
This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures.
21102110
2111-
2112-
2113-
## Examples
2114-
The following example uses <xref:System.MathF.SinCos%2A> to evaluate certain trigonometric identities for selected angles.
2115-
2116-
:::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.MathF.SinCos/CPP/sincos.cpp" id="Snippet1":::
2117-
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.MathF.SinCos/CS/sincos.cs" interactive="try-dotnet" id="Snippet1":::
2118-
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.MathF.SinCos/VB/sincos.vb" id="Snippet1":::
2119-
21202111
]]></format>
21212112
</remarks>
21222113
</Docs>

0 commit comments

Comments
 (0)