Author mark.dickinson
Recipients christian.heimes, mark.dickinson, rpetrov, skip.montanaro, tim.peters
Date 2009-01-04.22:57:09
SpamBayes Score 0.00671144
Marked as misclassified No
Message-id <>
Tim, I'm in need of some advice on Py_IS_INFINITY.  It's currently
implemented (on platforms that don't provide isinf) as

#define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))

I'd like to rewrite it as something like:

#define Py_IS_INFINITY_D(X) ((X) < -DBL_MAX || (X) > DBL_MAX)
#define Py_IS_INFINITY_F(X) ((X) < -FLT_MAX || (X) > FLT_MAX)
#define Py_IS_INFINITY(X) (sizeof(X) == sizeof(double) ? Py_IS_INFINITY_D(X) : Py_IS_INFINITY_F(X))

Are there any hidden (or obvious) numerical pitfalls with
this approach?

The reason for the rewrite is that the current Py_IS_INFINITY
can give false positives on x86 for values that are
pretending to be doubles, but are actually coming from an
80-bit x87 register.
Date User Action Args
2009-01-04 22:57:10mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, skip.montanaro, christian.heimes, rpetrov
2009-01-04 22:57:10mark.dickinsonsetmessageid: <>
2009-01-04 22:57:09mark.dickinsonlinkissue4575 messages
2009-01-04 22:57:09mark.dickinsoncreate