fabs.hpp 1013 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // (C) Copyright Matt Borland 2021.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. // Constepxr implementation of fabs (see c.math.abs secion 26.8.2 of the ISO standard)
  7. #ifndef BOOST_MATH_CCMATH_FABS
  8. #define BOOST_MATH_CCMATH_FABS
  9. #include <boost/math/ccmath/detail/config.hpp>
  10. #ifdef BOOST_MATH_NO_CCMATH
  11. #error "The header <boost/math/fabs.hpp> can only be used in C++17 and later."
  12. #endif
  13. #include <boost/math/ccmath/abs.hpp>
  14. namespace boost::math::ccmath {
  15. template <typename T>
  16. inline constexpr auto fabs(T x) noexcept
  17. {
  18. return boost::math::ccmath::abs(x);
  19. }
  20. inline constexpr float fabsf(float x) noexcept
  21. {
  22. return boost::math::ccmath::abs(x);
  23. }
  24. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  25. inline constexpr long double fabsl(long double x) noexcept
  26. {
  27. return boost::math::ccmath::abs(x);
  28. }
  29. #endif
  30. }
  31. #endif // BOOST_MATH_CCMATH_FABS