0

g++ 5.4.0 under cygwin will successfully compile programs with M_PI with no parameters.

However, with -std=c++11 it will give an error.

This question: How to use the PI constant in C++

implies that older machines might need to define

#define _USE_MATH_DEFINES
#include <math.h>

But in fact no one should be including math.h, now it should be

#include <cmath>

What is the standard, what should it be? On my ubuntu, with a much older g++ 4.8.4 it compiles fine.

It is utterly ridiculous that each programmer should define

const double pi = 3.14159265358979;

for themselves.

Community
  • 1
  • 1
Dov
  • 8,000
  • 8
  • 46
  • 75
  • 2
    why it is utterly ridiculous? For a mathematician it may sound utterly ridiculous that you call the value `3.14159265358979` pi. When you cut infinite digits `3` can be just as valid as approximation as any other choice – 463035818_is_not_an_ai Oct 07 '16 at 14:50
  • 1
    pi is intrinsicly defined in the math lib when you do `4*atan(-1)` making the definition of pi redundant and possibly different depending on the way `atan` is computed. and you get ovoïd circles :) – Jean-François Fabre Oct 07 '16 at 14:52
  • 1
    @tobi303: `double pi = 3` has an error which is _well_ beyond the ULP. Because pi is irrational, there is in fact a unique best approximation. – MSalters Oct 07 '16 at 15:09
  • @MSalters I should be more careful with making sloppy not too serious comments when you are around :P – 463035818_is_not_an_ai Oct 07 '16 at 15:13
  • @tobi303: Now you've ruined my weekend, by telling met that you've been putting sloppy comments all over StackOverflow. Can't leave those unchallenged, so that's my next 48 hours wasted :P – MSalters Oct 07 '16 at 15:15
  • @MSalters dont worry, the rest of the day I was actually seriously working.... but I have a full weekend without plans in front of me – 463035818_is_not_an_ai Oct 07 '16 at 15:17

0 Answers0