~ubuntu-branches/ubuntu/gutsy/imaze/gutsy

« back to all changes in this revision

Viewing changes to source/gentrigtab.c

  • Committer: Bazaar Package Importer
  • Author(s): Hans Freitag
  • Date: 2002-11-28 13:24:12 UTC
  • Revision ID: james.westby@ubuntu.com-20021128132412-lw82xl9oq1j36g8b
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** - - -  iMaze  - - -
 
3
**
 
4
** Copyright (c) 1993-2001 by Hans-Ulrich Kiel & Joerg Czeranski
 
5
** All rights reserved.
 
6
**
 
7
** Redistribution and use in source and binary forms, with or without
 
8
** modification, are permitted provided that the following conditions are
 
9
** met:
 
10
**
 
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
 
18
**    permission.
 
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.
 
21
**
 
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.
 
33
**
 
34
**
 
35
** Datei: gentrigtab.c
 
36
**
 
37
** Kommentar:
 
38
**  Berechnet die Sinus-, Cosinus- und Arcustangens-Tabellen
 
39
**  und schreibt sie in trigtab.c
 
40
*/
 
41
 
 
42
 
 
43
#include <stdio.h>
 
44
#include <math.h>
 
45
 
 
46
#include "global.h"
 
47
 
 
48
static char sccsid[] = "@(#)gentrigtab.c        3.2 12/3/01";
 
49
 
 
50
 
 
51
#define N (TRIGANZ / 4)  /* N = 90 Grad */
 
52
 
 
53
#define M (TRIGANZ / 2)  /* M entspricht tan = 1 */
 
54
 
 
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.) */
 
57
 
 
58
 
 
59
/*
 
60
** main
 
61
**  die Hauptroutine
 
62
**
 
63
** Seiteneffekte:
 
64
**  Die Datei 'trigtab.c' wird geschrieben
 
65
*/
 
66
int main(void)
 
67
{
 
68
        int i;
 
69
 
 
70
        /* Cosinuswerte bis 90 Grad berechnen (-TRIGFAKTOR ... TRIGFAKTOR) */
 
71
        for (i = 0; i < N; i++)
 
72
        {
 
73
                tab[i] = cos(3.1415926536 / 2.0 * i / N) * TRIGFAKTOR;
 
74
        }
 
75
        tab[N] = 0;  /* 90 Grad */
 
76
 
 
77
        /* Arcustangenswerte von 0 bis 1 mittels Sinus/Cosinus-Tabelle
 
78
           berechnen (0 ... TRIGANZ/8) */
 
79
        {
 
80
                int winkel;
 
81
                int j, k; /* Tangens von winkel - 1 und winkel */
 
82
 
 
83
                j = -1;
 
84
                for (winkel = 1; winkel <= N / 2; winkel++)
 
85
                {
 
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;
 
89
                        j = k;
 
90
                }
 
91
        }
 
92
 
 
93
        /* Dateikopf schreiben */
 
94
        puts("/*");
 
95
        puts("** iMaze: Sinus-, Cosinus- und Arcustangens-Tabelle");
 
96
        puts("** Diese Datei wird automatisch erstellt!");
 
97
        puts("*/");
 
98
        putchar('\n');
 
99
        puts("#include \"global.h\"");
 
100
        putchar('\n');
 
101
        printf("static char sccsid[] = \"%s\";\n\n", sccsid);
 
102
 
 
103
        /* Cosinus-Tabelle ausgeben */
 
104
        puts("int costab[TRIGANZ] =");
 
105
        putchar('{');
 
106
        for (i = 0; i < TRIGANZ; i++)
 
107
        {
 
108
                /* 8 Werte pro Zeile */
 
109
                if (i % 8)
 
110
                        putchar(' ');
 
111
                else
 
112
                        putchar('\n'), putchar('\t');
 
113
 
 
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]);
 
116
        }
 
117
        putchar('\n');
 
118
        puts("};");
 
119
        putchar('\n');
 
120
 
 
121
        /* Sinus-Tabelle ausgeben */
 
122
        puts("int sintab[TRIGANZ] =");
 
123
        putchar('{');
 
124
        for (i = 0; i < TRIGANZ; i++)
 
125
        {
 
126
                /* 8 Werte pro Zeile */
 
127
                if (i % 8)
 
128
                        putchar(' ');
 
129
                else
 
130
                        putchar('\n'), putchar('\t');
 
131
 
 
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]);
 
134
        }
 
135
        putchar('\n');
 
136
        puts("};");
 
137
        putchar('\n');
 
138
 
 
139
        /* Arcustangens-Tabelle ausgeben */
 
140
        puts("int atantab[TRIGANZ + 1] =");
 
141
        putchar('{');
 
142
        for (i = 0; i <= TRIGANZ; i++)
 
143
        {
 
144
                /* 8 Werte pro Zeile */
 
145
                if (i % 8)
 
146
                        putchar(' ');
 
147
                else
 
148
                        putchar('\n'), putchar('\t');
 
149
 
 
150
                printf("%d,", i < M ?
 
151
                        (TRIGANZ - tab2[M - i]) % TRIGANZ : tab2[i - M]);
 
152
        }
 
153
        putchar('\n');
 
154
        puts("};");
 
155
        return 0;
 
156
}