Go to Post MORAL: Always wear safety glasses when you're putting on your safety glasses. ;) - Joel Glidden [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Spotlight this post!  
Unread 07-08-2005, 17:47
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: Strange products upon running code...

Quote:
Originally Posted by Billfred
In essence, it forces the compiler to treat WHEEL_RAD like a long variable.
So right you are BillFred! (long) is a c "unary" operator called a cast. It forces or "coerces" a type conversion.

...if you can, take a peek at a c manual like K&Rs "The c programming Language" ... p 46-47

In your original equation,
unsigned int WheelCirc = (2000 * WHEEL_RAD * PI) / 1000000;
the type conversion takes place across assignments, that is, the value of the right side is converted to the type of the left side. An unsigned int in the pic is 16 bits, so you get to play with 0-65535. Unfortunately, your values take you way outside this range. But with Mikes eq:
unsigned int WheelCirc = ((long) WHEEL_RAD * 710) / 113;

the cast, (long) forces the right hand side calculations to be done in 32 bits.
Then, the assignment (the = sign) forces a type conversion to 16 bits.

The higher order bits get chopped when "shortening" - going from long to unsigned int, but the value of the right hand side, now fits 0-65535, so you get the answer you expect.

(I also like the 355/113 trick )

Eric
__________________

Don't PANIC!
S. P. A. M.

Last edited by EricS-Team180 : 08-08-2005 at 12:42.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Out of the Box Camera Code russell Programming 9 21-10-2009 05:28
Team THRUST - Kevin's Code and Camera Code Combine Chris_Elston Programming 3 31-01-2005 22:28
Problem running compiled code jskene Programming 10 23-01-2005 21:13
heres the code. y this not working omega Programming 16 31-03-2004 15:18
Strange IR sensor movement with default tracker code wun Programming 5 19-03-2004 10:51


All times are GMT -5. The time now is 00:13.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi