Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jesper T

2+2 is... umm.. 5 ?

This topic is 6232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m using msvc++ to do this: value = ((( 2 * 1960 ) / 2048 ) - 1 ); the value is previously declared as type double.. what i cant understand is that when i check the value''s value its 0 !!! how can this be possible ?? ive done more accurate calculations before, might it have something to do with how I''ve set up msvc++ ? any ideas ?

Share this post


Link to post
Share on other sites
Advertisement
If you do the math it comes out to .91 . Now I can''t remember exactly as I''m still learning but a double doesn''t hold decimal values. Try using float and see if that helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
((( 2 * 1960 ) / 2048 ) = 1
1-1 = 0

doesn''t matter if value is a double, the conversation is done after the integer expression is evalutated.

however

((( 2.0 * 1960 ) / 2048 )-1 ~ 0.91




Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Doubles handle decimals, handle 4 decimal more than float

Share this post


Link to post
Share on other sites
I correct myself. Sorry about that. I tryed the code out and got the same thing you did. I split the math functions into multiple lines and that solved the problem.

  

#include <iostream>

int main()
{
float Value;

Value = 2 * 1960;
Value = Value / 2048;
Value = Value - 1;
std::cout<< Value;

return 0;

}

Share this post


Link to post
Share on other sites
try value = ((( 2.0 * 1960.0 ) / 2048.0 ) - 1.0 );
or value = ((( 2f * 1960f ) / 2048f ) - 1f );

i think, unless otherwise explicitly stated, the compiler will treat constant numbers as integers

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!