From ef4773c3c05cf36ac9000ba61195b3d1d5b14f0b Mon Sep 17 00:00:00 2001 From: Bar Arnon Date: Sun, 27 Mar 2022 17:34:56 +0300 Subject: [PATCH] Add reciprocal and SinCos methods to IFloatingPoint (#59521) --- .../System.Private.CoreLib/src/System/Double.cs | 9 +++++++++ .../System.Private.CoreLib/src/System/Half.cs | 13 +++++++++++++ .../src/System/IFloatingPoint.cs | 15 +++++++++++++++ .../System.Private.CoreLib/src/System/Single.cs | 9 +++++++++ .../System.Runtime/ref/System.Runtime.cs | 12 ++++++++++++ 5 files changed, 58 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Double.cs b/src/libraries/System.Private.CoreLib/src/System/Double.cs index 0143251707702..f605d61c514d8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Double.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Double.cs @@ -676,6 +676,12 @@ public static TInteger ILogB(double x) /// public static double Pow(double x, double y) => Math.Pow(x, y); + /// + public static double ReciprocalEstimate(double x) => Math.ReciprocalEstimate(x); + + /// + public static double ReciprocalSqrtEstimate(double x) => Math.ReciprocalSqrtEstimate(x); + /// public static double Round(double x) => Math.Round(x); @@ -697,6 +703,9 @@ public static double ScaleB(double x, TInteger n) /// public static double Sin(double x) => Math.Sin(x); + /// + public static (double Sin, double Cos) SinCos(double x) => Math.SinCos(x); + /// public static double Sinh(double x) => Math.Sinh(x); diff --git a/src/libraries/System.Private.CoreLib/src/System/Half.cs b/src/libraries/System.Private.CoreLib/src/System/Half.cs index 223fe66bd79f2..9d8ce8432140e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Half.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Half.cs @@ -899,6 +899,12 @@ public static TInteger ILogB(Half x) /// public static Half Pow(Half x, Half y) => (Half)MathF.Pow((float)x, (float)y); + /// + public static Half ReciprocalEstimate(Half x) => (Half)MathF.ReciprocalEstimate((float)x); + + /// + public static Half ReciprocalSqrtEstimate(Half x) => (Half)MathF.ReciprocalSqrtEstimate((float)x); + /// public static Half Round(Half x) => (Half)MathF.Round((float)x); @@ -920,6 +926,13 @@ public static Half ScaleB(Half x, TInteger n) /// public static Half Sin(Half x) => (Half)MathF.Sin((float)x); + /// + public static (Half Sin, Half Cos) SinCos(Half x) + { + var (sin, cos) = MathF.SinCos((float)x); + return ((Half)sin, (Half)cos); + } + /// public static Half Sinh(Half x) => (Half)MathF.Sinh((float)x); diff --git a/src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs b/src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs index 85ae24efc8ed6..219e121009198 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IFloatingPoint.cs @@ -215,6 +215,16 @@ static abstract TInteger ILogB(TSelf x) /// raised to the power of . static abstract TSelf Pow(TSelf x, TSelf y); + /// Computes an estimate of the reciprocal of a value. + /// The value whose estimate of the reciprocal is to be computed. + /// An estimate of the reciprocal of . + static abstract TSelf ReciprocalEstimate(TSelf x); + + /// Computes an estimate of the reciprocal square root of a value. + /// The value whose estimate of the reciprocal square root is to be computed. + /// An estimate of the reciprocal square root of . + static abstract TSelf ReciprocalSqrtEstimate(TSelf x); + /// Rounds a value to the nearest integer using the default rounding mode (). /// The value to round. /// The result of rounding to the nearest integer using the default rounding mode. @@ -253,6 +263,11 @@ static abstract TSelf ScaleB(TSelf x, TInteger n) /// The sine of . static abstract TSelf Sin(TSelf x); + /// Computes the sine and cosine of a value. + /// The value, in radians, whose sine and cosine are to be computed. + /// The sine and cosine of . + static abstract (TSelf Sin, TSelf Cos) SinCos(TSelf x); + /// Computes the hyperbolic sine of a value. /// The value, in radians, whose hyperbolic sine is to be computed. /// The hyperbolic sine of . diff --git a/src/libraries/System.Private.CoreLib/src/System/Single.cs b/src/libraries/System.Private.CoreLib/src/System/Single.cs index 065ac3d95327f..f241dbd1b0755 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Single.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Single.cs @@ -671,6 +671,12 @@ public static TInteger ILogB(float x) /// public static float Pow(float x, float y) => MathF.Pow(x, y); + /// + public static float ReciprocalEstimate(float x) => MathF.ReciprocalEstimate(x); + + /// + public static float ReciprocalSqrtEstimate(float x) => MathF.ReciprocalSqrtEstimate(x); + /// public static float Round(float x) => MathF.Round(x); @@ -692,6 +698,9 @@ public static float ScaleB(float x, TInteger n) /// public static float Sin(float x) => MathF.Sin(x); + /// + public static (float Sin, float Cos) SinCos(float x) => MathF.SinCos(x); + /// public static float Sinh(float x) => MathF.Sinh(x); diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index bf155afc8500f..0ec230c5a2fe6 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -2070,6 +2070,8 @@ 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(System.Double x, TInteger digits) where TInteger : IBinaryInteger { throw null; } @@ -2077,6 +2079,7 @@ public DivideByZeroException(string? message, System.Exception? innerException) public static System.Double ScaleB(System.Double x, TInteger n) where TInteger : IBinaryInteger { 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.operator +(System.Double left, System.Double right) { throw null; } @@ -2649,6 +2652,8 @@ 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(System.Half x, TInteger digits) where TInteger : IBinaryInteger { throw null; } @@ -2656,6 +2661,7 @@ public GopherStyleUriParser() { } public static System.Half ScaleB(System.Half x, TInteger n) where TInteger : IBinaryInteger { 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.operator &(System.Half left, System.Half right) { throw null; } @@ -2810,12 +2816,15 @@ public partial interface IFloatingPoint : System.ISignedNumber 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(TSelf x, TInteger digits) where TInteger : IBinaryInteger; static abstract TSelf Round(TSelf x, MidpointRounding mode); static abstract TSelf Round(TSelf x, TInteger digits, MidpointRounding mode) where TInteger : IBinaryInteger; static abstract TSelf ScaleB(TSelf x, TInteger n) where TInteger : IBinaryInteger; 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); @@ -4369,6 +4378,8 @@ 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(System.Single x, TInteger digits) where TInteger : IBinaryInteger { throw null; } @@ -4376,6 +4387,7 @@ public SerializableAttribute() { } public static System.Single ScaleB(System.Single x, TInteger n) where TInteger : IBinaryInteger { 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.operator +(System.Single left, System.Single right) { throw null; }