This is an archive of the discontinued LLVM Phabricator instance.

Added implementations of five Mathematical Special Functions added in C++17.
AbandonedPublic

Authored by thebrandre on Mar 2 2019, 11:41 AM.

Details

Reviewers
libcxx-commits
Summary

Added implementations of std::assoc_laguerre, std::assoc_legendre, std::hermite, std::laguerre, and std::legendre as specified in ISO/IEC JTC 1/SC 22/WG 21 N3060 and in the C++17 standard.

The implementations were tested against the implementations of Visual Studio 2017 and libstdc++.
I got the same results up to floating-point precision with one exception:
libstdc++'s implementation of std::assoc_legendre doesn't fully adhere to the standard: it has the (pretty trivial) Condon-Shortley phase term, which is not part of the standard and explicitly excluded on cppreference.com.
Visual Studio 2017 complies to the standard in this respect.
I plan to submit that change to libstdc++ for consistency.

All float versions use double internally! It turns out that float is too small for, e.g, std::assoc_legendre in the range of m, l up to 127. You can pretty easily get NaN with float if you don't want to check for inf in each iteration.
The double implementation doesn't run into this problem in the range specified by the standard.

Diff Detail

Event Timeline

thebrandre created this revision.Mar 2 2019, 11:41 AM

Thanks for doing this; I'll be commenting on this today. Sorry for the lag.

  • Fixed compilation error of unit tests with clang (previously only tested with gcc).
  • Removed the checks for STDCPP_WANT_MATH_SPEC_FUNCS as specified in ISO/IEC JTC 1/SC 22/WG 21 N3060. The special functions are thus available if and only if C++17 is enabled.
  • Adjusted Doxygen style to LLVM Coding Standards (backslash instead of @)

Minor changes:

  • Applied clang-format and LLVM Coding Standards to all files.
  • Added unit tests for std::hermite. We now check the roots of the first 20 Hermite polynomials against values from the literature. And also check if the recurrence relation holds
thebrandre abandoned this revision.Apr 2 2019, 10:46 PM

I am going to resubmit the functions separately ... and will integrate it into the project just like https://reviews.llvm.org/D59937