Definition of math constants

Started by Stefan, January 02, 2016, 04:05:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Stefan

After studying many pixels shaders i noticed that every coder defines math constants with a random number of decimal places - from 3.14 to more than double precision.

You can let the FPU do the job.
This will not make circles rounder though :P

#define TAU radians(360.0)
#define PI acos(-1.0)
#define PI_OVER_TWO asin(1.0)
#define PI_OVER_FOUR atan(1.0)

#define PHI (1.0+sqrt(5.0))/2.0        //golden ratio


EDIT:

Intel compiler warns
"Unary operation folding into constant is supported in newer GLSL versions",
but works fine

EDIT2:

const float pi = acos(-1.0);
is incompatible with MESA compiler: "error: initializer of const variable `pi' must be a constant expression",
but can be replaced with #define pi acos(-1.0)