cout for a double gives -0

I’m using xCode 7.3 on an iMac. This code;

double x, y;

x = -1;
y = 0;
y = x*y;

cout << "y = " << y << endl;

gives the output:

y = -0

It’s correct since -0 = 0, but I think it’s a cosmetic bug. When one does Gauss Elimination on a matrix of doubles, the output matrix has a number of these funny zeroes.

A work-around is to use:

y = y + 0;

y = -y also works, but you don’t know when to use it, since I can’t find a way of detecting it short of using cout.

Do other platforms have this problem?

Topic archived. No new replies allowed.