1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2014-2015 Oracle and/or its affiliates.
6 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9 // Licensed under the Boost Software License version 1.0.
10 // http://www.boost.org/users/license.html
12 #ifndef BOOST_GEOMETRY_TEST_UTIL_NUMBER_TYPES_HPP
13 #define BOOST_GEOMETRY_TEST_UTIL_NUMBER_TYPES_HPP
18 // define a custom number type and its sqrt in own namespace
19 namespace number_types
25 typedef custom<T> self;
29 custom() : m_value(0) {}
30 explicit custom(T const& value) : m_value(value) {}
32 bool operator<(self const& other) const
34 return m_value < other.m_value;
37 self operator-() const
39 return self(-m_value);
42 self operator-(self const& other) const
44 return self(m_value - other.m_value);
49 inline custom<T> sqrt(custom<T> const& c)
51 return custom<T>(std::sqrt(c.m_value));
55 inline custom<T> fabs(custom<T> const& c)
57 return custom<T>(c.m_value < T(0) ? c.m_value : -c.m_value);
60 } // namespace number_types
67 // define a custom number type with sqrt in global namespace
68 namespace number_types
72 struct custom_with_global_sqrt
74 typedef custom_with_global_sqrt<T> self;
78 custom_with_global_sqrt() : m_value(0) {}
79 explicit custom_with_global_sqrt(T const& value) : m_value(value) {}
81 bool operator<(self const& other) const
83 return m_value < other.m_value;
86 self operator-() const
88 return self(-m_value);
91 self operator-(self const& other) const
93 return self(m_value - other.m_value);
97 } // namespace number_types
100 inline number_types::custom_with_global_sqrt<T>
101 sqrt(number_types::custom_with_global_sqrt<T> const& c)
103 return number_types::custom_with_global_sqrt<T>(std::sqrt(c.m_value));
106 template <typename T>
107 inline number_types::custom_with_global_sqrt<T>
108 fabs(number_types::custom_with_global_sqrt<T> const& c)
110 return number_types::custom_with_global_sqrt<T>
111 (c.m_value < T(0) ? c.m_value : -c.m_value);
119 // define a custom number type and its sqrt in global namespace
120 template <typename T>
123 typedef custom_global<T> self;
127 custom_global() : m_value(0) {}
128 explicit custom_global(T const& value) : m_value(value) {}
130 bool operator<(self const& other) const
132 return m_value < other.m_value;
135 self operator-() const
137 return self(-m_value);
140 self operator-(self const& other) const
142 return self(m_value - other.m_value);
146 template <typename T>
147 inline custom_global<T> sqrt(custom_global<T> const& c)
149 return custom_global<T>(std::sqrt(c.m_value));
152 template <typename T>
153 inline custom_global<T> fabs(custom_global<T> const& c)
155 return custom_global<T>(c.m_value < T(0) ? c.m_value : -c.m_value);
160 // custom number type without functions definition
161 template <typename T>
164 typedef custom_raw<T> self;
168 custom_raw() : m_value(0) {}
169 explicit custom_raw(T const& value) : m_value(value) {}
171 bool operator<(self const& other) const
173 return m_value < other.m_value;
176 self operator-() const
178 return self(-m_value);
181 self operator-(self const& other) const
183 return self(m_value - other.m_value);
187 #endif // BOOST_GEOMETRY_TEST_UTIL_NUMBER_TYPES_HPP