Merge branch 'dmigen' into phcoder
[grub2/phcoder.git] / gentrigtables.py
blob7c069f833e5f2e5f1486422524fa944670323b74
1 #!/usr/bin/python
2 # Script to generate trigonometric function tables.
4 # GRUB -- GRand Unified Bootloader
5 # Copyright (C) 2008 Free Software Foundation, Inc.
7 # GRUB is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # GRUB is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 from math import *
21 from sys import stdout
23 def write(x):
24 stdout.write(x)
26 def writeTable(arr, name):
27 indent = ' ' * 4
28 write("short ")
29 write(name)
30 write("[] =\n{\n")
31 write(indent)
32 for i in range(len(arr)):
33 if i != 0:
34 write(",")
35 if i % 10 == 0:
36 write("\n")
37 write(indent)
38 write("%d" % arr[i])
39 write("\n};\n")
41 def main():
42 sintab = []
43 costab = []
44 for i in range(256):
45 # Convert to an angle in 1/256 of a circle.
46 x = i * 2 * pi / 256
47 sintab.append(int(round(sin(x) * 16384)))
48 costab.append(int(round(cos(x) * 16384)))
50 write("#define TRIG_ANGLE_MAX 256\n")
51 write("#define TRIG_FRACTION_SCALE 16384\n")
52 writeTable(sintab, "sintab")
53 writeTable(costab, "costab")
55 if __name__ == "__main__":
56 main()
58 # vim:ai et sw=4 ts=4