Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C: What does it mean for a double to be == -0?

Tags:

c

double

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
like image 443
hhafez Avatar asked Mar 06 '09 00:03

hhafez


People also ask

Is 0.0 a double?

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 .

What does != 0 mean in C?

“ %==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”);

What is the meaning of != 0?

...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 ).

How double is represented in C?

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.


1 Answers

Negative zero is a useful concept for numerical computing and is a valid floating point number in C.

like image 89
Randolpho Avatar answered Nov 04 '22 18:11

Randolpho