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