Skip to content

Commit fc5964c

Browse files
committed
Add reciprocal and SinCos methods to IFloatingPoint
Fix dotnet#58607
1 parent bfaa457 commit fc5964c

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

src/libraries/System.Private.CoreLib/src/System/Double.cs

+12
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,14 @@ static double IFloatingPoint<double>.MinMagnitude(double x, double y)
712712
static double IFloatingPoint<double>.Pow(double x, double y)
713713
=> Math.Pow(x, y);
714714

715+
[RequiresPreviewFeatures]
716+
static double IFloatingPoint<double>.ReciprocalEstimate(double x)
717+
=> Math.ReciprocalEstimate(x);
718+
719+
[RequiresPreviewFeatures]
720+
static double IFloatingPoint<double>.ReciprocalSqrtEstimate(double x)
721+
=> Math.ReciprocalSqrtEstimate(x);
722+
715723
[RequiresPreviewFeatures]
716724
static double IFloatingPoint<double>.Round(double x)
717725
=> Math.Round(x);
@@ -736,6 +744,10 @@ static double IFloatingPoint<double>.ScaleB<TInteger>(double x, TInteger n)
736744
static double IFloatingPoint<double>.Sin(double x)
737745
=> Math.Sin(x);
738746

747+
[RequiresPreviewFeatures]
748+
static (double, double) IFloatingPoint<double>.SinCos(double x)
749+
=> Math.SinCos(x);
750+
739751
[RequiresPreviewFeatures]
740752
static double IFloatingPoint<double>.Sinh(double x)
741753
=> Math.Sinh(x);

src/libraries/System.Private.CoreLib/src/System/Half.cs

+15
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,14 @@ static Half IFloatingPoint<Half>.MinMagnitude(Half x, Half y)
10151015
static Half IFloatingPoint<Half>.Pow(Half x, Half y)
10161016
=> (Half)MathF.Pow((float)x, (float)y);
10171017

1018+
[RequiresPreviewFeatures]
1019+
static Half IFloatingPoint<Half>.ReciprocalEstimate(Half x)
1020+
=> (Half)MathF.ReciprocalEstimate((float)x);
1021+
1022+
[RequiresPreviewFeatures]
1023+
static Half IFloatingPoint<Half>.ReciprocalSqrtEstimate(Half x)
1024+
=> (Half)MathF.ReciprocalSqrtEstimate((float)x);
1025+
10181026
[RequiresPreviewFeatures]
10191027
static Half IFloatingPoint<Half>.Round(Half x)
10201028
=> (Half)MathF.Round((float)x);
@@ -1039,6 +1047,13 @@ static Half IFloatingPoint<Half>.ScaleB<TInteger>(Half x, TInteger n)
10391047
static Half IFloatingPoint<Half>.Sin(Half x)
10401048
=> (Half)MathF.Sin((float)x);
10411049

1050+
[RequiresPreviewFeatures]
1051+
static (Half, Half) IFloatingPoint<Half>.SinCos(Half x)
1052+
{
1053+
var (sin, cos) = MathF.SinCos((float)x);
1054+
return ((Half)sin, (Half)cos);
1055+
}
1056+
10421057
[RequiresPreviewFeatures]
10431058
static Half IFloatingPoint<Half>.Sinh(Half x)
10441059
=> (Half)MathF.Sinh((float)x);

src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs

+15
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ static abstract TInteger ILogB<TInteger>(TSelf x)
222222
/// <returns><see cref="E" /> raised to the power of <paramref name="x" />.</returns>
223223
static abstract TSelf Pow(TSelf x, TSelf y);
224224

225+
/// <summary>Computes an estimate of the reciprocal of a value.</summary>
226+
/// <param name="x">The value whose estimate of the reciprocal is to be computed.</param>
227+
/// <returns>An estimate of the reciprocal of <paramref name="x" />.</returns>
228+
static abstract TSelf ReciprocalEstimate(TSelf x);
229+
230+
/// <summary>Computes an estimate of the reciprocal square root of a value.</summary>
231+
/// <param name="x">The value whose estimate of the reciprocal square root is to be computed.</param>
232+
/// <returns>An estimate of the reciprocal square root of <paramref name="x" />.</returns>
233+
static abstract TSelf ReciprocalSqrtEstimate(TSelf x);
234+
225235
/// <summary>Rounds a value to the nearest integer using the default rounding mode (<see cref="MidpointRounding.ToEven" />).</summary>
226236
/// <param name="x">The value to round.</param>
227237
/// <returns>The result of rounding <paramref name="x" /> to the nearest integer using the default rounding mode.</returns>
@@ -260,6 +270,11 @@ static abstract TSelf ScaleB<TInteger>(TSelf x, TInteger n)
260270
/// <returns>The sine of <paramref name="x" />.</returns>
261271
static abstract TSelf Sin(TSelf x);
262272

273+
/// <summary>Computes the sine and cosine of a value.</summary>
274+
/// <param name="x">The value, in radians, whose sine and cosine are to be computed.</param>
275+
/// <returns>The sine and cosine of <paramref name="x" />.</returns>
276+
static abstract (TSelf, TSelf) SinCos(TSelf x);
277+
263278
/// <summary>Computes the hyperbolic sine of a value.</summary>
264279
/// <param name="x">The value, in radians, whose hyperbolic sine is to be computed.</param>
265280
/// <returns>The hyperbolic sine of <paramref name="x" />.</returns>

src/libraries/System.Private.CoreLib/src/System/Single.cs

+12
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,14 @@ static float IFloatingPoint<float>.MinMagnitude(float x, float y)
704704
static float IFloatingPoint<float>.Pow(float x, float y)
705705
=> MathF.Pow(x, y);
706706

707+
[RequiresPreviewFeatures]
708+
static float IFloatingPoint<float>.ReciprocalEstimate(float x)
709+
=> MathF.ReciprocalEstimate(x);
710+
711+
[RequiresPreviewFeatures]
712+
static float IFloatingPoint<float>.ReciprocalSqrtEstimate(float x)
713+
=> MathF.ReciprocalSqrtEstimate(x);
714+
707715
[RequiresPreviewFeatures]
708716
static float IFloatingPoint<float>.Round(float x)
709717
=> MathF.Round(x);
@@ -729,6 +737,10 @@ static float IFloatingPoint<float>.Sin(float x)
729737
=> MathF.Sin(x);
730738

731739
[RequiresPreviewFeatures]
740+
static (float, float) IFloatingPoint<float>.SinCos(float x)
741+
=> MathF.SinCos(x);
742+
743+
[RequiresPreviewFeatures]
732744
static float IFloatingPoint<float>.Sinh(float x)
733745
=> MathF.Sinh(x);
734746

0 commit comments

Comments
 (0)