Please explain why the following pieces of code behave differently.
#include
int main(){
float a=0.1;
if(a<0.1)
printf(\"less\");
else
You cannot use comparison operators on floating point numbers reliably.
A good way of comparing two floating point numbers is to have a accuracy threshold which is relative to the magnitude of the two floating point numbers being compared.
Something like:
#include < math.h >
if(fabs(a - b) <= accurary_threshold * fabs(a))
Good Read: