[libcxx-commits] [libcxx] [libc++][math] Mathematical Special Functions: Hermite Polynomial (PR #89982)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Apr 28 12:24:10 PDT 2024
================
@@ -765,6 +766,54 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp __constexpr_scalbn(_Tp _
return __builtin_scalbn(__x, __exp);
}
+#if _LIBCPP_STD_VER >= 17
+
+/// \return the Hermite polynomial \f$ H_n(x) \f$
+/// \note The implementation is based on the recurrence formula
+/// \f[
+/// H_{n+1}(x) = 2x H_n(x) - 2n H_{n-1}
+/// \f]
+/// Press, William H., et al. Numerical recipes 3rd edition: The art of
+/// scientific computing. Cambridge university press, 2007, p. 183.
+template <class _Real>
+_LIBCPP_HIDE_FROM_ABI _Real __hermite(unsigned __n, _Real __x) {
+ if (std::isnan(__x))
+ return std::numeric_limits<_Real>::quiet_NaN();
----------------
PaulXiCao wrote:
For reference, the [Standard 28.7.6.1.1](https://wg21.link/sf.cmath.general): "_If any argument value to any of the functions specified in [sf.cmath] is a NaN (Not a Number), the function shall return a NaN but it shall not report a domain error. ..._"
I would interpret this as we must return a NaN but the actual NaN type is implemenation-defined?!
But as you point it out, I thought some more about it and I might also prefer the straight-forward alternative: `if (isnan(x)) return x;`.
Note, that the initial version (older abandoned mr) also contained the conversion.
I had a quick peed into my local libstdc++ installation. It also uses the conversion to `quiet_NaN`. Which makes we wonder if there is a deeper reason to it?
https://github.com/llvm/llvm-project/pull/89982
More information about the libcxx-commits
mailing list