-0.0f???

Hi, why do I get the answer -0.0f in my float multiplication? Kinda weard since it will interfere with calculations later interpreting it as -1.0f. what am I doing wrong?
1
2
///cord's a float[3]. this value = 0.0f and v value = -1.0f
result.cord[1] = (this->cord[0]*v.cord[2]);
It has something to do with how the float is multiplied.
I dont know exectly why but it can be easily fixed by doing another computation with it.

The EVIL way would be:
 
result.cord[1] = (this->cord[0]*v.cord[2]) + 0.0f;

this is so evil becouse any kind of optimization could remove the +0.0f as it does appeare to
be useless

a better but longer way would be
1
2
3
4
5
6
7

#include <math.h>

result.cord[1] = (this->cord[0]*v.cord[2]) 
if(result.cord[1]  == 0.0f){
    result.cord[1]  = fabs(result.cord[1] );
}

and yes in an if statement the -0.0f is the same as 0.0f which only shows how stupid this
entire thing really is.

I'm pretty sure there are better ways but it may not be nessisary.

Note: fabs gives the absolute value of a number -3 = 3, -0.1 = 0.1, 3 = 3, 0.1 = 0.1 and -0.0 = 0.0
Last edited on
Topic archived. No new replies allowed.