Ignition Math

API Reference

6.4.0
Helpers.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_MATH_FUNCTIONS_HH_
18 #define IGNITION_MATH_FUNCTIONS_HH_
19 
20 #include <algorithm>
21 #include <chrono>
22 #include <cmath>
23 #include <cstdint>
24 #include <iomanip>
25 #include <iostream>
26 #include <limits>
27 #include <sstream>
28 #include <string>
29 #include <tuple>
30 #include <utility>
31 #include <vector>
32 
33 #include <ignition/math/config.hh>
34 #include "ignition/math/Export.hh"
35 
38 template <typename T>
40 
43 #define IGN_DBL_MAX ignition::math::DPRCT_MAX_D
44 
47 #define IGN_DBL_MIN ignition::math::DPRCT_MIN_D
48 
51 #define IGN_DBL_LOW ignition::math::DPRCT_LOW_D
52 
55 #define IGN_DBL_INF ignition::math::DPRCT_INF_D
56 
59 #define IGN_FLT_MAX ignition::math::DPRCT_MAX_F
60 
63 #define IGN_FLT_MIN ignition::math::DPRCT_MIN_F
64 
67 #define IGN_FLT_LOW ignition::math::DPRCT_LOW_F
68 
71 #define IGN_FLT_INF ignition::math::DPRCT_INF_F
72 
75 #define IGN_UINT16_MAX ignition::math::DPRCT_MAX_UI16
76 
79 #define IGN_UINT16_MIN ignition::math::DPRCT_MIN_UI16
80 
84 #define IGN_UINT16_LOW ignition::math::DPRCT_LOW_UI16
85 
88 #define IGN_UINT16_INF ignition::math::DPRCT_INF_UI16
89 
92 #define IGN_INT16_MAX ignition::math::DPRCT_MAX_I16
93 
96 #define IGN_INT16_MIN ignition::math::DPRCT_MIN_I16
97 
101 #define IGN_INT16_LOW ignition::math::DPRCT_LOW_I16
102 
105 #define IGN_INT16_INF ignition::math::DPRCT_INF_I16
106 
109 #define IGN_UINT32_MAX ignition::math::DPRCT_MAX_UI32
110 
113 #define IGN_UINT32_MIN ignition::math::DPRCT_MIN_UI32
114 
118 #define IGN_UINT32_LOW ignition::math::DPRCT_LOW_UI32
119 
122 #define IGN_UINT32_INF ignition::math::DPRCT_INF_UI32
123 
126 #define IGN_INT32_MAX ignition::math::DPRCT_MAX_I32
127 
130 #define IGN_INT32_MIN ignition::math::DPRCT_MIN_I32
131 
135 #define IGN_INT32_LOW ignition::math::DPRCT_LOW_I32
136 
139 #define IGN_INT32_INF ignition::math::DPRCT_INF_I32
140 
143 #define IGN_UINT64_MAX ignition::math::DPRCT_MAX_UI64
144 
147 #define IGN_UINT64_MIN ignition::math::DPRCT_MIN_UI64
148 
152 #define IGN_UINT64_LOW ignition::math::DPRCT_LOW_UI64
153 
156 #define IGN_UINT64_INF ignition::math::DPRCT_INF_UI64
157 
160 #define IGN_INT64_MAX ignition::math::DPRCT_MAX_I64
161 
164 #define IGN_INT64_MIN ignition::math::DPRCT_MIN_I64
165 
169 #define IGN_INT64_LOW ignition::math::DPRCT_LOW_I64
170 
173 #define IGN_INT64_INF ignition::math::DPRCT_INF_I64
174 
177 #ifdef M_PI
178 #define IGN_PI M_PI
179 #define IGN_PI_2 M_PI_2
180 #define IGN_PI_4 M_PI_4
181 #define IGN_SQRT2 M_SQRT2
182 #else
183 #define IGN_PI 3.14159265358979323846
184 #define IGN_PI_2 1.57079632679489661923
185 #define IGN_PI_4 0.78539816339744830962
186 #define IGN_SQRT2 1.41421356237309504880
187 #endif
188 
192 #if defined __FLT_EVAL_METHOD__ && __FLT_EVAL_METHOD__ == 2
193 #define IGN_FP_VOLATILE volatile
194 #else
195 #define IGN_FP_VOLATILE
196 #endif
197 
200 #define IGN_SPHERE_VOLUME(_radius) (4.0*IGN_PI*std::pow(_radius, 3)/3.0)
201 
205 #define IGN_CYLINDER_VOLUME(_r, _l) (_l * IGN_PI * std::pow(_r, 2))
206 
211 #define IGN_BOX_VOLUME(_x, _y, _z) (_x *_y * _z)
212 
215 #define IGN_BOX_VOLUME_V(_v) (_v.X() *_v.Y() * _v.Z())
216 
217 namespace ignition
218 {
220  namespace math
221  {
222  // Inline bracket to help doxygen filtering.
223  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
224  //
226  static const size_t IGN_ZERO_SIZE_T = 0u;
227 
229  static const size_t IGN_ONE_SIZE_T = 1u;
230 
232  static const size_t IGN_TWO_SIZE_T = 2u;
233 
235  static const size_t IGN_THREE_SIZE_T = 3u;
236 
238  static const size_t IGN_FOUR_SIZE_T = 4u;
239 
241  static const size_t IGN_FIVE_SIZE_T = 5u;
242 
244  static const size_t IGN_SIX_SIZE_T = 6u;
245 
247  static const size_t IGN_SEVEN_SIZE_T = 7u;
248 
250  static const size_t IGN_EIGHT_SIZE_T = 8u;
251 
253  static const size_t IGN_NINE_SIZE_T = 9u;
254 
256  static const double MAX_D = std::numeric_limits<double>::max();
257 
259  static const double MIN_D = std::numeric_limits<double>::min();
260 
263 
266 
269 
271  static const float MAX_F = std::numeric_limits<float>::max();
272 
274  static const float MIN_F = std::numeric_limits<float>::min();
275 
278 
281 
284 
286  static const uint16_t MAX_UI16 = std::numeric_limits<uint16_t>::max();
287 
289  static const uint16_t MIN_UI16 = std::numeric_limits<uint16_t>::min();
290 
294 
297 
299  static const int16_t MAX_I16 = std::numeric_limits<int16_t>::max();
300 
302  static const int16_t MIN_I16 = std::numeric_limits<int16_t>::min();
303 
307 
310 
312  static const uint32_t MAX_UI32 = std::numeric_limits<uint32_t>::max();
313 
315  static const uint32_t MIN_UI32 = std::numeric_limits<uint32_t>::min();
316 
320 
323 
325  static const int32_t MAX_I32 = std::numeric_limits<int32_t>::max();
326 
328  static const int32_t MIN_I32 = std::numeric_limits<int32_t>::min();
329 
333 
336 
338  static const uint64_t MAX_UI64 = std::numeric_limits<uint64_t>::max();
339 
341  static const uint64_t MIN_UI64 = std::numeric_limits<uint64_t>::min();
342 
346 
349 
351  static const int64_t MAX_I64 = std::numeric_limits<int64_t>::max();
352 
354  static const int64_t MIN_I64 = std::numeric_limits<int64_t>::min();
355 
359 
362 
365 
366  // variables created to deprecate macros in this file
367  static const double IGN_DEPRECATED(3) DPRCT_MAX_D = MAX_D;
368  static const double IGN_DEPRECATED(3) DPRCT_MIN_D = MIN_D;
369  static const double IGN_DEPRECATED(3) DPRCT_LOW_D = LOW_D;
370  static const double IGN_DEPRECATED(3) DPRCT_INF_D = INF_D;
371  static const float IGN_DEPRECATED(3) DPRCT_MAX_F = MAX_F;
372  static const float IGN_DEPRECATED(3) DPRCT_MIN_F = MIN_F;
373  static const float IGN_DEPRECATED(3) DPRCT_LOW_F = LOW_F;
374  static const float IGN_DEPRECATED(3) DPRCT_INF_F = INF_F;
375  static const uint16_t IGN_DEPRECATED(3) DPRCT_MAX_UI16 = MAX_UI16;
376  static const uint16_t IGN_DEPRECATED(3) DPRCT_MIN_UI16 = MIN_UI16;
377  static const uint16_t IGN_DEPRECATED(3) DPRCT_LOW_UI16 = LOW_UI16;
378  static const uint16_t IGN_DEPRECATED(3) DPRCT_INF_UI16 = INF_UI16;
379  static const int16_t IGN_DEPRECATED(3) DPRCT_MAX_I16 = MAX_I16;
380  static const int16_t IGN_DEPRECATED(3) DPRCT_MIN_I16 = MIN_I16;
381  static const int16_t IGN_DEPRECATED(3) DPRCT_LOW_I16 = LOW_I16;
382  static const int16_t IGN_DEPRECATED(3) DPRCT_INF_I16 = INF_I16;
383  static const uint32_t IGN_DEPRECATED(3) DPRCT_MAX_UI32 = MAX_UI32;
384  static const uint32_t IGN_DEPRECATED(3) DPRCT_MIN_UI32 = MIN_UI32;
385  static const uint32_t IGN_DEPRECATED(3) DPRCT_LOW_UI32 = LOW_UI32;
386  static const uint32_t IGN_DEPRECATED(3) DPRCT_INF_UI32 = INF_UI32;
387  static const int32_t IGN_DEPRECATED(3) DPRCT_MAX_I32 = MAX_I32;
388  static const int32_t IGN_DEPRECATED(3) DPRCT_MIN_I32 = MIN_I32;
389  static const int32_t IGN_DEPRECATED(3) DPRCT_LOW_I32 = LOW_I32;
390  static const int32_t IGN_DEPRECATED(3) DPRCT_INF_I32 = INF_I32;
391  static const uint64_t IGN_DEPRECATED(3) DPRCT_MAX_UI64 = MAX_UI64;
392  static const uint64_t IGN_DEPRECATED(3) DPRCT_MIN_UI64 = MIN_UI64;
393  static const uint64_t IGN_DEPRECATED(3) DPRCT_LOW_UI64 = LOW_UI64;
394  static const uint64_t IGN_DEPRECATED(3) DPRCT_INF_UI64 = INF_UI64;
395  static const int64_t IGN_DEPRECATED(3) DPRCT_MAX_I64 = MAX_I64;
396  static const int64_t IGN_DEPRECATED(3) DPRCT_MIN_I64 = MIN_I64;
397  static const int64_t IGN_DEPRECATED(3) DPRCT_LOW_I64 = LOW_I64;
398  static const int64_t IGN_DEPRECATED(3) DPRCT_INF_I64 = INF_I64;
399 
404  template<typename T>
405  inline T clamp(T _v, T _min, T _max)
406  {
407  return std::max(std::min(_v, _max), _min);
408  }
409 
413  inline bool isnan(float _v)
414  {
415  return (std::isnan)(_v);
416  }
417 
421  inline bool isnan(double _v)
422  {
423  return (std::isnan)(_v);
424  }
425 
429  inline float fixnan(float _v)
430  {
431  return isnan(_v) || std::isinf(_v) ? 0.0f : _v;
432  }
433 
437  inline double fixnan(double _v)
438  {
439  return isnan(_v) || std::isinf(_v) ? 0.0 : _v;
440  }
441 
445  inline bool isEven(const int _v)
446  {
447  return !(_v % 2);
448  }
449 
453  inline bool isEven(const unsigned int _v)
454  {
455  return !(_v % 2);
456  }
457 
461  inline bool isOdd(const int _v)
462  {
463  return (_v % 2) != 0;
464  }
465 
469  inline bool isOdd(const unsigned int _v)
470  {
471  return (_v % 2) != 0;
472  }
473 
480  template<typename T>
481  inline int sgn(T _value)
482  {
483  return (T(0) < _value) - (_value < T(0));
484  }
485 
492  template<typename T>
493  inline int signum(T _value)
494  {
495  return sgn(_value);
496  }
497 
501  template<typename T>
502  inline T mean(const std::vector<T> &_values)
503  {
504  T sum = 0;
505  for (unsigned int i = 0; i < _values.size(); ++i)
506  sum += _values[i];
507  return sum / _values.size();
508  }
509 
513  template<typename T>
514  inline T variance(const std::vector<T> &_values)
515  {
516  T avg = mean<T>(_values);
517 
518  T sum = 0;
519  for (unsigned int i = 0; i < _values.size(); ++i)
520  sum += (_values[i] - avg) * (_values[i] - avg);
521  return sum / _values.size();
522  }
523 
527  template<typename T>
528  inline T max(const std::vector<T> &_values)
529  {
531  for (unsigned int i = 0; i < _values.size(); ++i)
532  if (_values[i] > max)
533  max = _values[i];
534  return max;
535  }
536 
540  template<typename T>
541  inline T min(const std::vector<T> &_values)
542  {
544  for (unsigned int i = 0; i < _values.size(); ++i)
545  if (_values[i] < min)
546  min = _values[i];
547  return min;
548  }
549 
554  template<typename T>
555  inline bool equal(const T &_a, const T &_b,
556  const T &_epsilon = T(1e-6))
557  {
558  IGN_FP_VOLATILE T diff = std::abs(_a - _b);
559  return diff <= _epsilon;
560  }
561 
566  template<typename T>
567  inline bool lessOrNearEqual(const T &_a, const T &_b,
568  const T &_epsilon = 1e-6)
569  {
570  return _a < _b + _epsilon;
571  }
572 
577  template<typename T>
578  inline bool greaterOrNearEqual(const T &_a, const T &_b,
579  const T &_epsilon = 1e-6)
580  {
581  return _a > _b - _epsilon;
582  }
583 
588  template<typename T>
589  inline T precision(const T &_a, const unsigned int &_precision)
590  {
591  auto p = std::pow(10, _precision);
592  return static_cast<T>(std::round(_a * p) / p);
593  }
594 
598  template<typename T>
599  inline void sort2(T &_a, T &_b)
600  {
601  using std::swap;
602  if (_b < _a)
603  swap(_a, _b);
604  }
605 
610  template<typename T>
611  inline void sort3(T &_a, T &_b, T &_c)
612  {
613  // _a <= _b
614  sort2(_a, _b);
615  // _a <= _c, _b <= _c
616  sort2(_b, _c);
617  // _a <= _b <= _c
618  sort2(_a, _b);
619  }
620 
624  inline bool isPowerOfTwo(unsigned int _x)
625  {
626  return ((_x != 0) && ((_x & (~_x + 1)) == _x));
627  }
628 
634  inline unsigned int roundUpPowerOfTwo(unsigned int _x)
635  {
636  if (_x == 0)
637  return 1;
638 
639  if (isPowerOfTwo(_x))
640  return _x;
641 
642  while (_x & (_x - 1))
643  _x = _x & (_x - 1);
644 
645  _x = _x << 1;
646 
647  return _x;
648  }
649 
660  inline int roundUpMultiple(int _num, int _multiple)
661  {
662  if (_multiple == 0)
663  return _num;
664 
665  int remainder = std::abs(_num) % _multiple;
666  if (remainder == 0)
667  return _num;
668 
669  if (_num < 0)
670  return -(std::abs(_num) - remainder);
671  else
672  return _num + _multiple - remainder;
673  }
674 
678  inline int parseInt(const std::string &_input)
679  {
680  // Return NAN_I if it is empty
681  if (_input.empty())
682  {
683  return NAN_I;
684  }
685  // Return 0 if it is all spaces
686  else if (_input.find_first_not_of(' ') == std::string::npos)
687  {
688  return 0;
689  }
690 
691  // Otherwise try standard library
692  try
693  {
694  return std::stoi(_input);
695  }
696  // if that fails, return NAN_I
697  catch(...)
698  {
699  return NAN_I;
700  }
701  }
702 
707  inline double parseFloat(const std::string &_input)
708  {
709  // Return NAN_D if it is empty
710  if (_input.empty())
711  {
712  return NAN_D;
713  }
714  // Return 0 if it is all spaces
715  else if (_input.find_first_not_of(' ') == std::string::npos)
716  {
717  return 0;
718  }
719 
720  // Otherwise try standard library
721  try
722  {
723  return std::stod(_input);
724  }
725  // if that fails, return NAN_D
726  catch(...)
727  {
728  return NAN_D;
729  }
730  }
731 
734  // and on macOS, microsecond precision.
739  const std::chrono::steady_clock::time_point &_time)
740  {
742  _time.time_since_epoch());
744  _time.time_since_epoch());
745  int64_t seconds = now_s.count();
746  int64_t nanoseconds = std::chrono::duration_cast
747  <std::chrono::nanoseconds>(now_ns - now_s).count();
748  return {seconds, nanoseconds};
749  }
750 
753  // and on macOS, microsecond precision.
758  inline std::chrono::steady_clock::time_point secNsecToTimePoint(
759  const uint64_t &_sec, const uint64_t &_nanosec)
760  {
761  auto duration = std::chrono::seconds(_sec) + std::chrono::nanoseconds(
762  _nanosec);
763  std::chrono::steady_clock::time_point result;
765  result += duration_cast<std::chrono::steady_clock::duration>(duration);
766  return result;
767  }
768 
771  // and on macOS, microsecond precision.
776  const std::chrono::steady_clock::duration &_dur)
777  {
780  return {s.count(), ns.count()};
781  }
782 
783  // TODO(anyone): Replace this with std::chrono::days.
786 
794  template<class...Durations, class DurationIn>
795  std::tuple<Durations...> breakDownDurations(DurationIn d) {
796  std::tuple<Durations...> retval;
797  using discard = int[];
798  (void)discard{0, (void((
799  (std::get<Durations>(retval) =
800  std::chrono::duration_cast<Durations>(d)),
801  (d -= std::chrono::duration_cast<DurationIn>(
802  std::get<Durations>(retval))))), 0)...};
803  return retval;
804  }
805 
810  const std::chrono::steady_clock::time_point &_point)
811  {
812  auto duration = _point - secNsecToTimePoint(0, 0);
813  auto cleanDuration = breakDownDurations<days,
818  duration);
819  std::ostringstream output_string;
820  output_string << std::setw(2) << std::setfill('0')
821  << std::get<0>(cleanDuration).count() << " "
822  << std::setw(2) << std::setfill('0')
823  << std::get<1>(cleanDuration).count() << ":"
824  << std::setw(2) << std::setfill('0')
825  << std::get<2>(cleanDuration).count() << ":"
826  << std::setfill('0') << std::setw(6)
828  << std::get<3>(cleanDuration).count() +
829  std::get<4>(cleanDuration).count()/1000.0;
830  return output_string.str();
831  }
832 
833  // Degrade precision on Windows, which cannot handle 'long double'
834  // values properly. See the implementation of Unpair.
835  // 32 bit ARM processors also define 'long double' to be the same
836  // size as 'double', and must also be degraded
837 #if defined _MSC_VER || defined __arm__
838  using PairInput = uint16_t;
839  using PairOutput = uint32_t;
840 #else
841  using PairInput = uint32_t;
842  using PairOutput = uint64_t;
843 #endif
844 
854  PairOutput IGNITION_MATH_VISIBLE Pair(
855  const PairInput _a, const PairInput _b);
856 
868  std::tuple<PairInput, PairInput> IGNITION_MATH_VISIBLE Unpair(
869  const PairOutput _key);
870  }
871  }
872 }
873 
874 #endif
static const size_t IGN_NINE_SIZE_T
size_t type with a value of 9
Definition: Helpers.hh:253
std::tuple< PairInput, PairInput > Unpair(const PairOutput _key)
The reverse of the Pair function. Accepts a key, produced from the Pair function, and returns a tuple...
static const double DPRCT_LOW_D
Definition: Helpers.hh:369
T empty(T... args)
static const size_t IGN_SIX_SIZE_T
size_t type with a value of 6
Definition: Helpers.hh:244
static const int NAN_I
Returns the representation of a quiet not a number (NAN)
Definition: Helpers.hh:364
static const int32_t LOW_I32
32bit unsigned integer lowest value. This is equivalent to IGN_INT32_MIN, and is defined here for com...
Definition: Helpers.hh:332
static const float INF_F
float positive infinite value
Definition: Helpers.hh:280
static const double LOW_D
Double low value, equivalent to -MAX_D.
Definition: Helpers.hh:262
static const int64_t DPRCT_INF_I64
Definition: Helpers.hh:398
T find_first_not_of(T... args)
static const uint64_t MIN_UI64
64bit unsigned integer minimum value
Definition: Helpers.hh:341
static const uint32_t MIN_UI32
32bit unsigned integer minimum value
Definition: Helpers.hh:315
static const uint32_t DPRCT_MAX_UI32
Definition: Helpers.hh:383
static const uint16_t DPRCT_LOW_UI16
Definition: Helpers.hh:377
static const float DPRCT_LOW_F
Definition: Helpers.hh:373
std::chrono::duration< uint64_t, std::ratio< 86400 > > days
This will exist in C++-20.
Definition: Helpers.hh:785
T precision(const T &_a, const unsigned int &_precision)
get value at a specified precision
Definition: Helpers.hh:589
static const size_t IGN_EIGHT_SIZE_T
size_t type with a value of 8
Definition: Helpers.hh:250
static const int32_t DPRCT_MIN_I32
Definition: Helpers.hh:388
T mean(const std::vector< T > &_values)
get mean of vector of values
Definition: Helpers.hh:502
static const int32_t INF_I32
32-bit unsigned integer positive infinite value
Definition: Helpers.hh:335
T swap(T... args)
static const float NAN_F
Returns the representation of a quiet not a number (NAN)
Definition: Helpers.hh:283
static const int16_t MAX_I16
16bit unsigned integer maximum value
Definition: Helpers.hh:299
static const uint16_t MAX_UI16
16bit unsigned integer maximum value
Definition: Helpers.hh:286
bool isnan(float _v)
check if a float is NaN
Definition: Helpers.hh:413
T stod(T... args)
static const uint64_t MAX_UI64
64bit unsigned integer maximum value
Definition: Helpers.hh:338
static const uint64_t LOW_UI64
64bit unsigned integer lowest value. This is equivalent to IGN_UINT64_MIN, and is defined here for co...
Definition: Helpers.hh:345
static const int64_t DPRCT_LOW_I64
Definition: Helpers.hh:397
unsigned int roundUpPowerOfTwo(unsigned int _x)
Get the smallest power of two that is greater or equal to a given value.
Definition: Helpers.hh:634
static const uint32_t MAX_UI32
32bit unsigned integer maximum value
Definition: Helpers.hh:312
T max(const std::vector< T > &_values)
get the maximum value of vector of values
Definition: Helpers.hh:528
T duration_cast(T... args)
static const int16_t DPRCT_MAX_I16
Definition: Helpers.hh:379
static const int64_t MAX_I64
64bit unsigned integer maximum value
Definition: Helpers.hh:351
bool equal(const T &_a, const T &_b, const T &_epsilon=T(1e-6))
check if two values are equal, within a tolerance
Definition: Helpers.hh:555
static const double MIN_D
Double min value. This value will be similar to 2.22507e-308.
Definition: Helpers.hh:259
static const size_t IGN_ONE_SIZE_T
size_t type with a value of 1
Definition: Helpers.hh:229
static const int16_t DPRCT_MIN_I16
Definition: Helpers.hh:380
T setw(T... args)
bool isOdd(const int _v)
Check if parameter is odd.
Definition: Helpers.hh:461
static const float DPRCT_INF_F
Definition: Helpers.hh:374
bool greaterOrNearEqual(const T &_a, const T &_b, const T &_epsilon=1e-6)
inequality test, within a tolerance
Definition: Helpers.hh:578
STL class.
T variance(const std::vector< T > &_values)
get variance of vector of values
Definition: Helpers.hh:514
T min(T... args)
static const int64_t DPRCT_MAX_I64
Definition: Helpers.hh:395
static const size_t IGN_FOUR_SIZE_T
size_t type with a value of 4
Definition: Helpers.hh:238
std::pair< int64_t, int64_t > durationToSecNsec(const std::chrono::steady_clock::duration &_dur)
Convert a std::chrono::steady_clock::duration to a seconds and nanoseconds pair.
Definition: Helpers.hh:775
std::tuple< Durations... > breakDownDurations(DurationIn d)
break down durations NOTE: the template arguments must be properly ordered according to magnitude and...
Definition: Helpers.hh:795
static const uint32_t INF_UI32
32-bit unsigned integer positive infinite value
Definition: Helpers.hh:322
static const size_t IGN_FIVE_SIZE_T
size_t type with a value of 5
Definition: Helpers.hh:241
static const uint64_t INF_UI64
64-bit unsigned integer positive infinite value
Definition: Helpers.hh:348
T lowest(T... args)
static const float LOW_F
Float low value, equivalent to -MAX_F.
Definition: Helpers.hh:277
static const float DPRCT_MIN_F
Definition: Helpers.hh:372
uint64_t PairOutput
Definition: Helpers.hh:842
static const double DPRCT_INF_D
Definition: Helpers.hh:370
static const int16_t DPRCT_LOW_I16
Definition: Helpers.hh:381
#define IGN_FP_VOLATILE
Define IGN_FP_VOLATILE for FP equality comparisons Use volatile parameters when checking floating poi...
Definition: Helpers.hh:195
std::pair< int64_t, int64_t > timePointToSecNsec(const std::chrono::steady_clock::time_point &_time)
Convert a std::chrono::steady_clock::time_point to a seconds and nanoseconds pair.
Definition: Helpers.hh:738
static const uint16_t DPRCT_MAX_UI16
Definition: Helpers.hh:375
T setfill(T... args)
static const uint16_t DPRCT_MIN_UI16
Definition: Helpers.hh:376
bool isPowerOfTwo(unsigned int _x)
Is this a power of 2?
Definition: Helpers.hh:624
static const uint16_t INF_UI16
16-bit unsigned integer positive infinite value
Definition: Helpers.hh:296
uint32_t PairInput
Definition: Helpers.hh:841
std::chrono::steady_clock::time_point secNsecToTimePoint(const uint64_t &_sec, const uint64_t &_nanosec)
Convert seconds and nanoseconds to std::chrono::steady_clock::time_point.
Definition: Helpers.hh:758
static const size_t IGN_ZERO_SIZE_T
size_t type with a value of 0
Definition: Helpers.hh:226
static const uint16_t MIN_UI16
16bit unsigned integer minimum value
Definition: Helpers.hh:289
static const uint16_t LOW_UI16
16bit unsigned integer lowest value. This is equivalent to IGN_UINT16_MIN, and is defined here for co...
Definition: Helpers.hh:293
static const uint32_t DPRCT_INF_UI32
Definition: Helpers.hh:386
static const int16_t MIN_I16
16bit unsigned integer minimum value
Definition: Helpers.hh:302
T infinity(T... args)
static const int32_t MIN_I32
32bit unsigned integer minimum value
Definition: Helpers.hh:328
T max(T... args)
static const uint32_t DPRCT_LOW_UI32
Definition: Helpers.hh:385
static const int64_t MIN_I64
64bit unsigned integer minimum value
Definition: Helpers.hh:354
T count(T... args)
static const int32_t DPRCT_INF_I32
Definition: Helpers.hh:390
T fixed(T... args)
PairOutput Pair(const PairInput _a, const PairInput _b)
A pairing function that maps two values to a unique third value. This is an implement of Szudzik&#39;s fu...
static const float MAX_F
Float maximum value. This value will be similar to 3.40282e+38.
Definition: Helpers.hh:271
static const uint64_t DPRCT_MIN_UI64
Definition: Helpers.hh:392
int sgn(T _value)
The signum function.
Definition: Helpers.hh:481
T size(T... args)
static const double DPRCT_MIN_D
Definition: Helpers.hh:368
int signum(T _value)
The signum function.
Definition: Helpers.hh:493
static const uint32_t DPRCT_MIN_UI32
Definition: Helpers.hh:384
STL class.
static const int16_t DPRCT_INF_I16
Definition: Helpers.hh:382
bool isEven(const int _v)
Check if parameter is even.
Definition: Helpers.hh:445
T pow(T... args)
static const double NAN_D
Returns the representation of a quiet not a number (NAN)
Definition: Helpers.hh:268
static const float DPRCT_MAX_F
Definition: Helpers.hh:371
static const int16_t LOW_I16
16bit unsigned integer lowest value. This is equivalent to IGN_INT16_MIN, and is defined here for com...
Definition: Helpers.hh:306
static const int64_t LOW_I64
64bit unsigned integer lowest value. This is equivalent to IGN_INT64_MIN, and is defined here for com...
Definition: Helpers.hh:358
static const double MAX_D
Double maximum value. This value will be similar to 1.79769e+308.
Definition: Helpers.hh:256
static const size_t IGN_TWO_SIZE_T
size_t type with a value of 2
Definition: Helpers.hh:232
static const int64_t INF_I64
64-bit unsigned integer positive infinite value
Definition: Helpers.hh:361
static const float MIN_F
Float minimum value. This value will be similar to 1.17549e-38.
Definition: Helpers.hh:274
T isnan(T... args)
double parseFloat(const std::string &_input)
parse string into float
Definition: Helpers.hh:707
constexpr T IGN_MASSMATRIX3_DEFAULT_TOLERANCE
The default tolerance value used by MassMatrix3::IsValid(), MassMatrix3::IsPositive(), and MassMatrix3::ValidMoments()
Definition: Helpers.hh:39
static const int16_t INF_I16
16-bit unsigned integer positive infinite value
Definition: Helpers.hh:309
T quiet_NaN(T... args)
static const double INF_D
Double positive infinite value.
Definition: Helpers.hh:265
void sort2(T &_a, T &_b)
Sort two numbers, such that _a <= _b.
Definition: Helpers.hh:599
static const uint32_t LOW_UI32
32bit unsigned integer lowest value. This is equivalent to IGN_UINT32_MIN, and is defined here for co...
Definition: Helpers.hh:319
static const size_t IGN_THREE_SIZE_T
size_t type with a value of 3
Definition: Helpers.hh:235
static const size_t IGN_SEVEN_SIZE_T
size_t type with a value of 7
Definition: Helpers.hh:247
static const uint64_t DPRCT_MAX_UI64
Definition: Helpers.hh:391
T isinf(T... args)
Definition: Angle.hh:42
T setprecision(T... args)
static const int64_t DPRCT_MIN_I64
Definition: Helpers.hh:396
float fixnan(float _v)
Fix a nan value.
Definition: Helpers.hh:429
std::string timePointToString(const std::chrono::steady_clock::time_point &_point)
Convert a std::chrono::steady_clock::time_point to a string.
Definition: Helpers.hh:809
static const double DPRCT_MAX_D
Definition: Helpers.hh:367
static const uint16_t DPRCT_INF_UI16
Definition: Helpers.hh:378
T stoi(T... args)
static const int32_t DPRCT_LOW_I32
Definition: Helpers.hh:389
static const uint64_t DPRCT_LOW_UI64
Definition: Helpers.hh:393
static const int32_t DPRCT_MAX_I32
Definition: Helpers.hh:387
T round(T... args)
int parseInt(const std::string &_input)
parse string into an integer
Definition: Helpers.hh:678
bool lessOrNearEqual(const T &_a, const T &_b, const T &_epsilon=1e-6)
inequality test, within a tolerance
Definition: Helpers.hh:567
T min(const std::vector< T > &_values)
get the minimum value of vector of values
Definition: Helpers.hh:541
T clamp(T _v, T _min, T _max)
Simple clamping function.
Definition: Helpers.hh:405
int roundUpMultiple(int _num, int _multiple)
Round a number up to the nearest multiple. For example, if the input number is 12 and the multiple is...
Definition: Helpers.hh:660
void sort3(T &_a, T &_b, T &_c)
Sort three numbers, such that _a <= _b <= _c.
Definition: Helpers.hh:611
static const uint64_t DPRCT_INF_UI64
Definition: Helpers.hh:394
static const int32_t MAX_I32
32bit unsigned integer maximum value
Definition: Helpers.hh:325