View Single Post
  #11   Spotlight this post!  
Unread 27-02-2007, 16:11
TimCraig TimCraig is offline
Registered User
AKA: Tim Craig
no team
 
Join Date: Aug 2004
Rookie Year: 2003
Location: San Jose, CA
Posts: 221
TimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to behold
Re: Trouble with Autonomous

Quote:
Originally Posted by AustinSchuh View Post
It might be better to simplify that further using some algebra to something like
Code:
time = (int)((long)10 * (long)degrees / (long)3)
That way, you won't run into interger or long overflow problems until degrees is 100 times as large as it would have had to be earlier.
True, he doesn't gain anything in using 1000 and 300 vs 10 and 3. And in that case he doesn't need to force the compiler to do the computation as long. 10 * 360 = 3600 which fits quite comfortably in an int.

BTW, you only need the first (long) cast. Once one element of that calcuation is long, the compiler will force the rest to long to complete it. Actually, casting either the 10 or degrees will do it. Casting the 3 to long will force the result to long but the compiler is free to do the calculation in the parentheses as int then promote it to long before the division.