Skip to content

Commit 2d1798e

Browse files
committed
Place fixed_point class in namespaces
1 parent f92da81 commit 2d1798e

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

ref_app/src/app/benchmark/app_benchmark_fixed_point.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2010 - 2019.
2+
// Copyright Christopher Kormanyos 2010 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -18,7 +18,7 @@
1818

1919
namespace
2020
{
21-
using fixed_point_type = fixed_point<std::int32_t>;
21+
using fixed_point_type = ::math::fixed::fixed_point<std::int32_t>;
2222
}
2323

2424
extern fixed_point_type global_a;

ref_app/src/math/fixed_point/fixed_point.h

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@
2323
#include <ostream>
2424
#endif
2525

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+
2639
// Utility structure to help with the epsilon limits for fixed_point.
2740
// These special numbers represent the smallest value for a decimal part
2841
// that differs from 1 for the corresponding decimal-part width.
@@ -32,9 +45,7 @@
3245
template<> struct epsilon_helper<16U> { static const std::size_t epsilon_value = std::size_t(7U); };
3346
template<> struct epsilon_helper<32U> { static const std::size_t epsilon_value = std::size_t(44U); };
3447

35-
// Forward declaration of the fixed_point template class.
36-
template<typename integer_type>
37-
class fixed_point;
48+
} // namespace detail
3849

3950
// The scalable fixed_point template class.
4051
template<typename integer_type>
@@ -322,7 +333,7 @@
322333
static fixed_point value_max () { return fixed_point(internal(), signed_value_type((unsigned_value_type(-1LL) - 1U) / 2U)); }
323334
static fixed_point value_min () { return fixed_point(internal(), signed_value_type(2L)); }
324335
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)); }
326337
static fixed_point value_pi () { return fixed_point(internal(), signed_value_type(0x3243f6A88ULL >> (32U - decimal_split))); }
327338
static fixed_point value_pi_half () { return fixed_point(internal(), signed_value_type(0x1921FB544ULL >> (32U - decimal_split))); }
328339
static fixed_point value_two_over_pi () { return fixed_point(internal(), signed_value_type(0x0A2F98370ULL >> (32U - decimal_split))); }
@@ -545,6 +556,11 @@
545556
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)); }
546557

547558
// 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+
548564
friend inline fixed_point fabs(const fixed_point& x)
549565
{
550566
return fixed_point(internal(), (x.data < signed_value_type(0) ? -x.data : x.data));
@@ -941,11 +957,14 @@
941957
#endif // !FIXED_POINT_DISABLE_IOSTREAM
942958
};
943959

960+
} // namespace fixed
961+
} // namespace math
962+
944963
// 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;
949968

950969
namespace std
951970
{
@@ -956,6 +975,8 @@
956975
template<> class numeric_limits<fixed_point_31pt32> : public fixed_point_31pt32::my_numeric_limits { };
957976
}
958977

978+
namespace math { namespace fixed {
979+
959980
// Include a few more global sample fixed_point functions.
960981
template<typename fixed_point_type>
961982
inline fixed_point_type sqrt(const fixed_point_type& x) { return fixed_point_type(x).calculate_sqrt(); }
@@ -973,4 +994,7 @@
973994
return sqrt<fixed_point_type>((x * x) + (y * y));
974995
}
975996

997+
} // namespace fixed
998+
} // namespace math
999+
9761000
#endif // FIXED_POINT_2011_02_22_H

0 commit comments

Comments
 (0)