View Single Post
  #4   Spotlight this post!  
Unread 26-01-2013, 12:23
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Require help programming a Z-Axis on a Logitech joystick

Quote:
Originally Posted by agartner01 View Post
If the most positive value is 1 and the most negative value is -1, what I've done in the past is added 1 and divided by 2 (to the joystick value). Also, an exception needs to be put in place when is the value is -1 because -1+1=0/.5 results in potentially undefined behavior (at least in c++).
There are 2 things wrong with the last sentence above.

1) Dividing zero by something does not result in undefined behavior. Dividing something by zero does.

2) 0/.5 is not dividing by 2. It is dividing by 1/2, which is multiplying by 2.