4
** Copyright (c) 1993-2001 by Hans-Ulrich Kiel & Joerg Czeranski
5
** All rights reserved.
7
** Redistribution and use in source and binary forms, with or without
8
** modification, are permitted provided that the following conditions are
11
** 1. Redistributions of source code must retain the above copyright
12
** notice, this list of conditions and the following disclaimer.
13
** 2. Redistributions in binary form must reproduce the above copyright
14
** notice, this list of conditions and the following disclaimer in the
15
** documentation and/or other materials provided with the distribution.
16
** 3. The name of the authors may not be used to endorse or promote
17
** products derived from this software without specific prior written
19
** 4. The name ``iMaze'' may not be used for products derived from this
20
** software unless a prefix or a suffix is added to the name.
22
** THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
23
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
** DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT,
26
** INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30
** STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
** IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
** POSSIBILITY OF SUCH DAMAGE.
35
** Datei: gentrigtab.c
38
** Berechnet die Sinus-, Cosinus- und Arcustangens-Tabellen
39
** und schreibt sie in trigtab.c
48
static char sccsid[] = "@(#)gentrigtab.c 3.2 12/3/01";
51
#define N (TRIGANZ / 4) /* N = 90 Grad */
53
#define M (TRIGANZ / 2) /* M entspricht tan = 1 */
55
static int tab[N + 1]; /* fuer Cosinuswerte von 0 bis 90 Grad (incl.) */
56
static int tab2[M + 1]; /* fuer Arctustangenswerte von 0 bis 1 (incl.) */
64
** Die Datei 'trigtab.c' wird geschrieben
70
/* Cosinuswerte bis 90 Grad berechnen (-TRIGFAKTOR ... TRIGFAKTOR) */
71
for (i = 0; i < N; i++)
73
tab[i] = cos(3.1415926536 / 2.0 * i / N) * TRIGFAKTOR;
75
tab[N] = 0; /* 90 Grad */
77
/* Arcustangenswerte von 0 bis 1 mittels Sinus/Cosinus-Tabelle
78
berechnen (0 ... TRIGANZ/8) */
81
int j, k; /* Tangens von winkel - 1 und winkel */
84
for (winkel = 1; winkel <= N / 2; winkel++)
86
k = (M * tab[N - winkel] + tab[winkel] / 2) / tab[winkel];
87
for (i = j + 1; i <= k; i++)
88
tab2[i] = i <= (j + k) / 2 ? winkel - 1 : winkel;
93
/* Dateikopf schreiben */
95
puts("** iMaze: Sinus-, Cosinus- und Arcustangens-Tabelle");
96
puts("** Diese Datei wird automatisch erstellt!");
99
puts("#include \"global.h\"");
101
printf("static char sccsid[] = \"%s\";\n\n", sccsid);
103
/* Cosinus-Tabelle ausgeben */
104
puts("int costab[TRIGANZ] =");
106
for (i = 0; i < TRIGANZ; i++)
108
/* 8 Werte pro Zeile */
112
putchar('\n'), putchar('\t');
114
printf("%d,", i < N ? tab[i] : i < 2 * N ? -tab[2 * N - i] :
115
i < 3 * N ? -tab[i - 2 * N] : tab[4 * N - i]);
121
/* Sinus-Tabelle ausgeben */
122
puts("int sintab[TRIGANZ] =");
124
for (i = 0; i < TRIGANZ; i++)
126
/* 8 Werte pro Zeile */
130
putchar('\n'), putchar('\t');
132
printf("%d,", i < N ? tab[N - i] : i < 2 * N ? tab[i - N] :
133
i < 3 * N ? -tab[3 * N - i] : -tab[i - 3 * N]);
139
/* Arcustangens-Tabelle ausgeben */
140
puts("int atantab[TRIGANZ + 1] =");
142
for (i = 0; i <= TRIGANZ; i++)
144
/* 8 Werte pro Zeile */
148
putchar('\n'), putchar('\t');
150
printf("%d,", i < M ?
151
(TRIGANZ - tab2[M - i]) % TRIGANZ : tab2[i - M]);