I am writing a Python extension in C/C++ that works with numeric values. When a user passes in a value that is too large to fit into a float, I want to return the value that is represented in Python code as inf
. How can I do that in C/C++? The Floating Point Objects page in the official documentation lists PyFloat_GetMax()
, but nothing for inf
. I searched the Python 3.9 source code for this function and found the following:
SetDblFlag(DBL_MAX);
SetIntFlag(DBL_MAX_EXP);
SetIntFlag(DBL_MAX_10_EXP);
SetDblFlag(DBL_MIN);
SetIntFlag(DBL_MIN_EXP);
SetIntFlag(DBL_MIN_10_EXP);
SetIntFlag(DBL_DIG);
SetIntFlag(DBL_MANT_DIG);
SetDblFlag(DBL_EPSILON);
SetIntFlag(FLT_RADIX);
SetIntFlag(FLT_ROUNDS);
But none of those seems to be what I'm looking for. Theoretically, I could add 1 to DBL_MAX, but that doesn't seem very clean. Any suggestions?