#include <iostream.h>
#include <math.h>
float a, b, c, d, e, f, tempa, tempb, tempc;
float BadFunction (void)
{
a = 9.0f;
b = 4.0f;
c = 5.0f;
d = 4.0f;
e = 7.0f;
f = 5.0f;
tempa = a-d;
if (tempa==0.0f) tempa = 0.000001f; // without this, undefined result
tempb = b-e;
if (tempb==0.0f) tempa = 0.000001f; // without this, undefined result
tempc = c-f;
if (tempc==0.0f) tempa = 0.000001f; // without this, undefined result
tempd = (tempa*tempa)+(tempb*tempb)+(tempc*tempc);
return tempd
}
The function should return 25+9+0 which is... 34, right?
Well it returns 10.3.... It was acually giving me an undefined result error before I put in the "if (tempb==0.0f) tempa = 0.000001f;" fix. And now it gives me a WRONG answer.
How can MSVC++ be so bad at addition and subtraction? Am I using math.h wrongly? Is there another better math header file out there? Thanks for your comments.
Keer
Edited by - Keermalec on May 3, 2001 11:57:37 AM
Collision detection prob: MSVC++ cannot add?
Hi, I've been developing my own collision detection algorithm and have finally managed to pinpoint where it is going wrong.
When running the following function, MSVC++ 6.0 returns the answer 10.3 which is clearly wrong, as any of you can check using a calculator:
Well, since 5-5 = 0 , wich is: tempc = c - f , and you then have:
if(tempc == 0.0f)
tempa = 0.000001f;
It''s not VC++ who can''t calculate, it''s your type-o
since, (0.000001*0.000001)+(-3*-3)+(0*0) = 9.something extreamly small
I don''t know how you get it to 10.3 though..
return 1;
if(tempc == 0.0f)
tempa = 0.000001f;
It''s not VC++ who can''t calculate, it''s your type-o
since, (0.000001*0.000001)+(-3*-3)+(0*0) = 9.something extreamly small
I don''t know how you get it to 10.3 though..
return 1;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement