Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C preprocessor evaluate sin() of constant

Is there a way to convince the C preprocessor to evaluate a transcendental function of a constant at compile-time?

For example, replace (int)256*sin(PI/4) with 181. This will help me keep magic numbers out of my code.

If it makes a difference, I'm using MSPGCC 4.5.3 and I have no sin() or cos() available at runtime.

like image 505
markrages Avatar asked Mar 20 '12 21:03

markrages


1 Answers

The C preprocessor can't provide sin() or cos().

For my applications, I use a perl script to create a separate .h file containing the needed precalculations. There are probably sexier ways to do it, but this integrates into my workflow well enough.

like image 117
Throwback1986 Avatar answered Oct 06 '22 10:10

Throwback1986