PDA

View Full Version : c++ values acting odd.


nightthepope
03-15-2005, 09:48 PM
I have this program and when it outputs its values to me using cout, sometimes I get some very odd numbers.

Such as for a double I would expect its value to be like "0" I get something like "2.640e-392". Or numbers of the like.

Or for other numbers like some of my ints, even those which werent assigned a value other than zero are having values of like -256.

What is going on?

I've traced my variables and nothing should lead to these sort of numbers.

Jason
03-15-2005, 11:16 PM
having the code to look over might help us trace your problems... as for why its doing that, it has to be something your doing in the code.


Jason

shmoove
03-16-2005, 11:44 AM
As far as the doubles are concerned, you have to keep in mind that the floating point format sacrifices precision in order to have a very broad range, so there are usually rounding errors in calculations. That why you shouldn't compare floating point values to 0, but instead you check that abs(myDouble) < EPSILON where EPSILON is an arbitrarily small value. "2.640e-392" is 2.64*10^(-392), a very very small number, and as far as floating point numbers are concerned that value should be treated as 0.

With the ints, if you assigned 0 then they should print 0, but if you didn't assign anything then they contain garbage, so you can't assume anything.

shmoove

nightthepope
03-20-2005, 04:49 AM
Thanks for the clearup about doubles.
The problem with the random ints was I was just calling beyond the length of my array. Silly me.
Instead of an error it just gave me random numbers.