Home › Forum › Community › Jumps in measured data › Reply To: Jumps in measured data
January 15, 2018 at 10:11 am
#5485
Keymaster
Yes, that would work too. Something similar was added in firmware v130 as a fix:
// an uint16_t stores 16 bits, we use first bit for sign, and following 15 bits for number (0..32767)
// result is divided by 100 for a real with 2 decimals, max is 327.00
uint16_t di(double val) {
uint16_t res = 0;
uint16_t mask = 1<<15;
if (val > 327 || val < -327) return res;
if (val < 0) {
val *= -1000;
res = val / 10; // fix double approximation issue
res |= mask;
} else {
val *= 1000;
res = val / 10; // fix double approximation issue
}
return res;
}
and
// an uint16_t stores 16 bits, we use first bit for sign, and following 15 bits for number (0..32767)
// result is divided by 100 for a real with 2 decimals, max is 327.00
double id(uint16_t val) {
double res = 0;
uint16_t mask = 1<<15;
// check negative number
if (val & mask) {
val &= ~mask; // remove sign bit
res = val;
res = -res;
} else {
res = val;
}
res /= 100.0; // restore the 2 decimals
return res;
}
It’s pretty much the same thing.