The <cmath> implementation has a few things that I wanted to change. I originally planned to do them one at a time, but noticed that the changes essentially amount to a rewrite of the header, so I did that instead.
Specifically the changes are:
- Replacing _LIBCPP_INLINE_VISIBILITY with _LIBCPP_HIDE_FROM_ABI
- Moving the enable_ifs from the return type to a defaulted template parameter
- Removing the libcpp prefix on the argument names
- Granularizing the header
- Moving the functions into the versioned namespace
- Using builtins for the math functions
The libcpp prefix has been added for compatibility with newlib in D5080, but I think we can remove the workaround. We use __x elsewhere and newlib doesn't use __x in it's implementation since 2015 for GCC 2.97 and later. I think even older newlibs shouldn't be affected, since we don't rely on the macros from the libc with this patch.
The main functional change here is switching to builtins for all functions. This has multiple benefits:
- We can provide the full overload set of all functions without having to include the libc math.h
- We can support <cmath> during constant evaluation, even on platforms which don't have the functions implemented (once P0533R9 is implemented)
- Platforms with an incomplete implementation of math.h can use libc++ (there will be a link-time error if the functions are used instead of a compile-time error when trying to build libc++)
The main disadvantage of this patch is that it adds a double overload for all functions, but I think this is outweighed by the benefits, especially since the overloads are all just forwarding to __builtin_<function name>.