DxLibEx
abs.hpp
Go to the documentation of this file.
1 /*=============================================================================
2  Copyright (C) 2015-2017 DxLibEx project
3  https://github.com/Nagarei/DxLibEx/
4 
5  Distributed under the Boost Software License, Version 1.0.
6  (See http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #ifndef DXLE_INC_CSTDLIB_ABS_HPP_
9 #define DXLE_INC_CSTDLIB_ABS_HPP_
10 #include "dxlibex/config/defines.h"
11 #include <cstdlib>
13 #include <type_traits>
14 #ifdef DXLE_NO_CXX11_CONSTEXPR
15 namespace dxle{
16  using std::abs;
17 }
18 #else //DXLE_NO_CXX11_CONSTEXPR
19 namespace dxle {
20 
21  // 7.20.6.1 abs,labs,及び llabs 関数
23  {
24  return j < 0 ? -j : j;
25  }
26 
28  {
29  return j < 0 ? -j : j;
30  }
31 
32  inline DXLE_CONSTEXPR long long llabs(long long j) DXLE_NOEXCEPT_OR_NOTHROW
33  {
34  return j < 0 ? -j : j;
35  }
36 
37  inline DXLE_CONSTEXPR long abs(long j) DXLE_NOEXCEPT_OR_NOTHROW { return dxle::labs(j); }
38 
39  inline DXLE_CONSTEXPR long long abs(long long j) DXLE_NOEXCEPT_OR_NOTHROW { return dxle::llabs(j); }
40 
41  template<typename IntType, enable_if_t<std::is_integral<IntType>::value && std::is_signed<IntType>::value, std::nullptr_t> = nullptr>
42  inline DXLE_CONSTEXPR IntType abs(IntType j) DXLE_NOEXCEPT_OR_NOTHROW
43  {
44  return j < 0 ? -j : j;
45  }
46 
47 } // namespace dxle
48 #endif //DXLE_NO_CXX11_CONSTEXPR
49 namespace dxle{
50  template<typename IntType, enable_if_t<std::is_integral<IntType>::value && std::is_unsigned<IntType>::value, std::nullptr_t> = nullptr>
51  inline DXLE_CONSTEXPR IntType abs(IntType j) DXLE_NOEXCEPT_OR_NOTHROW
52  {
53  return j;
54  }
55 }
56 #endif //DXLE_INC_CSTDLIB_ABS_HPP_
#define DXLE_CONSTEXPR
Definition: suffix.hpp:21
DXLE_CONSTEXPR long long llabs(long long j) DXLE_NOEXCEPT_OR_NOTHROW
Definition: abs.hpp:32
DXLE_CONSTEXPR int abs(int j) DXLE_NOEXCEPT_OR_NOTHROW
Definition: abs.hpp:22
Definition: cast_if.hpp:12
DXLE_CONSTEXPR FloatType abs(FloatType x) DXLE_NOEXCEPT_OR_NOTHROW
Definition: abs.hpp:28
#define DXLE_NOEXCEPT_OR_NOTHROW
Definition: suffix.hpp:94
DXLE_CONSTEXPR long labs(long j) DXLE_NOEXCEPT_OR_NOTHROW
Definition: abs.hpp:27