DxLibEx
fabs.hpp
Go to the documentation of this file.
1 /*=============================================================================
2  Copyright (c) 2011-2016 Bolero MURAKAMI
3  https://github.com/bolero-MURAKAMI/Sprout
4  Copyright (C) 2015-2017 DxLibEx project
5  https://github.com/Nagarei/DxLibEx/
6 
7  Distributed under the Boost Software License, Version 1.0.
8  (See http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
10 #ifndef DXLE_INC_MATH_FABS_HPP_
11 #define DXLE_INC_MATH_FABS_HPP_
12 #include "dxlibex/config/defines.h"
13 #include <cmath>
16 #ifdef DXLE_NO_CXX11_CONSTEXPR
17 namespace dxle{
18  namespace math{
19  using std::fabs;
20  }
21  using dxle::math::fabs;
22 }
23 #else //DXLE_NO_CXX11_CONSTEXPR
24 namespace dxle {
25  namespace math {
26  template<typename FloatType, enable_if_t<std::is_floating_point<FloatType>::value, std::nullptr_t> = nullptr>
27  inline DXLE_CONSTEXPR FloatType fabs(FloatType x) DXLE_NOEXCEPT_OR_NOTHROW
28  {
29  return
30  dxle::math::isnan(x) ? std::numeric_limits<FloatType>::quiet_NaN()
31  : x == 0 ? FloatType(0)
32  : dxle::math::copysign(x, FloatType(0))
33  ;
34  }
35  template<typename IntType, enable_if_t<std::is_integral<IntType>::value, std::nullptr_t> = nullptr>
36  inline DXLE_CONSTEXPR double fabs(IntType x) DXLE_NOEXCEPT_OR_NOTHROW
37  {
38  return dxle::math::fabs(static_cast<double>(x));
39  }
40  } // namespace math
41 
42  using dxle::math::fabs;
43 } // namespace dxle
44 #endif //DXLE_NO_CXX11_CONSTEXPR
45 #endif //DXLE_INC_MATH_FABS_HPP_
#define DXLE_CONSTEXPR
Definition: suffix.hpp:21
DXLE_CONSTEXPR FloatType copysign(FloatType x, FloatType y) DXLE_NOEXCEPT_OR_NOTHROW
Definition: copysign.hpp:47
DXLE_CONSTEXPR double fabs(IntType x) DXLE_NOEXCEPT_OR_NOTHROW
Definition: fabs.hpp:36
Definition: cast_if.hpp:12
DXLE_CONSTEXPR bool isnan(FloatType x) DXLE_NOEXCEPT_OR_NOTHROW
Definition: isnan.hpp:25
DXLE_CONSTEXPR FloatType fabs(FloatType x) DXLE_NOEXCEPT_OR_NOTHROW
Definition: fabs.hpp:27
#define DXLE_NOEXCEPT_OR_NOTHROW
Definition: suffix.hpp:94