From dc2adaa4d196b79c1b75393f4a2e6c302b5a1241 Mon Sep 17 00:00:00 2001 From: RobTillaart Date: Thu, 27 Jul 2017 15:26:36 +0200 Subject: [PATCH] Fix double to float (issue 33) --- libraries/FastMap/FastMap.cpp | 18 +++++++++--------- libraries/FastMap/FastMap.h | 27 +++++++++++++-------------- libraries/FastMap/library.properties | 2 +- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/libraries/FastMap/FastMap.cpp b/libraries/FastMap/FastMap.cpp index 0c4529f7..16396be8 100644 --- a/libraries/FastMap/FastMap.cpp +++ b/libraries/FastMap/FastMap.cpp @@ -1,13 +1,14 @@ // // FILE: FastMap.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.7 +// VERSION: 0.1.8 // PURPOSE: class with fast map function - library for Arduino // URL: http://forum.arduino.cc/index.php?topic=276194 // // HISTORY: +// 0.1.8 2017-07-27 revert double to float (issue 33) // 0.1.7 2017-04-28 cleaned up, get examples working again -// 0.1.06 2015-03-08 replaced float by double (support ARM) +// 0.1.06 2015-03-08 replaced float by float (support ARM) // 0.1.05 2014-11-02 stripped of bit mask experimental code // 0.1.04 add back() - the inverse map // tested with bit mask for constrain code (Perfomance was killed) @@ -28,7 +29,7 @@ FastMap::FastMap() init(0, 1, 0, 1); } -void FastMap::init(double in_min, double in_max, double out_min, double out_max) +void FastMap::init(float in_min, float in_max, float out_min, float out_max) { _in_min = in_min; _in_max = in_max; @@ -42,24 +43,23 @@ void FastMap::init(double in_min, double in_max, double out_min, double out_max) _backbase = in_min - out_min * _backfactor; } -double FastMap::constrainedMap(double value) +float FastMap::constrainedMap(float value) { if (value <= _in_min) return _out_min; if (value >= _in_max) return _out_max; return this->map(value); } -double FastMap::lowerConstrainedMap(double value) +float FastMap::lowerConstrainedMap(float value) { if (value <= _in_min) return _out_min; return this->map(value); } -double FastMap::upperConstrainedMap(double value) +float FastMap::upperConstrainedMap(float value) { if (value >= _in_max) return _out_max; return this->map(value); } -// -// END OF FILE -// \ No newline at end of file + +// END OF FILE \ No newline at end of file diff --git a/libraries/FastMap/FastMap.h b/libraries/FastMap/FastMap.h index 75a6f17f..021efa3a 100644 --- a/libraries/FastMap/FastMap.h +++ b/libraries/FastMap/FastMap.h @@ -1,7 +1,7 @@ // // FILE: FastMap.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.7 +// VERSION: 0.1.8 // PURPOSE: class with fast map function - library for Arduino // URL: http://forum.arduino.cc/index.php?topic=276194 // @@ -18,29 +18,28 @@ #include #endif -#define FASTMAP_LIB_VERSION (F("0.1.7")) +#define FASTMAP_LIB_VERSION (F("0.1.8")) class FastMap { public: FastMap(); - void init(const double in_min, const double in_max, const double out_min, const double out_max); + void init(const float in_min, const float in_max, const float out_min, const float out_max); - double inline map (const double value) { return _base + value * _factor; } - double inline back (const double value) { return _backbase + value * _backfactor; } + float inline map (const float value) { return _base + value * _factor; } + float inline back (const float value) { return _backbase + value * _backfactor; } - double constrainedMap(const double value); - double lowerConstrainedMap(const double value); - double upperConstrainedMap(const double value); + float constrainedMap(const float value); + float lowerConstrainedMap(const float value); + float upperConstrainedMap(const float value); private: - double _in_min, _in_max, _out_min, _out_max; - double _factor, _base; - double _backfactor, _backbase; + float _in_min, _in_max, _out_min, _out_max; + float _factor, _base; + float _backfactor, _backbase; }; #endif -// -// END OF FILE -// \ No newline at end of file + +// END OF FILE \ No newline at end of file diff --git a/libraries/FastMap/library.properties b/libraries/FastMap/library.properties index b4daa696..e4b15af6 100644 --- a/libraries/FastMap/library.properties +++ b/libraries/FastMap/library.properties @@ -1,5 +1,5 @@ name=FastMap -version=0.1.7 +version=0.1.8 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library with fast map function for Arduino.