This behaves as wanted:
double t = r[1][0] * .5;
But this doesn’t:
double t = ((1/2)*r[1][0]);
r is a 2-D Vector.
Just thought of a possibility. Is it because (1/2) is considered an int and (1/2) == 0?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, both of those literals are of type
int, therefore the result will be of typeint, and that result is 0.Instead, make one of those literals a
floatordoubleand you’ll end up with the floating point result of0.5, ie:double t = ((1.0/2)*r[1][0]);Because
1.0is of typedouble, theint2 will be promoted to adoubleand the result will be adouble.