View Single Post
  #7   Spotlight this post!  
Unread 08-01-2008, 15:39
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,815
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: How does division work?

Just to throw in my two cents here:

first for the OP - integer division ALWAYS truncates (at least it does it most of the major languages in use today). If you need more significant digits, by far the easiest solution is to typecast your variables (both the divisor and the dividend) - int a=1; int b=2; float c=((float) a)/((float) b); gives you c = 0.5.

Second, to the discussion on bitwise operations and performance: For these robots, you really don't need to be that concerned with performance. If you follow the KISS (keep it simple, stupid) strategy, you're code won't be long enough of complicated enough to make performance an issue. When it comes to the robot controller, the difference between doing something one way or another might be a few milliseconds, but the human operator is only operating on the scale of seconds, so the level of performance you might gain is going to be lost, unless you've made your code overly complex.

Last year, our code was probably two-three times more complex than it needed to be, because we were using it as a teaching tool more than anything else, and the same thing will be true this year. Even with that, though, there was absolutely no detectable performance degradation to the robot.

Yes, in some systems performance really does matter - i remember back in school making an AI for class and fine tuning everything, down to the point where each game state was sized to exactly fit into the processor cache and using optimizations for the specific brand/model of the processor being used, and in that case it did pay off in noticeable quantities. It's good as a programmer to be aware of performance, and even to be aware of the performance characteristics of the libraries you're using, but you also need to know when you need to apply that knowledge and when you don't.