102 #define Cordic_T_Bits (int)(sizeof(Cordic_T) << 3) 103 #define FCordic_T_Bits (int)(sizeof(FCordic_T) << 3) 105 #define Cordic_T_FractionBits (int)(Cordic_T_Bits - 3 - 1) 107 #define Cordic_T_STR "typedef int Cordic_T;" 108 #define UCordic_T_STR "typedef unsigned int UCordic_T;" 109 #define FCordic_T_STR "typedef double FCordic_T;" 117 #define Cordic_One (1UL << Cordic_T_FractionBits) 118 #define Cordic_K (Cordic_One * 0.6072529350088812561694) 119 #define Cordic_INVK (Cordic_One / 0.6072529350088812561694) 120 #define Cordic_KP (Cordic_One * 1.20749706776307212887772) 121 #define Cordic_INVKP (Cordic_One * 1/1.20749706776307212887772) 122 #define Cordic_HalfPI ((UCordic_T) (Cordic_One * M_PI_2) ) 123 #define Cordic2FP(a) ( (double) (a) / (double) (Cordic_One)) 124 #define FP2Cordic(a) ((Cordic_T) (Cordic_One * (a))) 167 fprintf(FO,
"#define Cordic_One 0x%lx /* %.15le */\n",
169 fprintf(FO,
"#define Cordic_K 0x%lx /* %.15le */\n",
171 fprintf(FO,
"#define Cordic_INVK 0x%lx /* %.15le */\n",
173 fprintf(FO,
"#define Cordic_KP 0x%lx /* %.15le */\n",
175 fprintf(FO,
"#define Cordic_INVKP 0x%lx /* %.15le */\n",
177 fprintf(FO,
"#define Cordic_HalfPI 0x%lx /* %.15le */\n",
179 fprintf(FO,
"#define Cordic2FP(a) ( (double) (a) / (double) (Cordic_One)) \n");
180 fprintf(FO,
"#define FP2Cordic(a) ((Cordic_T) (Cordic_One * (a)))\n");
182 fprintf(FO,
"#ifdef CORDIC_TABLE\n");
189 fprintf(FO,
"static const Cordic_T v_atangrad[] = {\n");
191 fprintf(FO,
"\t0x%lx, /* %.8le */\n",
275 if (vecmode >= 0 &&
Y < vecmode || vecmode < 0 && Z >= 0) {
317 int main (
int argc,
char *argv[])
342 fprintf(
stderr,
"-o filename is CORDIC C table output file\n");
346 FO =
fopen(oname,
"w");
354 fprintf(FO,
"#ifndef _CORDIC_INC_H\n");
355 fprintf(FO,
"#define _CORDIC_INC_H\n");
361 fprintf(FO,
" By Mike Gore 2015, Cordic C Table\n");
367 fprintf(FO,
"#else // CORDIC_TABLE\n");
368 fprintf(FO,
"extern const Cordic_T v_atangrad[];\n");
369 fprintf(FO,
"#endif // CORDIC_TABLE\n");
370 fprintf(FO,
"#endif // _CORDIC_INC_H\n");
372 printf(
"// Verify CORDIC table \n");
377 a = (int) 100 * d + 0.000005;
381 printf(
"// End of CORDIC verify\n");
Cordic_T asinCordic(Cordic_T a)
Compute ArcSine (a) Only works for |a| < 0.98.
void cordit1(Cordic_T x, Cordic_T y, Cordic_T z, Cordic_T vecmode)
This is the circular method. One slight change from the other methods is the y < vecmode test...
MEMSPACE size_t WEAK_ATR strlen(const char *str)
String Length.
int main(int argc, char *argv[])
Create C Cordic Tables and test the results.
void dump_tables(FILE *FO)
Create Cordic tables Normalize base number system to 1.0 == Cordic_One == PI/2 (90 degrees) Example ...
Common Linux/POSIX time functions.
#define Cordic_T_FractionBits
MEMSPACE FILE * fopen(const char *path, const char *mode)
POSIX Open a file with path name and ascii file mode string.
MEMSPACE int fprintf(FILE *fp, const char *format,...)
fprintf function Example user defined printf function using fputc for I/O This method allows I/O to d...
MEMSPACE time_t time(time_t *t)
Return second from epoch - POSIX function.
uint32_t time_t
type of EPOCH result.
MEMSPACE tm_t * localtime(time_t *tp)
Convert POSIX epoch time_t *tp into POSIX tm_t *result.
void Circular(Cordic_T x, Cordic_T y, Cordic_T z)
Main Cordic routine - used for basic trig and vector rotations.
MEMSPACE char * asctime(tm_t *t)
Convert tm_t *t structure into POSIX asctime() ASCII string.
int Cordic_T
cordicC.c – J. Pitts Jarvis, III cordicC.c computes CORDIC constants and exercises the basic algorit...
MEMSPACE int printf(const char *format,...)
char * get_date()
Get the current date in a string.
MEMSPACE char * basename(char *str)
POSIX Basename of filename.
static Cordic_T v_atan[Cordic_T_Bits+1]
#define sprintf(s, format, args...)
void PrintXYZ(char *str)
Display X,Y,Z as floating point.