GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

how float 0.5 and double 0.5 are equal ?

I Have some doubts in floating system

int main() {

float a = 0.5 ;

if ( a == 0.5  )

    printf("Equal") ;

else

   printf("Not Equal") ;

return 0 ;

}

1. How float 0.5 and double 0.5 are equal please explain step by step because i'm new to programming

2. C standard says,  compare two different data types it implicitly converted to lower to higher then, According to this rules, when i can compare float 0.3 and double 0.3 the float automatically converted to double and give the result as equal but it gives false

3. floating  follows IEEE764 standard then

          i) The binary value of float 0.5 is 00111111 00000000 00000000 00000000

    ii) The binary value of double 0.5 is 00111111 11100000 00000000 00000000 00000000 00000000 00000000 00000000

     How float 0.5 and double 0.5 are equal ?

     why float 0.3 and double 0.3 are not equal ?

 

asked Mar 4, 2017 by Muniyasamy V
...