Hello,
My function calculates scalar value from dB value using formular scalar = 10 ^ (dB / 20)
In case of ARMCLANG V6.12 and Optimizer Level -O2 the calculation fails as it is shown in my test code.
Maybe, I overlook something, do I?
#include "stm32f4xx.h" #include <stdio.h> #include <stdint.h> #include <math.h> static volatile int8_t dB; static int8_t lastGain; /**/ void setGain(int8_t gain) { float vol; if (lastGain == gain) { // value is already set return; } // calculate scalar value vol = powf(10.f, (float)gain / 20.f); // = 0.199526... // check limits if (vol > 10) { // "vol out of range" is printed in case of ARMCLANG V6.12 and Optimization > -O2 printf("vol out of range\n"); } else { // "passed" is printed in case of ARMCLANG V6.12 and Optimization -O0 or -O1 printf("passed\n"); lastGain = gain; } } /**/ int main(void) { dB = -14; for(;;) { setGain(dB); } }
View all questions in Keil forum