modf.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright John Maddock 2007.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MATH_MODF_HPP
  6. #define BOOST_MATH_MODF_HPP
  7. #ifdef _MSC_VER
  8. #pragma once
  9. #endif
  10. #include <boost/math/special_functions/math_fwd.hpp>
  11. #include <boost/math/tools/config.hpp>
  12. #include <boost/math/special_functions/trunc.hpp>
  13. namespace boost{ namespace math{
  14. template <class T, class Policy>
  15. inline T modf(const T& v, T* ipart, const Policy& pol)
  16. {
  17. *ipart = trunc(v, pol);
  18. return v - *ipart;
  19. }
  20. template <class T>
  21. inline T modf(const T& v, T* ipart)
  22. {
  23. return modf(v, ipart, policies::policy<>());
  24. }
  25. template <class T, class Policy>
  26. inline T modf(const T& v, int* ipart, const Policy& pol)
  27. {
  28. *ipart = itrunc(v, pol);
  29. return v - *ipart;
  30. }
  31. template <class T>
  32. inline T modf(const T& v, int* ipart)
  33. {
  34. return modf(v, ipart, policies::policy<>());
  35. }
  36. template <class T, class Policy>
  37. inline T modf(const T& v, long* ipart, const Policy& pol)
  38. {
  39. *ipart = ltrunc(v, pol);
  40. return v - *ipart;
  41. }
  42. template <class T>
  43. inline T modf(const T& v, long* ipart)
  44. {
  45. return modf(v, ipart, policies::policy<>());
  46. }
  47. template <class T, class Policy>
  48. inline T modf(const T& v, long long* ipart, const Policy& pol)
  49. {
  50. *ipart = lltrunc(v, pol);
  51. return v - *ipart;
  52. }
  53. template <class T>
  54. inline T modf(const T& v, long long* ipart)
  55. {
  56. return modf(v, ipart, policies::policy<>());
  57. }
  58. }} // namespaces
  59. #endif // BOOST_MATH_MODF_HPP