View Single Post
  #14   Spotlight this post!  
Unread 30-05-2002, 10:26
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
false negatives

The way that PBASIC "handles" negatives is by treating them as their standard two's complement. -1 is treated as approx. 65,000. Therefore, any useful operation will fail because the number is not actually negative. Because the two's complement system was originally designed to allow "negative" numbers to be added and subtracted using the same CPU instructions as unsigned numbers, these two operations work just fine in PBASIC.

If you need to do negatives for some reason (my team hasn't had any yet), the easiest thing to do is just pretend that something else is zero. For example, you could think of the number 120 as being -7 and the number 134 as being +7. Then, anytime you use this number, just use a Min/Max statement and then subtract 127 off the end, much like the white paper Innovation First has on "One Joystick Tank Drive."
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php