Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

Currently, it's a bit hard to parse the // C++17 comments nested in the // C99 group. This patch attempts to sort functions into 4 groups.

  • C90: functions with names introduced in C89/90.
  • C99: functions with names introduced C99, including f and l variants of C89/90 functions, except for 3D hypot.
  • C++17: 3D hypot and C++17 math special functions.
  • C++20: C++20 lerp.

The next group is expected to be C23, which will be added when C++ starts to merge C23 math functions.

More arithmetic and floating_point are used for simplification.

Currently, it's a bit hard to parse the `// C++17` comments nested in
the `//  C99` group. This patch attempts to sort functions into 4
groups.
- C90: functions with names introduced in C89/90.
- C99: functions with names introduced C99,
including `f` and `l` variants of C89/90 functions,
except for 3D `hypot`.
- C++17: 3D `hypot` and C++17 math special functions.
- C++20: C++20 `lerp`.

The next group is expected to be C23, which will be added when C++
starts to merge C23 math functions.

More `arithmetic` and `floating_point` are used for simplification.
@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner July 27, 2024 09:26
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 27, 2024

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes

Currently, it's a bit hard to parse the // C++17 comments nested in the // C99 group. This patch attempts to sort functions into 4 groups.

  • C90: functions with names introduced in C89/90.
  • C99: functions with names introduced C99, including f and l variants of C89/90 functions, except for 3D hypot.
  • C++17: 3D hypot and C++17 math special functions.
  • C++20: C++20 lerp.

The next group is expected to be C23, which will be added when C++ starts to merge C23 math functions.

More arithmetic and floating_point are used for simplification.


Full diff: https://github.com/llvm/llvm-project/pull/100862.diff

1 Files Affected:

  • (modified) libcxx/include/cmath (+73-55)
diff --git a/libcxx/include/cmath b/libcxx/include/cmath
index 3c22604a683c3..32b8ccdf4e698 100644
--- a/libcxx/include/cmath
+++ b/libcxx/include/cmath
@@ -46,112 +46,134 @@ Types:
 
 floating_point abs(floating_point x);
 
-floating_point acos (arithmetic x);
+floating_point acos(arithmetic x);
+
+floating_point asin(arithmetic x);
+
+floating_point atan(arithmetic x);
+
+floating_point atan2(arithmetic y, arithmetic x);
+
+floating_point ceil(arithmetic x);
+
+floating_point cos(arithmetic x);
+
+floating_point cosh(arithmetic x);
+
+floating_point exp(arithmetic x);
+
+floating_point fabs(arithmetic x);
+
+floating_point floor(arithmetic x);
+
+floating_point fmod(arithmetic x, arithmetic y);
+
+floating_point frexp(arithmetic value, int* exp);
+
+floating_point ldexp(arithmetic value, int exp);
+
+floating_point log(arithmetic x);
+
+floating_point modf(floating_point value, floating_point* iptr);
+
+floating_point log10(arithmetic x);
+
+floating_point pow(arithmetic x, arithmetic y);
+
+floating_point sin(arithmetic x);
+
+floating_point sinh(arithmetic x);
+
+floating_point sqrt(arithmetic x);
+
+floating_point tan(arithmetic x);
+
+floating_point tanh(arithmetic x);
+
+//  C99
+
+bool signbit(arithmetic x);
+
+int fpclassify(arithmetic x);
+
+bool isfinite(arithmetic x);
+bool isinf(arithmetic x);
+bool isnan(arithmetic x);
+bool isnormal(arithmetic x);
+
+bool isgreater(arithmetic x, arithmetic y);
+bool isgreaterequal(arithmetic x, arithmetic y);
+bool isless(arithmetic x, arithmetic y);
+bool islessequal(arithmetic x, arithmetic y);
+bool islessgreater(arithmetic x, arithmetic y);
+bool isunordered(arithmetic x, arithmetic y);
+
 float          acosf(float x);
 long double    acosl(long double x);
 
-floating_point asin (arithmetic x);
 float          asinf(float x);
 long double    asinl(long double x);
 
-floating_point atan (arithmetic x);
 float          atanf(float x);
 long double    atanl(long double x);
 
-floating_point atan2 (arithmetic y, arithmetic x);
 float          atan2f(float y, float x);
 long double    atan2l(long double y, long double x);
 
-floating_point ceil (arithmetic x);
 float          ceilf(float x);
 long double    ceill(long double x);
 
-floating_point cos (arithmetic x);
 float          cosf(float x);
 long double    cosl(long double x);
 
-floating_point cosh (arithmetic x);
 float          coshf(float x);
 long double    coshl(long double x);
 
-floating_point exp (arithmetic x);
 float          expf(float x);
 long double    expl(long double x);
 
-floating_point fabs (arithmetic x);
 float          fabsf(float x);
 long double    fabsl(long double x);
 
-floating_point floor (arithmetic x);
 float          floorf(float x);
 long double    floorl(long double x);
 
-floating_point fmod (arithmetic x, arithmetic y);
 float          fmodf(float x, float y);
 long double    fmodl(long double x, long double y);
 
-floating_point frexp (arithmetic value, int* exp);
 float          frexpf(float value, int* exp);
 long double    frexpl(long double value, int* exp);
 
-floating_point ldexp (arithmetic value, int exp);
 float          ldexpf(float value, int exp);
 long double    ldexpl(long double value, int exp);
 
-floating_point log (arithmetic x);
 float          logf(float x);
 long double    logl(long double x);
 
-floating_point log10 (arithmetic x);
 float          log10f(float x);
 long double    log10l(long double x);
 
-floating_point modf (floating_point value, floating_point* iptr);
 float          modff(float value, float* iptr);
 long double    modfl(long double value, long double* iptr);
 
-floating_point pow (arithmetic x, arithmetic y);
 float          powf(float x, float y);
 long double    powl(long double x, long double y);
 
-floating_point sin (arithmetic x);
 float          sinf(float x);
 long double    sinl(long double x);
 
-floating_point sinh (arithmetic x);
 float          sinhf(float x);
 long double    sinhl(long double x);
 
-floating_point sqrt (arithmetic x);
 float          sqrtf(float x);
 long double    sqrtl(long double x);
 
-floating_point tan (arithmetic x);
 float          tanf(float x);
 long double    tanl(long double x);
 
-floating_point tanh (arithmetic x);
 float          tanhf(float x);
 long double    tanhl(long double x);
 
-//  C99
-
-bool signbit(arithmetic x);
-
-int fpclassify(arithmetic x);
-
-bool isfinite(arithmetic x);
-bool isinf(arithmetic x);
-bool isnan(arithmetic x);
-bool isnormal(arithmetic x);
-
-bool isgreater(arithmetic x, arithmetic y);
-bool isgreaterequal(arithmetic x, arithmetic y);
-bool isless(arithmetic x, arithmetic y);
-bool islessequal(arithmetic x, arithmetic y);
-bool islessgreater(arithmetic x, arithmetic y);
-bool isunordered(arithmetic x, arithmetic y);
-
 floating_point acosh (arithmetic x);
 float          acoshf(float x);
 long double    acoshl(long double x);
@@ -204,22 +226,10 @@ floating_point fmin (arithmetic x, arithmetic y);
 float          fminf(float x, float y);
 long double    fminl(long double x, long double y);
 
-double         hermite(unsigned n, double x);                    // C++17
-float          hermite(unsigned n, float x);                     // C++17
-long double    hermite(unsigned n, long double x);               // C++17
-float          hermitef(unsigned n, float x);                    // C++17
-long double    hermitel(unsigned n, long double x);              // C++17
-template <class Integer>
-double         hermite(unsigned n, Integer x);                   // C++17
-
 floating_point hypot (arithmetic x, arithmetic y);
 float          hypotf(float x, float y);
 long double    hypotl(long double x, long double y);
 
-double       hypot(double x, double y, double z);                // C++17
-float        hypot(float x, float y, float z);                   // C++17
-long double  hypot(long double x, long double y, long double z); // C++17
-
 int ilogb (arithmetic x);
 int ilogbf(float x);
 int ilogbl(long double x);
@@ -304,9 +314,17 @@ floating_point trunc (arithmetic x);
 float          truncf(float x);
 long double    truncl(long double x);
 
-constexpr float       lerp(float a, float b, float t) noexcept;                   // C++20
-constexpr double      lerp(double a, double b, double t) noexcept;                // C++20
-constexpr long double lerp(long double a, long double b, long double t) noexcept; // C++20
+//  C++17
+
+floating_point hypot(arithmetic x, arithmetic y, arithmetic z);
+
+floating_point hermite (unsigned n, arithmetic x);
+float          hermitef(unsigned n, float x);
+long double    hermitel(unsigned n, long double x);
+
+//  C++20
+
+constexpr floating_point lerp(arithmetic a, arithmetic b, arithmetic t) noexcept;
 
 }  // std
 

Comment on lines +321 to +323
floating_point hermite (unsigned n, arithmetic x);
float hermitef(unsigned n, float x);
long double hermitel(unsigned n, long double x);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will affect the convention of math special functions in synopsis comments. I think it will be better to show them consistently with most other functions.
@PaulXiCao Would you mind to follow this (probably pre-existing) convention?

@PaulXiCao
Copy link
Contributor

The previous order was (almost?) an exact copy of the standard I believe (e.g. see https://eel.is/c++draft/c.math.syn). I see benefits to sticking to that order instead of defining a new one which might not be adhered to by new contributors.

Nonetheless, there are things to update, e.g.

//
// from main
// 
floating_point hypot (arithmetic x, arithmetic y);
float          hypotf(float x, float y);
long double    hypotl(long double x, long double y);

double       hypot(double x, double y, double z);                // C++17
float        hypot(float x, float y, float z);                   // C++17
long double  hypot(long double x, long double y, long double z); // C++17

//
// from the standard
//
constexpr floating-point-type hypot(floating-point-type x, floating-point-type y);
constexpr float hypotf(float x, float y);
constexpr long double hypotl(long double x, long double y);

// [[c.math.hypot3]](https://eel.is/c++draft/c.math.hypot3), three-dimensional hypotenuse
constexpr floating-point-type hypot(floating-point-type x, floating-point-type y,
                                    floating-point-type z);

I would also include constexpr as long as we support it.

I do not have an opinion yet what to do about the comments and links therein (e.g. // [[c.math.hypot3]](https://eel.is/c++draft/c.math.hypot3), three-dimensional hypotenuse). Not sure if there is really a benefit if we also include those.

@mordante
Copy link
Member

The previous order was (almost?) an exact copy of the standard I believe (e.g. see https://eel.is/c++draft/c.math.syn). I see benefits to sticking to that order instead of defining a new one which might not be adhered to by new contributors.

The goal is indeed to match the synopsis in the Standard to validate what we have and have not implemented.

Nonetheless, there are things to update, e.g.

//
// from main
//
floating_point hypot (arithmetic x, arithmetic y);
float hypotf(float x, float y);
long double hypotl(long double x, long double y);

double hypot(double x, double y, double z); // C++17
float hypot(float x, float y, float z); // C++17
long double hypot(long double x, long double y, long double z); // C++17

//
// from the standard
//
constexpr floating-point-type hypot(floating-point-type x, floating-point-type y);
constexpr float hypotf(float x, float y);
constexpr long double hypotl(long double x, long double y);

// [c.math.hypot3], three-dimensional hypotenuse
constexpr floating-point-type hypot(floating-point-type x, floating-point-type y,
floating-point-type z);

Since we have not implemented constexpr hypot (and friends) they should not be marked constexpr in the synopsis.
This is our way to determine what the status of our implementation is. Deviations from the Standard should mean we're missing features. This helps tracking the status of larger papers that are partly implemented.

Side note: This may not be the best way, but it's the best we got. We discussed other ideas in the past, but haven't found a better solution.

@ldionne
Copy link
Member

ldionne commented Aug 19, 2024

Gentle ping on this -- do we want to move forward with some version of this, or close the PR?

@ldionne
Copy link
Member

ldionne commented Nov 28, 2024

I'm going to tentatively close this since it's fairly old, please reopen if you still want to pursue this.

@ldionne ldionne closed this Nov 28, 2024
@frederick-vs-ja
Copy link
Contributor Author

frederick-vs-ja commented Jan 9, 2025

Sorry for the late response. I won't pursue this PR, but I think the I'll make a larger cleanup for synopsis comments later.

@frederick-vs-ja frederick-vs-ja deleted the cmath-synopsis-comments branch January 9, 2025 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants