Martin Storsjö <[email protected]> writes: > From: "Ronald S. Bultje" <[email protected]> > > MSVC don't recognize the divisions by zero as meaning > infinity/nan. > --- > libavutil/mathematics.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h > index a734b75..10ed881 100644 > --- a/libavutil/mathematics.h > +++ b/libavutil/mathematics.h > @@ -25,6 +25,7 @@ > #include <math.h> > #include "attributes.h" > #include "rational.h" > +#include "intfloat.h" > > #ifndef M_LOG2_10 > #define M_LOG2_10 3.32192809488736234787 /* log_2 10 */ > @@ -32,12 +33,21 @@ > #ifndef M_PHI > #define M_PHI 1.61803398874989484820 /* phi / golden ratio */ > #endif > +#ifdef _MSC_VER > +#ifndef NAN > +#define NAN av_int2float(0x7fc00000) > +#endif > +#ifndef INFINITY > +#define INFINITY av_int2float(0x7f800000) > +#endif > +#else > #ifndef NAN > #define NAN (0.0/0.0) > #endif > #ifndef INFINITY > #define INFINITY (1.0/0.0) > #endif > +#endif
The standard says these macros should expand to constant expressions, which those function calls are not, but that doesn't matter for our purposes (yes, I suggested this in the first place). The amount of ifdef nesting would be reduced by placing these definitions in a separate #ifdef _MSC_VER block before the existing ones. That said, I'm less than pleased with adding compiler-specific hacks like this, especially in public headers. Like stdint, such things really belong in a separate fixup layer unless they can be done in a compiler/system-independent way (such as a simple existence check). One possibility is always using the int2float version as fallback. I know of at least one other compiler that also fails on the division by zero. -- Måns Rullgård [email protected] _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
