# neglect / neglect / cpplib / include / neglect / math.hpp

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63``` ```#ifndef _INC_NEGLECT_MATH_HPP_ #define _INC_NEGLECT_MATH_HPP_ #include namespace neglect { /* check if two numeric values are almost equal */ inline bool almost_equal(int a, int b) { return a == b; } inline bool almost_equal(size_t a, size_t b) { return a == b; } inline bool almost_equal(float a, float b) { return (a - 1e-08 < b && a + 1e-08 > b); } inline bool almost_equal(double a, double b) { return (a - 1e-10 < b && a + 1e-10 > b); } // currently these are just aliases to the C/C++ math functions // but this gives the possibility to replace them later with more // optimized functions namespace math { static const double e = 2.7182818284590452354; static const double pi = 3.14159265358979323846; static const double sqrt2 = 1.41421356237309504880; template T sqrt(T x) { return ::std::sqrt(x); } template T cos(T x) { return ::std::cos(x); } template T cosh(T x) { return ::std::cosh(x); } template T sin(T x) { return ::std::sin(x); } template T sinh(T x) { return ::std::sinh(x); } template T tan(T x) { return ::std::tan(x); } template T tanh(T x) { return ::std::tanh(x); } template T exp(T x) { return ::std::exp(x); } template T log(T x) { return ::std::log(x); } template T log10(T x) { return ::std::log10(x); } template T pow(T x, T y) { return ::std::pow(x, y); } template T deg_to_rad(T degrees) { return degrees * pi / 180.0; } template T rad_to_deg(T radians) { return radians * 180.0 / pi; } } } #endif ```