Skip to content

Commit

Permalink
update veml7700 libary
Browse files Browse the repository at this point in the history
  • Loading branch information
device111 committed May 24, 2020
1 parent ebbbd37 commit e1e604e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
24 changes: 0 additions & 24 deletions lib/Adafruit_VEML7700/Adafruit_VEML7700.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Adafruit_VEML7700/Adafruit_VEML7700.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -110,7 +111,7 @@ class Adafruit_VEML7700 {
*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;

Expand Down

0 comments on commit e1e604e

Please sign in to comment.