Is there any difference between these:
float foo1 = (int)(bar / 3.0);
float foo2 = floor(bar / 3.0);
As I understand both cases have the same result. Is there any difference in the compiled code?
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.
Casting to an int will truncate toward zero.
floor()will truncate toward negative infinite. This will give you different values ifbarwere negative.