mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
Fix double to float (issue 33)
This commit is contained in:
parent
2d0a424a1e
commit
dc2adaa4d1
@ -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
|
||||
//
|
@ -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 <Arduino.h>
|
||||
#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
|
||||
//
|
@ -1,5 +1,5 @@
|
||||
name=FastMap
|
||||
version=0.1.7
|
||||
version=0.1.8
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library with fast map function for Arduino.
|
||||
|
Loading…
Reference in New Issue
Block a user