Hi there,
I observe an unexpected result when using trunc(). I wonder if anybody could help me using Redlib with floats and libm.
Compiling, linking using Redlib and debugging
#include <math.h>
int main(void) {
float adc_read = 123.123;
int adc_int = trunc(adc_read);
//...enter infinite loop or other code
}
will give me the a value of 0 for adc_int (see attached screenshot).
If I link using Newlib instead, trunc() returns the correct result of 123.
As a workaround, I'm now using a cast to int instead:
int adc_int = (int)adc_read;
But still I'm puzzled why Redlib's trunc() returns 0? What am I missing here? According to LPCXsupport, "Redlib is just a C library" and therefore I assume it should implement at least functionality according to C90 standard.
Thanks a lot!
Daniel
So trunc() is a C99 function and one that Redlib unfortunately doesn't currently implement. So I'm intrigued as to how you even got your project to build against Redlib - unless something else in your setup is providing it.
You should also note that where available, trunc() returns a double, not an int:
http://www.cplusplus.com/reference/cmath/trunc/?kw=trunc
Regards,
MCUXpresso IDE Support