This is an archive of the discontinued LLVM Phabricator instance.

Added implementation of expint [sf.cmath]
Needs ReviewPublic

Authored by thebrandre on Mar 28 2019, 8:32 AM.

Details

Reviewers
libcxx-commits
Summary

Added implementations of std::expint to cmath as specified in "29.9.5 Mathematical special functions [sf.cmath]" of the C++17 standard.

The implementation is based on Press, William H., et al. Numerical recipes 3rd edition: The art of scientific computing. Cambridge university press, 2007.

It is tested with a table of values generated by gcc-8.3.1 and boost-1.66.0 (confirmed with msvc-192027508 and boost-1.69.0) using boost::multiprecision::cpp_bin_float_oct (256bit float).

There are also tests for analytical bounds for large arguments and arguments close to the singularity.
And we also check the corner cases when +/- infinity or 0 is passed as an argument.

The implementation is inline for the same reason as mentioned in D60869.

Related revisions:

Diff Detail

Event Timeline

thebrandre created this revision.Mar 28 2019, 8:32 AM
thebrandre created this object with edit policy "thebrandre (Andre Brand)".
thebrandre added reviewers: Restricted Project, libcxx-commits.Mar 28 2019, 8:33 AM
thebrandre removed a reviewer: Restricted Project.Mar 28 2019, 9:37 AM
  • Moved expint from std::experimental to std -- from my understanding, that's where it belongs from C++17 onwards.
  • Added _NOEXCEPT because it doesn't throw and all the other functions in math.h have it, too.
  • Added the missing overloads for integral types.
thebrandre retitled this revision from Added implementation of expint (Math Special Functions) in std::experimental. to Added implementation of expint (Math Special Functions).Mar 29 2019, 9:06 AM
  • Fixed shared linking on Windows : the internal implementation libcpp_expint<T> is no longer exported via explicit instantiation of the template. Instead, there are now three functions libcpp_expintf, libcpp_expint, and libcpp_expintl annotated with _LIBCPP_FUNC_VIS. I also put them into namespace std.
  • Added "UNSUPPORTED: c++98, c++03, c++11, c++14" to the unit tests because std::expint is ifdef'ed out for versions prior to c++17.

Open questions:

  • The internal implementations libcpp_expintf, libcpp_expint, and __libcpp_expintl are currently exported even if _LIBCPP_STD_VER is 14 or less because the declarations with _LIBCPP_FUNC_VIS are outside the #if _LIBCPP_STD_VER > 14 ... so one might link the same binaries for all values of _LIBCPP_STD_VER. I am not quite sure if this is desired or aspired ...
  • The internal implementations could be put inside extern "C". But there is no actual benefit in doing so because the rest of the library doesn't do that either. Is that correct?

Sorry for all the corrections. I am new to the project ... but I have some hope that I finally got the hang of it. ;-)

thebrandre updated this revision to Diff 193021.EditedMar 31 2019, 12:22 PM
thebrandre edited the summary of this revision. (Show Details)

Updated the diff: no longer make changes to math.h (as specified in ISO/IEC JTC 1/SC 22/WG 21 N3060) but only to cmath (as specified in "29.9.5 Mathematical special functions [sf.cmath]") -- updated the summary accordingly.

thebrandre updated this revision to Diff 193850.Apr 5 2019, 3:08 AM
thebrandre retitled this revision from Added implementation of expint (Math Special Functions) to Added implementation of expint [sf.cmath].

A very small change in the synopsis in cmath: expint is now listed separately in a new category ... just as in 29.9.1 [cmath.syn].
This is also for consistency with https://reviews.llvm.org/D60234

thebrandre edited the summary of this revision. (Show Details)
  • The implementation is inline for the same reason as mentioned in D60869.
  • 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 other implementations no longer serves any purpose.
  • Rebased against current master branch.
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 2:11 PM