Blame view

3rdparty/boost_1_81_0/boost/math/ccmath/modf.hpp 1.92 KB
63e88f80   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  //  (C) Copyright Matt Borland 2021.
  //  Use, modification and distribution are subject to the
  //  Boost Software License, Version 1.0. (See accompanying file
  //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  
  #ifndef BOOST_MATH_CCMATH_MODF_HPP
  #define BOOST_MATH_CCMATH_MODF_HPP
  
  #include <cmath>
  #include <limits>
  #include <type_traits>
  #include <boost/math/tools/is_constant_evaluated.hpp>
  #include <boost/math/ccmath/abs.hpp>
  #include <boost/math/ccmath/isinf.hpp>
  #include <boost/math/ccmath/isnan.hpp>
  #include <boost/math/ccmath/trunc.hpp>
  
  namespace boost::math::ccmath {
  
  namespace detail {
  
  template <typename Real>
  inline constexpr Real modf_error_impl(Real x, Real* iptr)
  {
      *iptr = x;
      return boost::math::ccmath::abs(x) == Real(0) ? x :
             x > Real(0) ? Real(0) : -Real(0);
  }
  
  template <typename Real>
  inline constexpr Real modf_nan_impl(Real x, Real* iptr)
  {
      *iptr = x;
      return x;
  }
  
  template <typename Real>
  inline constexpr Real modf_impl(Real x, Real* iptr)
  {
      *iptr = boost::math::ccmath::trunc(x);
      return (x - *iptr);
  }
  
  } // Namespace detail
  
  template <typename Real>
  inline constexpr Real modf(Real x, Real* iptr)
  {
      if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))
      {
          return boost::math::ccmath::abs(x) == Real(0) ? detail::modf_error_impl(x, iptr) :
                 boost::math::ccmath::isinf(x) ? detail::modf_error_impl(x, iptr) :
                 boost::math::ccmath::isnan(x) ? detail::modf_nan_impl(x, iptr) :
                 boost::math::ccmath::detail::modf_impl(x, iptr);
      }
      else
      {
          using std::modf;
          return modf(x, iptr);
      }
  }
  
  inline constexpr float modff(float x, float* iptr)
  {
      return boost::math::ccmath::modf(x, iptr);
  }
  
  #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  inline constexpr long double modfl(long double x, long double* iptr)
  {
      return boost::math::ccmath::modf(x, iptr);
  }
  #endif
  
  } // Namespaces
  
  #endif // BOOST_MATH_CCMATH_MODF_HPP