-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 missing math functions defined by IEEE 754:2019 #20137
Comments
@dcwuser, if you could update the proposal to include the These functions are also defined in section It is likely worth calling out in the rationale that these functions can account for floating-point inaccuracies when performing these common operations and is one reason why they are exposed by other languages/frameworks and recommended by the IEEE 754 specification. |
We'd like to finish off all of the part 9 methods in one pass (the list seems to be @tannergooding: Please update the proposal to include all of these operations (PascalCased as appropriate) to show the signatures (including parameter names). Should be an easy re-review. |
Updated to include the full set, as per design-review. |
namespace System
{
public static partial class Math
{
public static double AcosPi(double x);
public static double AsinPi(double x);
public static double Atan2Pi(double y, double x);
public static double AtanPi(double x);
public static double Compound(double x, double n);
public static double CosPi(double x);
public static double Exp10(double x);
public static double Exp10M1(double x);
public static double Exp2(double x);
public static double Exp2M1(double x);
public static double ExpM1(double x);
public static double Hypot(double x, double y);
public static double Log10P1(double x);
public static double Log2P1(double x);
public static double LogP1(double x);
public static double MaxMagnitudeNumber(double x, double y);
public static double MaxNumber(double x, double y);
public static double MinMagnitudeNumber(double x, double y);
public static double MinNumber(double x, double y);
public static double Root(double x, double n);
public static double SinPi(double x);
public static double TanPi(double x);
}
public static partial class MathF
{
public static float AcosPi(float x);
public static float AsinPi(float x);
public static float Atan2Pi(float y, float x);
public static float AtanPi(float x);
public static float Compound(float x, float n);
public static float CosPi(float x);
public static float Exp10(float x);
public static float Exp10M1(float x);
public static float Exp2(float x);
public static float Exp2M1(float x);
public static float ExpM1(float x);
public static float Hypot(float x, float y);
public static float Log10P1(float x);
public static float Log2P1(float x);
public static float LogP1(float x);
public static float MaxMagnitudeNumber(float x, float y);
public static float MaxNumber(float x, float y);
public static float MinMagnitudeNumber(float x, float y);
public static float MinNumber(float x, float y);
public static float Root(float x, float n);
public static float SinPi(float x);
public static float TanPi(float x);
}
} |
marking 'up for grabs' as I assume it is? |
This one requires JIT work as well and is blocked on the generic math work. |
@tannergooding Why is work on the JIT needed here? Should AggresiveInlining not optimize these functions sufficiently? |
Implementing these functions correctly is non-trivial and requires quite a bit of work. We are currently relying on the C Runtime to provide these functions where possible to help simplify the implementation. The JIT work can be quite verbose and requires touching multiple layers, from PAL to JIT to managed, as well as adding tests and knowing the relevant edge case scenarios that need to be tested/validated for correctness. |
@tannergooding, with all of the functions being exposed via the generic math interfaces, is this issue still relevant / we still want to add all these functions to Math{F}? |
This can be closed now. We are indeed exposing all functions via the generic math interfaces and there aren't currently any plans to also expose them in |
Sorry, but how do the generic math interfaces make e.g. Log1P available? The use of generic math interfaces might make it possible to write a generic math implementation, but they don't make that implementation magically appear. The key issue here isn't whether these function are exposed via the Math/MathF types; it's whether they are available in anywhere. And unless I misunderstand, the generic math interfaces do not make them available. |
API review decided as part of generic math that The The The These interfaces are implemented by APIs like The over-arching design doc for the generic math feature is covered in https://github.com/dotnet/designs/tree/main/accepted/2021/statics-in-interfaces |
I believe |
These are very standard methods used in numerical computing.
They appear, with exactly these names, in the Java Math class and Boost and GSL libraries, in many other mathematical libraries, and in many articles in the numerical computing literature.
Naming: The names are somewhat cryptic. .NET coding guidelines would probably favor ExpMinusOne over Expm1, etc. On the other hand, the names are quite standardized. We would need to decide whether conforming to the expectations of advanced users or giving a better hint at meaning to less advanced users is more important.
Location: The obvious place is System.Math, but: (i) this class is already quite a jumble, (ii) it mostly follows math.h of the C standard library, which does not contain these functions, and (iii) the presence of these functions might baffle naive users. One possibility would be to add a MoreMath or AdvancedMath static class in the System.Numerics namespace, which would also be a natural place for future advanced functions such as erf, Gamma, etc.
Domain and Range: The only slightly non-trivial issue here is that Log1p is not defined for x < -1. We would need to decide whether to retutrn NaN or throw ArgumentOutOfRangeException.
Implementation and Performance: Implementations are straightforward and well-established. Each can be executed over the entire range with a handfull of flops, making them about as fast as most other standard math functions.
The text was updated successfully, but these errors were encountered: