Variables with Undefined Values

Started by
17 comments, last by Eleventy 20 years, 10 months ago
I don't think there's any easy way around just fixing the bug. Go through the entire code searching for the '/' character. Each time you find a division, decide whether the denominator could be zero and make the appropriate changes. I don't want to sound like i'm telling you what to do, but every time you write a division into your program, it's a good idea to check if the denominator could be zero.

[edited by - kdogg on May 30, 2003 3:56:36 AM]
Advertisement
Thanks for the responses - I will try both methods to see what I can do to fix this - I''m kind of "stuck" as of right now trying to find this bug.

My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM
We (your friends) will miss you, YodaTheCoda!

Eleventy

By the way, a floating exception can be caused by things other than dividing by zero. If you overflow an int, for example, you might have a floating exception. Using a number smaller than the precision of the machine can result in a floating exception, as could using an uninitialized variable. Sometimes, windows can be a difficult OS to be working in when it comes to diagnosing a floating exception. Case and point, you don't even know for sure a FPE is the culprit in this case. I'd guess (mind you without even looking at your code) that your algorithm divides a very small number by a very big number somewhere and then tries to assign the result in some variable. While dividing by zero is certainly the most common cause of a FPE in general programming, mathematical routines can create nagging errors if you're not careful about your variable types. You might consider using a math library that will take care of some of that stuff for you. For example, i've used the Cephes C library in the past for high precision math routines. It provides some error checking and will catch some exceptions that might cause fatal runtime errors otherwise if you aren't careful.

[edited by - kdogg on May 30, 2003 4:34:58 AM]
quote:Original post by kdogg
By the way, a floating exception can be caused by things other than dividing by zero. If you overflow an int, for example, you might have a floating exception. Using a number smaller than the precision of the machine can result in a floating exception, as could using an uninitialized variable. Sometimes, windows can be a difficult OS to be working in when it comes to diagnosing a floating exception. Case and point, you don''t even know for sure a FPE is the culprit in this case. I''d guess (mind you without even looking at your code) that your algorithm divides a very small number by a very big number somewhere and then tries to assign the result in some variable. While dividing by zero is certainly the most common cause of a FPE in general programming, mathematical routines can create nagging errors if you''re not careful about your variable types. You might consider using a math library that will take care of some of that stuff for you. For example, i''ve used the Cephes C library in the past for high precision math routines. It provides some error checking and will catch some exceptions that might cause fatal runtime errors otherwise if you aren''t careful.


Are those math libraries any slower than the standard C includes? That''s exactly what I need - more precision. The main reason I''m having trouble with collision detection is the lack of precision the current C libraries have. Btw, thanks for the link.

My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM

Eleventy

Also, a variable could get nuked if you try something weird like calculating a cosinus or sinus of a value which is out of range for that function. (As I accidently tried once until i noticed, that i needed tangens in that case ;-)

Just my 2-Cents

LightBrain website relaunched, BomberFUN only USD 9.99
visit http://www.lightbrain.de
quote:Original post by JoshT172
Thanks - but, I''ve never used the debugger...


This is the perfect time to learn. Stepping through code and watching the values of variables change is *easy* with the right IDE. Once you start, you''ll wonder how you ever developed code without it. Which compiler are you using?

Brianmiserere nostri Domine miserere nostri
BriTeg: I'm using MSVC++ .NET Enterprise Architect (entire studio collection). However, I believe that I've found my problem. Might as well go ahead and tell me how to use the debugger, that way I can find out which acos(), asin(), etc funtion is causing the problem without having to test each one.

TroneX: Hah - I believe you have just found my problem! Never even considered the fact that acos(), asin() and atan() can return undefined values... Doh!! Thanks for your reply - that really helps!


P.S. Sorry for taking so much time to reply, my stupid IE brower locked up my computer for no apparent reason... All I did was simply open another window and suddenly it locks up (Typical M$ problem) - making me have to reboot my computer.

My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM

[edited by - JoshT172 on May 30, 2003 12:37:24 PM]

Eleventy

It ended up being all of the acos() asin() and atan() functions that I had in my program. Works like a charm now. Thanks for all the replies and advice.

My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM

Eleventy

On a side note, if you''re going to download software off Kazaa or IRC, try not to be too obvious about it. JoshT172, I''m not trying to pick on you or make fun of you; I''ve seen this in many other threads. If you have a pirated copy of software, don''t bother saying exactly what it is. In this case, just say "I have Visual C++ .Net". Warez kiddies always offer the most expensive version of any software package, so it''s clear to anyone ''in the know'' that it''s not legal. Pirating is looked down upon in these forums, and you don''t want to have a reputation of stealing stuff. Just a bit of advice.

P.S. If you actually did buy the Enterprise Architect version of VS.Net, then you wasted a whole lot of money.

--Buzzy

This topic is closed to new replies.

Advertisement