|
23 | 23 | #include <ostream> |
24 | 24 | #endif |
25 | 25 |
|
| 26 | + namespace math { namespace fixed { |
| 27 | + |
| 28 | + // Forward declaration of the fixed_point template class. |
| 29 | + template<typename integer_type> |
| 30 | + class fixed_point; |
| 31 | + |
| 32 | + } // namespace fixed |
| 33 | + } // namespace math |
| 34 | + |
| 35 | + namespace math { namespace fixed { |
| 36 | + |
| 37 | + namespace detail { |
| 38 | + |
26 | 39 | // Utility structure to help with the epsilon limits for fixed_point. |
27 | 40 | // These special numbers represent the smallest value for a decimal part |
28 | 41 | // that differs from 1 for the corresponding decimal-part width. |
|
32 | 45 | template<> struct epsilon_helper<16U> { static const std::size_t epsilon_value = std::size_t(7U); }; |
33 | 46 | template<> struct epsilon_helper<32U> { static const std::size_t epsilon_value = std::size_t(44U); }; |
34 | 47 |
|
35 | | - // Forward declaration of the fixed_point template class. |
36 | | - template<typename integer_type> |
37 | | - class fixed_point; |
| 48 | + } // namespace detail |
38 | 49 |
|
39 | 50 | // The scalable fixed_point template class. |
40 | 51 | template<typename integer_type> |
|
322 | 333 | static fixed_point value_max () { return fixed_point(internal(), signed_value_type((unsigned_value_type(-1LL) - 1U) / 2U)); } |
323 | 334 | static fixed_point value_min () { return fixed_point(internal(), signed_value_type(2L)); } |
324 | 335 | static fixed_point value_half () { return fixed_point(internal(), signed_value_type(1ULL << (decimal_split - 1U))); } |
325 | | - static fixed_point value_eps () { return fixed_point(internal(), signed_value_type(epsilon_helper<decimal_split>::epsilon_value)); } |
| 336 | + static fixed_point value_eps () { return fixed_point(internal(), signed_value_type(detail::epsilon_helper<decimal_split>::epsilon_value)); } |
326 | 337 | static fixed_point value_pi () { return fixed_point(internal(), signed_value_type(0x3243f6A88ULL >> (32U - decimal_split))); } |
327 | 338 | static fixed_point value_pi_half () { return fixed_point(internal(), signed_value_type(0x1921FB544ULL >> (32U - decimal_split))); } |
328 | 339 | static fixed_point value_two_over_pi () { return fixed_point(internal(), signed_value_type(0x0A2F98370ULL >> (32U - decimal_split))); } |
|
545 | 556 | template<typename other_signed_type> friend inline bool operator> (const fixed_point<other_signed_type>& b, const fixed_point& a) { return (std::int_least8_t(-a.cmp(b)) > std::int_least8_t(0)); } |
546 | 557 |
|
547 | 558 | // Include a few global sample fixed_point functions. |
| 559 | + friend inline int fpclassify(const fixed_point& x) |
| 560 | + { |
| 561 | + return (x.data == signed_value_type(0) ? FP_ZERO : FP_NORMAL); |
| 562 | + } |
| 563 | + |
548 | 564 | friend inline fixed_point fabs(const fixed_point& x) |
549 | 565 | { |
550 | 566 | return fixed_point(internal(), (x.data < signed_value_type(0) ? -x.data : x.data)); |
|
941 | 957 | #endif // !FIXED_POINT_DISABLE_IOSTREAM |
942 | 958 | }; |
943 | 959 |
|
| 960 | + } // namespace fixed |
| 961 | + } // namespace math |
| 962 | + |
944 | 963 | // Define the four scalable fixed_point types. |
945 | | - typedef fixed_point<std::int8_t> fixed_point_3pt4; |
946 | | - typedef fixed_point<std::int16_t> fixed_point_7pt8; |
947 | | - typedef fixed_point<std::int32_t> fixed_point_15pt16; |
948 | | - typedef fixed_point<std::int64_t> fixed_point_31pt32; |
| 964 | + typedef math::fixed::fixed_point<std::int8_t> fixed_point_3pt4; |
| 965 | + typedef math::fixed::fixed_point<std::int16_t> fixed_point_7pt8; |
| 966 | + typedef math::fixed::fixed_point<std::int32_t> fixed_point_15pt16; |
| 967 | + typedef math::fixed::fixed_point<std::int64_t> fixed_point_31pt32; |
949 | 968 |
|
950 | 969 | namespace std |
951 | 970 | { |
|
956 | 975 | template<> class numeric_limits<fixed_point_31pt32> : public fixed_point_31pt32::my_numeric_limits { }; |
957 | 976 | } |
958 | 977 |
|
| 978 | + namespace math { namespace fixed { |
| 979 | + |
959 | 980 | // Include a few more global sample fixed_point functions. |
960 | 981 | template<typename fixed_point_type> |
961 | 982 | inline fixed_point_type sqrt(const fixed_point_type& x) { return fixed_point_type(x).calculate_sqrt(); } |
|
973 | 994 | return sqrt<fixed_point_type>((x * x) + (y * y)); |
974 | 995 | } |
975 | 996 |
|
| 997 | + } // namespace fixed |
| 998 | + } // namespace math |
| 999 | + |
976 | 1000 | #endif // FIXED_POINT_2011_02_22_H |
0 commit comments