I've got the following operator overload for my Vector Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// vec3.cpp
Vec3 Vec3::operator+(const Vec3 &v) const {
return Vec3(x + v.x, y + v.y, z + v.z);
}
// Main
Vec3 a(0,0,0);
Vec3 b(0,0,0);
Vec3 result(0,0,0);
result = a + b;
result.Print(); // and I get vec: 0.000000 0.000000 -3.5005043
// sometimes I get -0.000000, or any other random positive or neg number.
My result's z property is never getting full zero's. Always a negative zero, sometimes a random positive or negative number, but never zeros like x and y. And I'm only adding two vector's of zeros.
I also checked if my a and b vectors are instantiating anything other than zeros, and no, everything is fine.
By the way, result.Print() is a function the Vector Class has where I simply use:
printf("%f,%f,%f\n",x,y,z);
Would anybody know why I get random numbers when adding to floating point zero's?