21 #ifndef GNASH_NUMERIC_H
22 #define GNASH_NUMERIC_H
35 #include <boost/cstdint.hpp>
37 #include <boost/utility/enable_if.hpp>
44 static const double PI = 3.14159265358979323846;
49 #if defined(HAVE_FINITE) && !defined(HAVE_ISFINITE)
70 return std::max<T>(min, std::min<T>(
i, max));
77 return (b - a) * f +
a;
83 return static_cast<int>(f + 0.5f);
89 return static_cast<double>(i / 20.0);
92 template<
size_t Factor>
97 const double factor =
static_cast<double>(Factor);
106 static const double upperUnsignedLimit =
107 std::numeric_limits<boost::uint32_t>::max() + 1.0;
108 static const double upperSignedLimit =
109 std::numeric_limits<boost::int32_t>::max() / factor;
110 static const double lowerSignedLimit =
111 std::numeric_limits<boost::int32_t>::min() / factor;
113 if (a >= lowerSignedLimit && a <= upperSignedLimit) {
119 static_cast<boost::uint32_t
>(
120 std::fmod(a * factor, upperUnsignedLimit))
122 -static_cast<boost::uint32_t>(
123 std::fmod(-a * factor, upperUnsignedLimit));
127 inline boost::int32_t
130 return truncateWithFactor<20>(
a);