26 lines
849 B
Python
26 lines
849 B
Python
#!/usr/bin/env python3
|
|
import math
|
|
|
|
N = 4096
|
|
FIXED_ONE = 65536
|
|
|
|
def generate_table(func_name, math_func):
|
|
"""Generate a table for the given math function"""
|
|
with open(f"axl_{func_name}_table.inc", "w") as file:
|
|
file.write(f"//{func_name}[{N}] - fixed point 16.16\n")
|
|
file.write("//Generated by gen_math_tables.py\n\n")
|
|
file.write(f"static inline f16_16 axl_{func_name}_table[{N}] = \n{{\n")
|
|
for i in range(N):
|
|
angle = i * 2.0 * math.pi / (N - 1)
|
|
value = math_func(angle)
|
|
fixed_value = round(value * FIXED_ONE)
|
|
file.write(f"\t{fixed_value}{',' if i < N - 1 else ''}\n")
|
|
file.write("};")
|
|
|
|
def main():
|
|
generate_table("sin", math.sin)
|
|
generate_table("cos", math.cos)
|
|
print("Generated sin and cos tables")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|