0

I have a strange and unexpected problem with a comparison of two variables in my C code. The code is wrote using Keil for STM32F407 micro-controller. Please consider the following:

if ( f1 > u1 )
 {
  // do some ...
 }

f1 is a float variable and u1 is an unsigned integer. In debug mode, f1=0.1 and u1=1600, but the if condition results true.

Can anybody solve the problem?

Rasool
  • 3
  • 3
  • Possible duplicate of [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – gstukelj Oct 14 '19 at 07:33
  • 1
    `u1` should be implictly promoted to `float`. In normal circumstances condition should evaluate false. Something is missing here. Please create [mcve]. – user694733 Oct 14 '19 at 07:39
  • that `if` condition does ***not*** result in true. Is there something you are omitting to show us? Please post a self-contained, compilable, verifiable sample. – Mike Nakis Oct 14 '19 at 07:40
  • 1
    @gst That is not duplicate. Assuming typical IEEE 754 implementation, precision issues are not the reason for problems here. – user694733 Oct 14 '19 at 07:48

0 Answers0