Skip to content

Add support for Acosh, Asin, Atanh, and Cbrt to System.Math and System.MathF #20322

@tannergooding

Description

@tannergooding

Rationale

The .NET framework does not currently provide support for several of the mathematical functions that are available to the C/C++ Standard Library.

Support should be provided for these mathematical functions in order to better interop with high-performance, scientific, and multimedia-based applications where these functions may be in demand.

Several of these functions, such as ExpM1, may be more accurate or may return values for inputs outside the range of the corresponding code written manually (EXP(x) - 1).

Approved API

public static partial class Math
{
    // Hyperbolic Functions
    public static double Acosh(double);                 // Compute area hyperbolic cosine
    public static double Asinh(double);                 // Compute area hyperbolic sine
    public static double Atanh(double);                 // Compute area hyperbolic tangent

    // Power Functions
    public static double Cbrt(double);                  // Compute cubic root
}

public static partial class MathF
{
    // Hyperbolic Functions
    public static float Acosh(float);                   // Compute area hyperbolic cosine
    public static float Asinh(float);                   // Compute area hyperbolic sine
    public static float Atanh(float);                   // Compute area hyperbolic tangent

    // Power Functions
    public static float Cbrt(float);                    // Compute cubic root
}

Unapproved APIs

The following APIs were also reviewed but rejected at this time. The discussion ended up that these would likely be better suited in a MathExtensions or similar class provided through a separate library (and likely implemented using the hardware intrinsics functionality rather than as FCALLs in the runtime).

public static partial class Math
{
    // Exponential Functions
    public static double Exp2(double);                  // Compute binary exponential
    public static double ExpM1(double);                 // Compute exponential minus one

    // Logarithmic Functions
    public static double Log1P(double);                 // Compute logarithm plus one
    public static double Log2(double);                  // Compute binary logarithm

    // Power Functions
    public static double Hypot(double, double);    // Compute hypotenuse
}

public static partial class MathF
{
    // Exponential Functions
    public static float Exp2(float);                    // Compute binary exponential
    public static float ExpM1(float);                   // Compute exponential minus one

    // Logarithmic Functions
    public static float Log1P(float);                   // Compute logarithm plus one
    public static float Log2(float);                    // Compute binary logarithm

    // Power Functions
    public static float Hypot(float, float);       // Compute hypotenuse
}

Additional Details

This will require several changes in the CoreCLR as well to support the new APIs via FCALLs and Intrinsics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions