diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-07-05 11:43:16 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-07-05 11:43:16 +0200 |
commit | 2cfe9ee1b49681ad0ba0e6f4e8a54dba3e7f2638 (patch) | |
tree | bc7e53decc97041ac14344c00ebfb7e7a4216713 /src/modules/mathlib/math | |
parent | 05d68154014910a428f1f77eae98a393d14b7f37 (diff) | |
download | px4-firmware-2cfe9ee1b49681ad0ba0e6f4e8a54dba3e7f2638.tar.gz px4-firmware-2cfe9ee1b49681ad0ba0e6f4e8a54dba3e7f2638.tar.bz2 px4-firmware-2cfe9ee1b49681ad0ba0e6f4e8a54dba3e7f2638.zip |
Improved limits handling
Diffstat (limited to 'src/modules/mathlib/math')
-rw-r--r-- | src/modules/mathlib/math/Limits.cpp | 16 | ||||
-rw-r--r-- | src/modules/mathlib/math/Limits.hpp | 7 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/modules/mathlib/math/Limits.cpp b/src/modules/mathlib/math/Limits.cpp index 810a4484d..d4c892d8a 100644 --- a/src/modules/mathlib/math/Limits.cpp +++ b/src/modules/mathlib/math/Limits.cpp @@ -39,6 +39,7 @@ #include <math.h> +#include <stdint.h> #include "Limits.hpp" @@ -61,6 +62,11 @@ unsigned __EXPORT min(unsigned val1, unsigned val2) return (val1 < val2) ? val1 : val2; } +uint64_t __EXPORT min(uint64_t val1, uint64_t val2) +{ + return (val1 < val2) ? val1 : val2; +} + double __EXPORT min(double val1, double val2) { return (val1 < val2) ? val1 : val2; @@ -81,6 +87,11 @@ unsigned __EXPORT max(unsigned val1, unsigned val2) return (val1 > val2) ? val1 : val2; } +uint64_t __EXPORT max(uint64_t val1, uint64_t val2) +{ + return (val1 > val2) ? val1 : val2; +} + double __EXPORT max(double val1, double val2) { return (val1 > val2) ? val1 : val2; @@ -102,6 +113,11 @@ unsigned __EXPORT constrain(unsigned val, unsigned min, unsigned max) return (val < min) ? min : ((val > max) ? max : val); } +uint64_t __EXPORT constrain(uint64_t val, uint64_t min, uint64_t max) +{ + return (val < min) ? min : ((val > max) ? max : val); +} + double __EXPORT constrain(double val, double min, double max) { return (val < min) ? min : ((val > max) ? max : val); diff --git a/src/modules/mathlib/math/Limits.hpp b/src/modules/mathlib/math/Limits.hpp index e1f2e7078..fb778dd66 100644 --- a/src/modules/mathlib/math/Limits.hpp +++ b/src/modules/mathlib/math/Limits.hpp @@ -40,6 +40,7 @@ #pragma once #include <nuttx/config.h> +#include <stdint.h> namespace math { @@ -50,6 +51,8 @@ int __EXPORT min(int val1, int val2); unsigned __EXPORT min(unsigned val1, unsigned val2); +uint64_t __EXPORT min(uint64_t val1, uint64_t val2); + double __EXPORT min(double val1, double val2); float __EXPORT max(float val1, float val2); @@ -58,6 +61,8 @@ int __EXPORT max(int val1, int val2); unsigned __EXPORT max(unsigned val1, unsigned val2); +uint64_t __EXPORT max(uint64_t val1, uint64_t val2); + double __EXPORT max(double val1, double val2); @@ -67,6 +72,8 @@ int __EXPORT constrain(int val, int min, int max); unsigned __EXPORT constrain(unsigned val, unsigned min, unsigned max); +uint64_t __EXPORT constrain(uint64_t val, uint64_t min, uint64_t max); + double __EXPORT constrain(double val, double min, double max); float __EXPORT radians(float degrees); |