add the helper for the UTC time and mach checks

This commit is contained in:
Sven Czarnian
2021-11-22 16:17:07 +01:00
parent 09e29afe7b
commit 9f80ce1631
2 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
/*
* @brief Defines and implements functions to get mathematical helper functions
* @file helper/Math.h
* @author Sven Czarnian <devel@svcz.de>
* @copyright Copyright 2020-2021 Sven Czarnian
* @license This project is published under the GNU General Public License v3 (GPLv3)
*/
#pragma once
#define _USE_MATH_DEFINES
#include <math.h>
namespace aman {
/**
* @brief Contains helper functions to get numerical stability in the functions
* @ingroup helper
*/
class Math {
public:
Math(const Math& other) = delete;
Math(Math&& other) = delete;
Math& operator=(const Math& other) = delete;
Math& operator=(Math&& other) = delete;
/**
* @brief Compares two floating point numbers if they are almost equal
* @param[in] value0 The first floating point number
* @param[in] value1 The second floating point number
* @param[in] threshold The threshold which defines both numbers as almost equal
* @return True if the difference between value0 and value1 is smaller than the threshold, else false
*/
static __inline bool almostEqual(float value0, float value1, float threshold = 1e-4) noexcept {
return std::abs(value0 - value1) <= threshold;
}
/**
* @brief Converts a degree value into a radian value
* @param[in] degree The degree value
* @return The radian value
*/
static constexpr __inline float deg2rad(float degree) noexcept {
return degree * static_cast<float>(M_PI) / 180.0f;
}
/**
* @brief Converts a radian value into a degree value
* @param[in] radian The degree value
* @return The degree value
*/
static constexpr __inline float rad2deg(float radian) noexcept {
return radian * 180.0f / static_cast<float>(M_PI);
}
};
}