`#define FLOAT_CONV 1000 // 10^<number of places you want to display>`

int64_t temperature = (int64_t)(double_temp * FLOAT_CONV);

uint64_t humidity = (uint64_t)(double_hum * FLOAT_CONV);

uint64_t pressure = (uint64_t)(double_press * FLOAT_CONV);

os_sprintf(buf, "\"T\":%d.%03u,\"rho\":%u.%03u,\"P\":%u.%03u",

temperature / FLOAT_CONV , abs(temperature % FLOAT_CONV ), //C

humidity / FLOAT_CONV , humidity % FLOAT_CONV , //rH

pressure / FLOAT_CONV , pressure % FLOAT_CONV ); //Pa

For more complex math, I have developed fixed point routines, so I have routines for sqrt and log10, exp etc. In my work I use all these for audio that I bring in through the I2S bus so they are natively 24 bits stored in a 32 bit long and end up squared for most of the calculations, so I treat them as Q1.48

davydnorris wrote:It depends on what math you need to do, but for really basic math (+, -, *, /) I use the floating point routines as they aren't that big. The floating point string formatting routines are bulky so for those I use fixed point and do things like:Code: Select all`#define FLOAT_CONV 1000 // 10^<number of places you want to display>`

int64_t temperature = (int64_t)(double_temp * FLOAT_CONV);

uint64_t humidity = (uint64_t)(double_hum * FLOAT_CONV);

uint64_t pressure = (uint64_t)(double_press * FLOAT_CONV);

os_sprintf(buf, "\"T\":%d.%03u,\"rho\":%u.%03u,\"P\":%u.%03u",

temperature / FLOAT_CONV , abs(temperature % FLOAT_CONV ), //C

humidity / FLOAT_CONV , humidity % FLOAT_CONV , //rH

pressure / FLOAT_CONV , pressure % FLOAT_CONV ); //Pa

For more complex math, I have developed fixed point routines, so I have routines for sqrt and log10, exp etc. In my work I use all these for audio that I bring in through the I2S bus so they are natively 24 bits stored in a 32 bit long and end up squared for most of the calculations, so I treat them as Q1.48

Wow man, thanks! And yes, im into more complex math, so if you can share with me your rutines, i would appreciate!

Or resolve to using fixed point, which isn't too bad either.