Insane ~ Simple Arithmatic Q

Nov 26, 2009 at 4:29am
Sorry to ask this - it is probably a stupid question:

Why does:

(e3*p + e0*q - e1*r)/2 return a float > 0

and

(1/2)*(e3*p + e0*q - e1*r) return 0

??? I have no idea what is going on lol

Nick
Nov 26, 2009 at 8:42am
1/2 is an integer division, the result gets truncated to 0 so you are multiplying the other part with zero.
try (1/2.)*(e3*p + e0*q - e1*r) , the period after the two makes it a double
Nov 26, 2009 at 10:17am
Haha wow that is amazing! Gotta say I'm not a fan of that lol I just tested then:

float t = 1/2;
cout << t;

Output: 0

Looks like I've got a lot of code to edit haha

Thanks though,

Nick :)

Topic archived. No new replies allowed.