floating point - about float datatype in C -


this question has answer here:

i studying logic building c, write small code equation. here code:

#include<stdio.h>  int main() {     float a,b;      printf("find solutions equation: ax + b = 0\n");     printf("input value a: ");     scanf("%f", &a);     printf("input value b: ");     scanf("%f", &b);      if(a == 0)     {         if (b ==0)         {             printf("countless solution.");         }         else         {             printf("have no solution.");         }     }      else     {         printf("have 1 solution: x = %.2f", -b/a);     }  } 

the problem when input a=any number, b=0, have solution is: x= -0.00.

i don't understand why x = -0.00 instead of x = 0.00? have tested cases a==0 && b==0, a==0 && b!=0 , works fine. confusing this. can explain me?

the ieee standard representation of floating point numbers allows negative 0. basically, there 1 bit represents "sign" of floating point number. when flip bit, sign flipped. in example, when use value -b, value used b sign bit flipped. 0 sign bit flipped -0.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -