Merge pull request #8527 from device111/development

update veml7700 libary
This commit is contained in:
Theo Arends 2020-05-24 16:43:43 +02:00 committed by GitHub
commit 9e0637cc60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 25 deletions

View File

@ -76,30 +76,6 @@ boolean Adafruit_VEML7700::begin(TwoWire *theWire) {
return true;
}
float Adafruit_VEML7700::alternate_pow(float a, float b)
{
// https://martin.ankerl.com/2012/01/25/optimized-approximative-pow-in-c-and-cpp/
// calculate approximation with fraction of the exponent
int e = abs((int)b);
union {
double d;
int x[2];
} u = { a };
u.x[1] = (int)((b - e) * (u.x[1] - 1072632447) + 1072632447);
u.x[0] = 0;
// exponentiation by squaring with the exponent's integer part
// double r = u.d makes everything much slower, not sure why
double r = 1.0;
while (e) {
if (e & 1) {
r *= a;
}
a *= a;
e >>= 1;
}
return r * u.d;
}
float Adafruit_VEML7700::normalize_resolution(float value) {
// adjust for gain (1x is normalized)
switch (getGain()) {

View File

@ -62,6 +62,7 @@
#define VEML7700_POWERSAVE_MODE3 0x02 ///< Power saving mode 3
#define VEML7700_POWERSAVE_MODE4 0x03 ///< Power saving mode 4
extern float FastPrecisePowf(const float x, const float y);
/*!
* @brief Class that stores state and functions for interacting with
@ -110,7 +111,7 @@ private:
*PowerSave_Enable, *PowerSave_Mode;
float normalize_resolution(float value);
float alternate_pow(float a, float b);
static inline float alternate_pow(float a, float b) { return FastPrecisePowf(a, b); }
Adafruit_I2CDevice *i2c_dev;