diff --git a/samples/snippets/csharp/VS_Snippets_CLR/math.sign/CS/sign.cs b/samples/snippets/csharp/VS_Snippets_CLR/math.sign/CS/sign.cs index 2063a16e727..7014ac48f04 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/math.sign/CS/sign.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/math.sign/CS/sign.cs @@ -15,6 +15,7 @@ public static void Main() float xSingle1 = 0.0f; double xDouble1 = 6.0; Decimal xDecimal1 = -7m; + nint xIntPtr1 = 8; // The following type is not CLS-compliant. sbyte xSbyte1 = -101; @@ -27,6 +28,7 @@ public static void Main() Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1))); Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1))); Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1))); + Console.WriteLine(str, "IntPtr", xIntPtr1, Test(Math.Sign(xIntPtr1))); Console.WriteLine($"{nl}The following type is not CLS-compliant."); Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1))); @@ -53,6 +55,7 @@ public static string Test(int compare) Single : 0 is equal to zero. Double : 6 is greater than zero. Decimal: -7 is less than zero. +IntPtr: 8 is greater than zero. The following type is not CLS-compliant. SByte : -101 is less than zero. diff --git a/samples/snippets/csharp/VS_Snippets_CLR/math.sign/System.Math.Sign.csproj b/samples/snippets/csharp/VS_Snippets_CLR/math.sign/System.Math.Sign.csproj new file mode 100644 index 00000000000..41f1d5ad4b2 --- /dev/null +++ b/samples/snippets/csharp/VS_Snippets_CLR/math.sign/System.Math.Sign.csproj @@ -0,0 +1,8 @@ + + + + Exe + net6.0 + + + diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/CS/sincos.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/CS/sincos.cs index 79c2e74e9bd..a1b83851afb 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/CS/sincos.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/CS/sincos.cs @@ -9,7 +9,7 @@ public static void Main() { Console.WriteLine( "This example of trigonometric " + - "Math.Sin( double ) and Math.Cos( double )\n" + + "Math.Sin( double ), Math.Cos( double ), and Math.SinCos( double )\n" + "generates the following output.\n" ); Console.WriteLine( "Convert selected values for X to radians \n" + @@ -17,6 +17,7 @@ public static void Main() Console.WriteLine( " sin^2(X) + cos^2(X) == 1\n" + " sin(2 * X) == 2 * sin(X) * cos(X)" ); Console.WriteLine( " cos(2 * X) == cos^2(X) - sin^2(X)" ); + Console.WriteLine( " cos(2 * X) == cos^2(X) - sin^2(X)" ); UseSineCosine(15.0); UseSineCosine(30.0); @@ -30,6 +31,32 @@ public static void Main() UseTwoAngles(15.0, 30.0); UseTwoAngles(30.0, 45.0); + + Console.WriteLine( + "\nWhen you have calls to sin(X) and cos(X) they \n" + + "can be replaced with a single call to sincos(x):" ); + + UseCombinedSineCosine(15.0); + UseCombinedSineCosine(30.0); + UseCombinedSineCosine(45.0); + } + + // Evaluate trigonometric identities with a given angle. + static void UseCombinedSineCosine(double degrees) + { + double angle = Math.PI * degrees / 180.0; + (double sinAngle, double cosAngle) = Math.SinCos(angle); + + // Evaluate sin^2(X) + cos^2(X) == 1. + Console.WriteLine( + "\n Math.SinCos({0} deg) == ({1:E16}, {2:E16})", + degrees, sinAngle, cosAngle); + Console.WriteLine( + "(double sin, double cos) = Math.SinCos({0} deg)", + degrees ); + Console.WriteLine( + "sin^2 + cos^2 == {0:E16}", + sinAngle * sinAngle + cosAngle * cosAngle ); } // Evaluate trigonometric identities with a given angle. diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/System.Math.SinCos.csproj b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/System.Math.SinCos.csproj new file mode 100644 index 00000000000..41f1d5ad4b2 --- /dev/null +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/System.Math.SinCos.csproj @@ -0,0 +1,8 @@ + + + + Exe + net6.0 + + + diff --git a/samples/snippets/csharp/api/system.reflection.metadata/metadatareader/MetadataReaderSnippets.csproj b/samples/snippets/csharp/api/system.reflection.metadata/metadatareader/MetadataReaderSnippets.csproj index 1763ae3474b..4abc160460e 100644 --- a/samples/snippets/csharp/api/system.reflection.metadata/metadatareader/MetadataReaderSnippets.csproj +++ b/samples/snippets/csharp/api/system.reflection.metadata/metadatareader/MetadataReaderSnippets.csproj @@ -6,7 +6,7 @@ - + diff --git a/xml/System/Math.xml b/xml/System/Math.xml index 925366cb7be..38d226beb0e 100644 --- a/xml/System/Math.xml +++ b/xml/System/Math.xml @@ -7036,10 +7036,37 @@ The following example demonstrates how to use the - To be added. - To be added. - To be added. - To be added. + A signed number. + Returns an integer that indicates the sign of a native sized signed integer. + A number that indicates the sign of , as shown in the following table. + + Return value + + Meaning + + -1 + + is less than zero. + + 0 + + is equal to zero. + + 1 + + is greater than zero. + + + + method to determine the sign of an value and display it to the console. + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/math.sign/CS/sign.cs" interactive="try-dotnet" id="Snippet1"::: + + ]]> + @@ -7317,10 +7344,26 @@ The following example demonstrates how to use the - To be added. - To be added. - To be added. - To be added. + An angle, measured in radians. + Returns the sine and cosine of the specified angle. + The sine and cosine of . If is equal to , , or , this method returns . + + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example uses to evaluate certain trigonometric identities for selected angles. + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Math.SinCos/CS/sincos.cs" interactive="try-dotnet" id="Snippet1"::: + + ]]> + diff --git a/xml/System/MathF.xml b/xml/System/MathF.xml index 510002cb4c6..155b39df463 100644 --- a/xml/System/MathF.xml +++ b/xml/System/MathF.xml @@ -2097,10 +2097,19 @@ If the value of the `x` argument is - To be added. - To be added. - To be added. - To be added. + An angle, measured in radians. + Returns the sine and cosine of the specified angle. + The sine and cosine of . If is equal to , , or , this method returns . + + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + ]]> +