Skip to content
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

Add reciprocal and SinCos methods to IFloatingPoint #59521

Merged
merged 8 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,12 @@ public static TInteger ILogB<TInteger>(double x)
/// <inheritdoc cref="IFloatingPoint{TSelf}.Pow(TSelf, TSelf)" />
public static double Pow(double x, double y) => Math.Pow(x, y);

/// <inheritdoc cref="IFloatingPoint{TSelf}.ReciprocalEstimate(TSelf)" />
public static double ReciprocalEstimate(double x) => Math.ReciprocalEstimate(x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.ReciprocalSqrtEstimate(TSelf)" />
public static double ReciprocalSqrtEstimate(double x) => Math.ReciprocalSqrtEstimate(x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.Round(TSelf)" />
public static double Round(double x) => Math.Round(x);

Expand All @@ -697,6 +703,9 @@ public static double ScaleB<TInteger>(double x, TInteger n)
/// <inheritdoc cref="IFloatingPoint{TSelf}.Sin(TSelf)" />
public static double Sin(double x) => Math.Sin(x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.SinCos(TSelf)" />
public static (double Sin, double Cos) SinCos(double x) => Math.SinCos(x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.Sinh(TSelf)" />
public static double Sinh(double x) => Math.Sinh(x);

Expand Down
13 changes: 13 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Half.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,12 @@ public static TInteger ILogB<TInteger>(Half x)
/// <inheritdoc cref="IFloatingPoint{TSelf}.Pow(TSelf, TSelf)" />
public static Half Pow(Half x, Half y) => (Half)MathF.Pow((float)x, (float)y);

/// <inheritdoc cref="IFloatingPoint{TSelf}.ReciprocalEstimate(TSelf)" />
public static Half ReciprocalEstimate(Half x) => (Half)MathF.ReciprocalEstimate((float)x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.ReciprocalSqrtEstimate(TSelf)" />
public static Half ReciprocalSqrtEstimate(Half x) => (Half)MathF.ReciprocalSqrtEstimate((float)x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.Round(TSelf)" />
public static Half Round(Half x) => (Half)MathF.Round((float)x);

Expand All @@ -920,6 +926,13 @@ public static Half ScaleB<TInteger>(Half x, TInteger n)
/// <inheritdoc cref="IFloatingPoint{TSelf}.Sin(TSelf)" />
public static Half Sin(Half x) => (Half)MathF.Sin((float)x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.SinCos(TSelf)" />
public static (Half Sin, Half Cos) SinCos(Half x)
{
var (sin, cos) = MathF.SinCos((float)x);
return ((Half)sin, (Half)cos);
}

/// <inheritdoc cref="IFloatingPoint{TSelf}.Sinh(TSelf)" />
public static Half Sinh(Half x) => (Half)MathF.Sinh((float)x);

Expand Down
15 changes: 15 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ static abstract TInteger ILogB<TInteger>(TSelf x)
/// <returns><see cref="E" /> raised to the power of <paramref name="x" />.</returns>
static abstract TSelf Pow(TSelf x, TSelf y);

/// <summary>Computes an estimate of the reciprocal of a value.</summary>
/// <param name="x">The value whose estimate of the reciprocal is to be computed.</param>
/// <returns>An estimate of the reciprocal of <paramref name="x" />.</returns>
static abstract TSelf ReciprocalEstimate(TSelf x);

/// <summary>Computes an estimate of the reciprocal square root of a value.</summary>
/// <param name="x">The value whose estimate of the reciprocal square root is to be computed.</param>
/// <returns>An estimate of the reciprocal square root of <paramref name="x" />.</returns>
static abstract TSelf ReciprocalSqrtEstimate(TSelf x);

/// <summary>Rounds a value to the nearest integer using the default rounding mode (<see cref="MidpointRounding.ToEven" />).</summary>
/// <param name="x">The value to round.</param>
/// <returns>The result of rounding <paramref name="x" /> to the nearest integer using the default rounding mode.</returns>
Expand Down Expand Up @@ -253,6 +263,11 @@ static abstract TSelf ScaleB<TInteger>(TSelf x, TInteger n)
/// <returns>The sine of <paramref name="x" />.</returns>
static abstract TSelf Sin(TSelf x);

/// <summary>Computes the sine and cosine of a value.</summary>
/// <param name="x">The value, in radians, whose sine and cosine are to be computed.</param>
/// <returns>The sine and cosine of <paramref name="x" />.</returns>
static abstract (TSelf Sin, TSelf Cos) SinCos(TSelf x);

/// <summary>Computes the hyperbolic sine of a value.</summary>
/// <param name="x">The value, in radians, whose hyperbolic sine is to be computed.</param>
/// <returns>The hyperbolic sine of <paramref name="x" />.</returns>
Expand Down
9 changes: 9 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,12 @@ public static TInteger ILogB<TInteger>(float x)
/// <inheritdoc cref="IFloatingPoint{TSelf}.Pow(TSelf, TSelf)" />
public static float Pow(float x, float y) => MathF.Pow(x, y);

/// <inheritdoc cref="IFloatingPoint{TSelf}.ReciprocalEstimate(TSelf)" />
public static float ReciprocalEstimate(float x) => MathF.ReciprocalEstimate(x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.ReciprocalSqrtEstimate(TSelf)" />
public static float ReciprocalSqrtEstimate(float x) => MathF.ReciprocalSqrtEstimate(x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.Round(TSelf)" />
public static float Round(float x) => MathF.Round(x);

Expand All @@ -692,6 +698,9 @@ public static float ScaleB<TInteger>(float x, TInteger n)
/// <inheritdoc cref="IFloatingPoint{TSelf}.Sin(TSelf)" />
public static float Sin(float x) => MathF.Sin(x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.SinCos(TSelf)" />
public static (float Sin, float Cos) SinCos(float x) => MathF.SinCos(x);

/// <inheritdoc cref="IFloatingPoint{TSelf}.Sinh(TSelf)" />
public static float Sinh(float x) => MathF.Sinh(x);

Expand Down
12 changes: 12 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2070,13 +2070,16 @@ public DivideByZeroException(string? message, System.Exception? innerException)
public static System.Double Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; }
public static System.Double Parse(string s, System.IFormatProvider? provider) { throw null; }
public static System.Double Pow(System.Double x, System.Double y) { throw null; }
public static System.Double ReciprocalEstimate(System.Double x) { throw null; }
public static System.Double ReciprocalSqrtEstimate(System.Double x) { throw null; }
public static System.Double Round(System.Double x) { throw null; }
public static System.Double Round(System.Double x, System.MidpointRounding mode) { throw null; }
public static System.Double Round<TInteger>(System.Double x, TInteger digits) where TInteger : IBinaryInteger<TInteger> { throw null; }
public static System.Double Round<TInteger>(System.Double x, TInteger digits, System.MidpointRounding mode) where TInteger : IBinaryInteger<TInteger> { throw null; }
public static System.Double ScaleB<TInteger>(System.Double x, TInteger n) where TInteger : IBinaryInteger<TInteger> { throw null; }
public static System.Double Sign(System.Double value) { throw null; }
public static System.Double Sin(System.Double x) { throw null; }
public static (System.Double Sin, System.Double Cos) SinCos(System.Double x) { throw null; }
public static System.Double Sinh(System.Double x) { throw null; }
public static System.Double Sqrt(System.Double x) { throw null; }
static System.Double System.IAdditionOperators<System.Double,System.Double,System.Double>.operator +(System.Double left, System.Double right) { throw null; }
Expand Down Expand Up @@ -2649,13 +2652,16 @@ public GopherStyleUriParser() { }
public static System.Half Parse(string s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowExponent | System.Globalization.NumberStyles.AllowLeadingSign | System.Globalization.NumberStyles.AllowLeadingWhite | System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.AllowTrailingWhite, System.IFormatProvider? provider = null) { throw null; }
public static System.Half Parse(string s, System.IFormatProvider? provider) { throw null; }
public static System.Half Pow(System.Half x, System.Half y) { throw null; }
public static System.Half ReciprocalEstimate(System.Half x) { throw null; }
public static System.Half ReciprocalSqrtEstimate(System.Half x) { throw null; }
public static System.Half Round(System.Half x) { throw null; }
public static System.Half Round(System.Half x, System.MidpointRounding mode) { throw null; }
public static System.Half Round<TInteger>(System.Half x, TInteger digits) where TInteger : IBinaryInteger<TInteger> { throw null; }
public static System.Half Round<TInteger>(System.Half x, TInteger digits, System.MidpointRounding mode) where TInteger : IBinaryInteger<TInteger> { throw null; }
public static System.Half ScaleB<TInteger>(System.Half x, TInteger n) where TInteger : IBinaryInteger<TInteger> { throw null; }
public static System.Half Sign(System.Half value) { throw null; }
public static System.Half Sin(System.Half x) { throw null; }
public static (System.Half Sin, System.Half Cos) SinCos(System.Half x) { throw null; }
public static System.Half Sinh(System.Half x) { throw null; }
public static System.Half Sqrt(System.Half x) { throw null; }
static System.Half System.IBitwiseOperators<System.Half,System.Half,System.Half>.operator &(System.Half left, System.Half right) { throw null; }
Expand Down Expand Up @@ -2810,12 +2816,15 @@ public partial interface IFloatingPoint<TSelf> : System.ISignedNumber<TSelf>
static abstract TSelf MaxMagnitude(TSelf x, TSelf y);
static abstract TSelf MinMagnitude(TSelf x, TSelf y);
static abstract TSelf Pow(TSelf x, TSelf y);
static abstract TSelf ReciprocalEstimate(TSelf x);
static abstract TSelf ReciprocalSqrtEstimate(TSelf x);
static abstract TSelf Round(TSelf x);
static abstract TSelf Round<TInteger>(TSelf x, TInteger digits) where TInteger : IBinaryInteger<TInteger>;
static abstract TSelf Round(TSelf x, MidpointRounding mode);
static abstract TSelf Round<TInteger>(TSelf x, TInteger digits, MidpointRounding mode) where TInteger : IBinaryInteger<TInteger>;
static abstract TSelf ScaleB<TInteger>(TSelf x, TInteger n) where TInteger : IBinaryInteger<TInteger>;
static abstract TSelf Sin(TSelf x);
static abstract (TSelf Sin, TSelf Cos) SinCos(TSelf x);
static abstract TSelf Sinh(TSelf x);
static abstract TSelf Sqrt(TSelf x);
static abstract TSelf Tan(TSelf x);
Expand Down Expand Up @@ -4369,13 +4378,16 @@ public SerializableAttribute() { }
public static System.Single Parse(string s, System.Globalization.NumberStyles style, System.IFormatProvider? provider) { throw null; }
public static System.Single Parse(string s, System.IFormatProvider? provider) { throw null; }
public static System.Single Pow(System.Single x, System.Single y) { throw null; }
public static System.Single ReciprocalEstimate(System.Single x) { throw null; }
public static System.Single ReciprocalSqrtEstimate(System.Single x) { throw null; }
public static System.Single Round(System.Single x) { throw null; }
public static System.Single Round(System.Single x, System.MidpointRounding mode) { throw null; }
public static System.Single Round<TInteger>(System.Single x, TInteger digits) where TInteger : IBinaryInteger<TInteger> { throw null; }
public static System.Single Round<TInteger>(System.Single x, TInteger digits, System.MidpointRounding mode) where TInteger : IBinaryInteger<TInteger> { throw null; }
public static System.Single ScaleB<TInteger>(System.Single x, TInteger n) where TInteger : IBinaryInteger<TInteger> { throw null; }
public static System.Single Sign(System.Single value) { throw null; }
public static System.Single Sin(System.Single x) { throw null; }
public static (System.Single Sin, System.Single Cos) SinCos(System.Single x) { throw null; }
public static System.Single Sinh(System.Single x) { throw null; }
public static System.Single Sqrt(System.Single x) { throw null; }
static System.Single System.IAdditionOperators<System.Single,System.Single,System.Single>.operator +(System.Single left, System.Single right) { throw null; }
Expand Down