2+2 is... umm.. 5 ?
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 ?
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.
((( 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
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
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;}
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
or value = ((( 2f * 1960f ) / 2048f ) - 1f );
i think, unless otherwise explicitly stated, the compiler will treat constant numbers as integers
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement