Add own version of the mathematical constants from the upcoming C++20 std::numbers.
I don't like taking a 64-bit constant and truncating it to 32 bits. For most common mathematical constants, it probably produces the right result, but it's not correctly rounded in general.
Do we actually have enough precision here if the type is long double?
Please use the correct number of digits (the smallest number of digits required to produce the correct double-precision result). Adding extra digits which don't actually affect the value is confusing.
The correct value of sqrt(2) in double-precision is 1.4142135623730951.
And now I don't trust any of the other values...
Please mark the constants with "f", e.g. 2.718282f, so there isn't an extra rounding step.
I'm not sure this describes the issue correctly. You can specify a long double as a string, or raw bits. It can't interoperate with the native long double because that might have the wrong width.
double has a precision of 15 or 16 significant digits. I don't understand why are you suggesting 17 significant digits when you asked to trim the precision down.
Besides, the reference I provided states that this value is 1.41421356237309505. Whether it's rounded to 1.4142135623730950 or 1.4142135623730951 is a bit moot, IMO.
What wording would you suggest, please?
I asked for "the smallest number of digits required to produce the correct double-precision result". This is what you get if, for example, you ask Python 2.7 or later to convert the value to a string with repr() (printf "import math\nprint(repr(math.sqrt(2)))" | python). 1.414213562373095 produces a value that's different by one ulp.
Yes, a one ulp difference is unlikely to matter for most uses, but if we're going to take the time to define these, we should define them correctly.
Maybe just FIXME: add more precise value of "e" for various long double types.
You're assuming that Python is correct. bc says 1.41421356237309504880. glibc's math.h says 1.41421356237309504880 as well. And none of these is the same as your 1.4142135623730951.
As I said, the precision of double is 15 to 16 digits and of float, 6 to 7 digits. math.h defines them with 20 digits, which is probably an agreeable precision, yes? But I believe that we call all live with a difference of ±1ulp.