This is an archive of the discontinued LLVM Phabricator instance.

Added std::assoc_laguerre and std::laguerre [sf.cmath]
Needs ReviewPublic

Authored by thebrandre on Apr 18 2019, 7:36 AM.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Added std::assoc_laguerre and std::laguerre from C++17, 29.9.5 Mathematical special functions [sf.cmath].

Resubmitted parts of Added implementations of five Mathematical Special Functions added in C++17

Notes:

  • The algorithm is the same one that is used in boost and libstdc++. Just like boost (but unlike gcc-8.3.1), I use double internally for the float implementation and long double for the double implementation. This is kind of a last resort to achieve sufficiently accurate results ... considering the large number of floating-point operations involved for large n. Otherwise, we'd get less than 1% accuracy for float even in the range n<128 targeted by the standard. That's the case in libstdc++ (with gcc-8.3.1) . (Confirmed that by comparing the results for float and long double).
  • I haven't included a comparison with Visual Studio 2017 this time. It turns out, they simply use boost-1.66 internally and export the implementations in msvcp140_2.dll (which is exclusively for sf.cmath functions) to hide the boost headers. Interestingly, the special functions in boost have a lot of (partly surprising) dependencies across boost: lexical_cast, smart_ptr, preprocessor, concept_check, array, container, etc.
  • The implementation is inline just like libstdc++ but unlike Visual Studio 2017. The latter thus runs into AVX-SSE transition penalties: on my system, the dll being loaded (msvcp140_2.dll) is compiled without AVX and uses SSE instructions (floating-point operations usually do that). The inline implementation avoids that problem completely.

Related revisions:

Diff Detail

Event Timeline

thebrandre created this revision.Apr 18 2019, 7:36 AM
thebrandre edited the summary of this revision. (Show Details)

Changes analog to the latest changes to D60234 and D59937:

  • Signal "domain error" according C11 Standard 7.12.1 and not as std::domain_error. See D60234 for details.
  • Moved the tests for consistency with the latest changes in cmath (lerp).
  • Simplification of the tests: now using only one set of reference values generated by boost with multiprecision floats (256bit rounded to 128bit). I am pretty optimistic that every digit is correct, so that the comparison to libstdc++ no longer serves any purpose.
  • Rebased against current master branch.
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 2:10 PM