21 #ifndef GNASH_NUMERIC_H
22 #define GNASH_NUMERIC_H
35 #include <boost/cstdint.hpp>
37 #include <boost/utility/enable_if.hpp>
38 #include <boost/type_traits/is_floating_point.hpp>
45 static const double PI = 3.14159265358979323846;
50 #if defined(HAVE_FINITE) && !defined(HAVE_ISFINITE)
62 typename boost::enable_if<boost::is_floating_point<T>,
bool>
::type
79 return std::max<T>(min, std::min<T>(
i, max));
86 return (b - a) * f +
a;
92 return static_cast<int>(f + 0.5f);
101 template<
size_t Factor>
112 const double factor =
static_cast<double>(Factor);
121 static const double upperUnsignedLimit =
122 std::numeric_limits<boost::uint32_t>::max() + 1.0;
123 static const double upperSignedLimit =
124 std::numeric_limits<boost::int32_t>::max() / factor;
125 static const double lowerSignedLimit =
126 std::numeric_limits<boost::int32_t>::min() / factor;
128 if (a >= lowerSignedLimit && a <= upperSignedLimit) {
134 static_cast<boost::uint32_t
>(
135 std::fmod(a * factor, upperUnsignedLimit))
137 -static_cast<boost::uint32_t>(
138 std::fmod(-a * factor, upperUnsignedLimit));
142 inline boost::int32_t
145 return truncateWithFactor<20>(
a);