Using M_PI with C89 standard

A conforming standard library file math.h is not only not required to, but actually must not define M_PI by default. In this context ‘by default’ means that M_PI must only get defined through compiler-specific tricks, most often undefined behavior through the use of reserved identifiers.

Just define the constant yourself (you can use the name M_PI freely, but should you want to be able to compile the code with a non-conforming compiler, you must first check that M_PI is not already defined). For convention’s sake, do not define M_PI as anything other than (the approximation of) pi.

Leave a Comment