AnsweredAssumed Answered

Redlib trunc() unexpectedly returns 0

Question asked by danielholala on May 2, 2018
Latest reply on May 3, 2018 by LPCX presso support

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).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!