math_abs.cpp 434 B

123456789101112131415161718192021
  1. #include "simple/support/math/abs.hpp"
  2. #include <cassert>
  3. #include <type_traits>
  4. using simple::support::abs;
  5. int main()
  6. {
  7. static_assert(std::is_same_v<decltype(abs(short{})), int>);
  8. constexpr auto x = abs(-1);
  9. static_assert(x == 1);
  10. static_assert(abs(x) == 1);
  11. assert(abs(-13) == 13);
  12. assert(abs(13) == 13);
  13. static_assert(noexcept(abs(0)));
  14. static_assert(noexcept(abs(0.0)));
  15. static_assert(abs(-0.0) == 0.0);
  16. return 0;
  17. }