Reputation: 272
I'm doing some matrix operations where the matrix elements obtains values from certain variables in the following way:
elem[1] = -x
but when x = 0
it sets -0
in the matrix which is undesirable. Any definitive way to prevent this?
Upvotes: 2
Views: 596
Reputation: 4827
You can do the following:
elem[i] = -x + 0.0;
I've tested the following code:
float a = -0.0;
printf("%f %f\n", a, a + 0.0);
Which produces the following output:
-0.000000 0.000000
Upvotes: 5