Author Topic: Definition of math constants  (Read 6805 times)

0 Members and 1 Guest are viewing this topic.


  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4815
Definition of math constants
« on: January 02, 2016, 04:05:13 PM »
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

Code: [Select]
#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


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


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)

« Last Edit: January 13, 2016, 02:56:48 AM by Stefan »