Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot (vkp)

...

Code Block
float f(float x) {
   return x * 0.1f;
}

float g(float x) {
   return x * 0.1;
}

Function f is allowed to return a value wider than float, but function g (which uses the wider constant) is not.

...

Code Block
bgColor#FFcccc
float calcPercentage(float value) {
   return value * 0.1f;
}

void floatRoutine(void) {
  float value = 99.0f;
  long double percentage;

  percentage = calcPercentage(value);
}

...

Code Block
bgColor#ccccff
float calcPercentage(float value) {
   return (float)(value * 0.1f);
}

void floatRoutine(void) {
  float value = 99.0f;
  long double percentage;

  percentage = calcPercentage(value);
}

...

Code Block
bgColor#ccccff
float calcPercentage(float value) {
  volatile float result;

  result = value * 0.1f;

   return result;
}

void floatRoutine(void) {
  float value = 99.0f;
  long double percentage;

  percentage = calcPercentage(value);
}

...

Wiki Markup
\[[ISO/IEC 9899:1999|AA. References#ISO/IEC 9899-1999]\]
\[[WG14/N1396|AA. References#WG14/N1396]\]

...

FLP36-C. Beware of precision loss when converting integral types to floating point      05. Floating Point (FLP)      06. Arrays (ARR)