2012-04-01 13:15:09 +00:00
|
|
|
|
#ifndef SPROUT_CSTDLIB_ABS_HPP
|
|
|
|
|
#define SPROUT_CSTDLIB_ABS_HPP
|
|
|
|
|
|
2012-05-25 13:21:16 +00:00
|
|
|
|
#include <type_traits>
|
2012-04-01 13:15:09 +00:00
|
|
|
|
#include <sprout/config.hpp>
|
2012-05-26 15:43:38 +00:00
|
|
|
|
#include <sprout/type_traits/enabler_if.hpp>
|
2012-04-01 13:15:09 +00:00
|
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
|
// Copyright (C) 2011 RiSK (sscrisk)
|
|
|
|
|
|
|
|
|
|
// 7.20.6.1 abs<62>Clabs<62>C<EFBFBD>y<EFBFBD><79> llabs <20><EFBFBD>
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR int
|
|
|
|
|
abs(int j) {
|
2012-04-01 13:15:09 +00:00
|
|
|
|
return j < 0 ? -j : j;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR long
|
|
|
|
|
labs(long j) {
|
2012-04-01 13:15:09 +00:00
|
|
|
|
return j < 0 ? -j : j;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR long long
|
|
|
|
|
llabs(long long j) {
|
2012-04-01 13:15:09 +00:00
|
|
|
|
return j < 0 ? -j : j;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR long
|
|
|
|
|
abs(long j) {
|
2012-05-05 06:57:55 +00:00
|
|
|
|
return sprout::labs(j);
|
2012-04-01 13:15:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR long long
|
|
|
|
|
abs(long long j) {
|
2012-05-05 06:57:55 +00:00
|
|
|
|
return sprout::llabs(j);
|
2012-04-01 13:15:09 +00:00
|
|
|
|
}
|
2012-05-25 13:21:16 +00:00
|
|
|
|
|
2012-05-26 10:19:08 +00:00
|
|
|
|
namespace {
|
|
|
|
|
template<
|
|
|
|
|
typename IntType,
|
|
|
|
|
typename sprout::enabler_if<
|
|
|
|
|
std::is_integral<IntType>::value && std::is_signed<IntType>::value
|
|
|
|
|
>::type = sprout::enabler
|
|
|
|
|
>
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR IntType
|
|
|
|
|
abs(IntType j) {
|
2012-05-26 10:19:08 +00:00
|
|
|
|
return j < 0 ? -j : j;
|
|
|
|
|
}
|
|
|
|
|
template<
|
|
|
|
|
typename IntType,
|
|
|
|
|
typename sprout::enabler_if<
|
|
|
|
|
std::is_integral<IntType>::value && std::is_unsigned<IntType>::value
|
|
|
|
|
>::type = sprout::enabler
|
|
|
|
|
>
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR IntType
|
|
|
|
|
abs(IntType j) {
|
2012-05-26 10:19:08 +00:00
|
|
|
|
return j;
|
|
|
|
|
}
|
|
|
|
|
} // anonymous-namespace
|
2012-04-01 13:15:09 +00:00
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_CSTDLIB_ABS_HPP
|