modf.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifdef BOOST_HAS_LONG_LONG
  48. template <class T, class Policy>
  49. inline T modf(const T& v, boost::long_long_type* ipart, const Policy& pol)
  50. {
  51. *ipart = lltrunc(v, pol);
  52. return v - *ipart;
  53. }
  54. template <class T>
  55. inline T modf(const T& v, boost::long_long_type* ipart)
  56. {
  57. return modf(v, ipart, policies::policy<>());
  58. }
  59. #endif
  60. }} // namespaces
  61. #endif // BOOST_MATH_MODF_HPP