I was just using gdb to print out a value of a double and to my surprise it printed -0
What is a double of -0 value mean in C?
By the way when I checked it's equality with 0 it returned true: To do the comparison I just did the following
in gdb
> print some_double
-0
> print some_double == 0
1
A literal 0 is considered to be an int literal; literal 0.0 is a double literal. When assigning to a double , either will work (since the int can be cast in a widening conversion); however, casting 0.0 to an int is a narrowing conversion, and must be done explicitly; i.e. (int)0.0 .
“ %==0 ” generally used in conditional statement where the remainder is required as the result from a condition. For example: int a=10, b=5; if(a%b==0) printf(“Hi”);
...it means to keep looping while the char that e points to is != 0 . C strings are terminated with a 0 char , '\0' (but usually written as simply 0 ).
A double in c can be printed by both using %f and %lf. Both the %f format specifier and the %lf format specifier represent float and double. The printf() in c treats both float and double the same.
Negative zero is a useful concept for numerical computing and is a valid floating point number in C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With