17 #ifndef GZ_MATH_FUNCTIONS_HH_
18 #define GZ_MATH_FUNCTIONS_HH_
31 #include <gz/math/config.hh>
32 #include "gz/math/Export.hh"
47 #define GZ_PI_2 M_PI_2
48 #define GZ_PI_4 M_PI_4
49 #define GZ_SQRT2 M_SQRT2
51 #define GZ_PI 3.14159265358979323846
52 #define GZ_PI_2 1.57079632679489661923
53 #define GZ_PI_4 0.78539816339744830962
54 #define GZ_SQRT2 1.41421356237309504880
60 #if defined __FLT_EVAL_METHOD__ && __FLT_EVAL_METHOD__ == 2
61 #define GZ_FP_VOLATILE volatile
63 #define GZ_FP_VOLATILE
68 #define GZ_SPHERE_VOLUME(_radius) (4.0*GZ_PI*std::pow(_radius, 3)/3.0)
73 #define GZ_CONE_VOLUME(_r, _l) (_l * GZ_PI * std::pow(_r, 2) / 3.0)
78 #define GZ_CYLINDER_VOLUME(_r, _l) (_l * GZ_PI * std::pow(_r, 2))
84 #define GZ_BOX_VOLUME(_x, _y, _z) (_x *_y * _z)
88 #define GZ_BOX_VOLUME_V(_v) (_v.X() *_v.Y() * _v.Z())
93 inline namespace GZ_MATH_VERSION_NAMESPACE {
144 static const
double LOW_D =
std::numeric_limits<
double>::lowest();
147 static const
double INF_D =
std::numeric_limits<
double>::infinity();
150 static const
double NAN_D =
std::numeric_limits<
double>::quiet_NaN();
159 static const
float LOW_F =
std::numeric_limits<
float>::lowest();
162 static const
float INF_F =
std::numeric_limits<
float>::infinity();
165 static const
float NAN_F =
std::numeric_limits<
float>::quiet_NaN();
175 static const uint16_t
LOW_UI16 =
std::numeric_limits<uint16_t>::lowest();
178 static const uint16_t
INF_UI16 =
std::numeric_limits<uint16_t>::infinity();
188 static const int16_t
LOW_I16 =
std::numeric_limits<int16_t>::lowest();
191 static const int16_t
INF_I16 =
std::numeric_limits<int16_t>::infinity();
201 static const uint32_t
LOW_UI32 =
std::numeric_limits<uint32_t>::lowest();
204 static const uint32_t
INF_UI32 =
std::numeric_limits<uint32_t>::infinity();
214 static const int32_t
LOW_I32 =
std::numeric_limits<int32_t>::lowest();
217 static const int32_t
INF_I32 =
std::numeric_limits<int32_t>::infinity();
227 static const uint64_t
LOW_UI64 =
std::numeric_limits<uint64_t>::lowest();
230 static const uint64_t
INF_UI64 =
std::numeric_limits<uint64_t>::infinity();
240 static const int64_t
LOW_I64 =
std::numeric_limits<int64_t>::lowest();
243 static const int64_t
INF_I64 =
std::numeric_limits<int64_t>::infinity();
246 static const
int NAN_I =
std::numeric_limits<
int>::quiet_NaN();
256 inline T
clamp(T _v, T _min, T _max)
304 inline bool isEven(
const unsigned int _v)
314 return (_v % 2) != 0;
320 inline bool isOdd(
const unsigned int _v)
322 return (_v % 2) != 0;
334 return (T(0) < _value) - (_value < T(0));
356 for (
unsigned int i = 0; i < _values.
size(); ++i)
358 return sum /
static_cast<T
>(_values.
size());
367 T avg = mean<T>(_values);
370 for (
unsigned int i = 0; i < _values.
size(); ++i)
371 sum += (_values[i] - avg) * (_values[i] - avg);
372 return sum /
static_cast<T
>(_values.
size());
399 inline bool equal(
const T &_a,
const T &_b,
400 const T &_epsilon = T(1e-6))
403 return diff <= _epsilon;
413 const T &_epsilon = 1e-6)
415 return _a < _b + _epsilon;
425 const T &_epsilon = 1e-6)
427 return _a > _b - _epsilon;
435 inline T
precision(
const T &_a,
const unsigned int &_precision)
438 return static_cast<T
>(
std::round(_a * p) / p);
461 inline void sort3(T &_a, T &_b, T &_c)
501 return ((_x != 0) && ((_x & (~_x + 1)) == _x));
517 while (_x & (_x - 1))
540 int remainder = std::abs(_num) % _multiple;
545 return -(std::abs(_num) - remainder);
547 return _num + _multiple - remainder;
567 const std::chrono::steady_clock::time_point &_time);
575 std::chrono::steady_clock::time_point GZ_MATH_VISIBLE
577 const uint64_t &_sec,
const uint64_t &_nanosec);
586 const uint64_t &_sec,
const uint64_t &_nanosec);
594 const std::chrono::steady_clock::duration &_dur);
607 template<
class...Durations,
class DurationIn>
610 using discard =
int[];
611 (void)discard{0, (void((
612 (std::get<Durations>(retval) =
613 std::chrono::duration_cast<Durations>(d)),
614 (d -= std::chrono::duration_cast<DurationIn>(
615 std::get<Durations>(retval))))), 0)...};
623 const std::chrono::steady_clock::time_point &_point);
629 const std::chrono::steady_clock::duration &_duration);
641 uint64_t & numberDays, uint64_t & numberHours,
642 uint64_t & numberMinutes, uint64_t & numberSeconds,
643 uint64_t & numberMilliseconds);
652 uint64_t d, h, m, s, ms;
671 std::chrono::steady_clock::time_point
678 #if defined _MSC_VER || defined __arm__
713 #endif // GZ_MATH_FUNCTIONS_HH_