|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Re: White Paper Discuss: 296's CORDIC Math Library
A "Short Long"? Isn't this contradictive? or just an oxymoron? I thought there were short ints and long ints.
|
|
#2
|
||||
|
||||
|
Re: White Paper Discuss: 296's CORDIC Math Library
Well, short ints are 16 bit, long ints are 32, and I guess that they needed a name for a 24 bit int, so they called it a short long.
|
|
#3
|
||||
|
||||
|
Re: White Paper Discuss: 296's CORDIC Math Library
We didn't use trig in our final implementation ... but in testing we did consider it, and also decided on the CORDIC algorithm. There is an added advantage of CORDIC that your library currently doesn't utilize -- it can compute both the sin and cosine at the same time (which you do, but then you throw one of them away). For our trig needs, anyway, we needed the sin and cos of the same angles.
Implementing this in a math library (admittedly more general than our custom implementation), would be interesting conceptually. Maybe create a structure called angle. Code:
struct angle {
short long angle;
short long sin, cos;
...
};
...
short long Sin (angle ang) {
...
ang.cos = blah;
ang.sin = more blah;
return ang.sin;
}
|
|
#4
|
|||||
|
|||||
|
Re: White Paper Discuss: 296's CORDIC Math Library
Quote:
Be that as it may, here's my suggestion of an implementation: Code:
typedef enum {wantsSin, wantsCos} WhichFunc;
short long cordic(short long theAngle, WhichFunc theRequestedFunction)
{
static char firstTime = 1;
static short long prevAngle;
static short long prevSin;
static short long prevCos;
unsigned char i;
short long X = K, Y = 0, t = theAngle;
short long dx, dy;
// If this is the first time the function has been called, or if the
// requested angle is different than the last time, then go ahead and
// calculate the sine and cosine, otherwise we can skip the calculations,
// and just return the value calculated last time.
if (firstTime || (theAngle != prevAngle)) {
if ((long) abs((long)theAngle) > 4194304)
t = (short long) sgn((long) theAngle) * (8388608 - (short long) abs(theAngle));
for (i = 0; i < 23; i++) {
dx = sgn((long) X) * ((unsigned short long) abs((long) X) >> i);
dy = sgn((long) Y) * ((unsigned short long) abs((long) Y) >> i);
X -= (t > 0) ? dy : -dy;
Y += (t > 0) ? dx : -dx;
t -= (t > 0) ? e[i] : -e[i];
} // for
if (abs((long) theAngle) > 4194304) X = -X;
firstTime = 0;
prevAngle = theAngle;
prevSin = Y;
prevCos = X;
} // if (firstTime ...
if (theRequestedFunction == wantsSin)
return prevSin;
else
return prevCos;
}
short long sin(short long theAngle)
{
return cordic(theAngle, wantsSin);
}
short long cos(short long theAngle)
{
return cordic(theAngle, wantsCos);
}
Last edited by Greg Ross : 28-04-2004 at 21:24. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| White Paper Discuss: All I Ever Needed to Know I learned in FIRST poster | CD47-Bot | Extra Discussion | 5 | 28-03-2005 15:44 |
| White Paper Discuss: Interrupts for Dummies | CD47-Bot | Extra Discussion | 5 | 29-01-2005 03:24 |
| White Paper Discuss: Team 810's 2004 Dashboard Backend | CD47-Bot | Extra Discussion | 1 | 07-03-2004 10:32 |
| White Paper Discuss: Controller Circuit- Infrared Emitters | CD47-Bot | Extra Discussion | 1 | 13-02-2004 17:48 |
| Some code in C that we may need if we are in trouble | Andrew Rudolph | Chit-Chat | 16 | 07-10-2003 21:34 |