arsenalgear-cpp
A library containing general purpose C++ utils.
math.hpp
Go to the documentation of this file.
1 //====================================================
2 // File data
3 //====================================================
11 //====================================================
12 // Preprocessor settings
13 //====================================================
14 #pragma once
15 #ifndef ARSENALGEAR_MATH_HPP
16 #define ARSENALGEAR_MATH_HPP
17 
18 //====================================================
19 // Headers
20 //====================================================
21 
22 // STD headers
23 #include <cmath>
24 
25 namespace agr
26  {
27  //====================================================
28  // Functions
29  //====================================================
30 
31  // roundoff
40  template <typename T>
41  inline T roundoff( T value, unsigned char prec )
42  {
43  T pow_10 = pow( 10.0f, static_cast<T> ( prec ) );
44 
45  return round( value * pow_10 ) / pow_10;
46  }
47 
48  // IsInBounds
58  template <typename T>
59  inline bool IsInBounds( T value, T low, T high )
60  {
61  return !( value < low ) && ( value < high );
62  }
63  }
64 
65 #endif
Definition: stream.cpp:22
T roundoff(T value, unsigned char prec)
Function to round a floating point to n-th decimal place after comma.
Definition: math.hpp:41
bool IsInBounds(T value, T low, T high)
Function to check if a number lies in a certain bound or not.
Definition: math.hpp:59