Chat freely about anything...

User avatar
By RBMK
#92290 Well, im forking https://github.com/cnlohr/nosdk8266 project but since the main idea of that project is to be as small as possible, im searching for at last be able to use floats. I already remove -nostdlib from makefile and update the used XTensa GCC to the last version. What option i should add to my Makefile (https://github.com/0z4/nosdk8266/blob/master/Makefile) to be able to print them on the UART port and do math?
User avatar
By davydnorris
#92292 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
User avatar
By RBMK
#92304
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!
User avatar
By eriksl
#92375 For floating point arithmetic you don't need the SDK at all, anyway. What you need is a libc with fp support (or not, if you don't want to print them...) and a gcc+gcc libs with fp support.

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