View Single Post
  #5   Spotlight this post!  
Unread 12-01-2005, 13:17
cabbagekid2 cabbagekid2 is offline
Registered User
#0368 (Kika Mana)
 
Join Date: Jun 2001
Rookie Year: 2000
Location: Honolulu, HI
Posts: 85
cabbagekid2 has a spectacular aura aboutcabbagekid2 has a spectacular aura aboutcabbagekid2 has a spectacular aura about
Re: Program for variable speed

Quote:
Originally Posted by Alan Anderson
This is using integer arithmetic. The division by 254 gives an intermediate result of zero, so the final answer is always 127.

You need to either a) force floating point arithmetic by dividing by 254.0, or b) scale the intermediate calculations up by multiplying by a constant (e.g. 256) first and dividing by the same constant just before adding the 127.

So would this be the same if I just added parenthesis and changed the formula to this:

if (p1_y >= 147)
p1_y = ((p1_wheel*(p1_y - 127))/254) + 127;

or is this what you were trying to say?

if (p1_y >= 147)
p1_y = ((p1_wheel*(p1_y - 127)*254)/(254*254)) + 127;

Thanks, I shall try these out!