Why does the below calculation produce a negative value?
long interval = 0;
interval = ((60000 * 60) * 24) * 30;
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.
Every expression in there is being evaluated (at compile-time, of course; it’s a constant) as
int * intinstead oflong * long. The result overflows at some point. So just useLto make all the operand literals long:Of course you could get away with only making some of the operands longs, but I tend to find it’s easier to just change everything.
Having said all of this, if you’re looking for “30 days-worth of milliseconds” it would be better to use: