Hi Francois,
On 01/10/14 15:29, Francois Gouget wrote:
The INFINITY and NAN definitions have been added to math.h in recent versions of msvcrt (i.e. they were not present in Visual C++ 2008 but are in Visual C++ 2013). This means we have to provide them too otherwise code that compiles with Visual C++ could fail to compile with Winelib.
To do so I'm just reusing the definition we have in wine/port.h.
This definition bothers me a bit in that it clearly depends on the in-memory representation of these floating point constants, which might not be very portable (depending on whether the system uses IEEE 754 or not, etc). In d3dx9_36 we used to define NAN as '0.0f / 0.0f'. Other definitions would be variants like 'INFINITY * 0.0f', etc. I can't really claim that those are really more portable and the compiler may (and some do) complain about them. Hence why I went with the wine/port.h definitions in the end. If they're good enough for port.h they should be good for math.h too.
include/msvcrt/math.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/include/msvcrt/math.h b/include/msvcrt/math.h index 34aa268..42d6bfe 100644 --- a/include/msvcrt/math.h +++ b/include/msvcrt/math.h @@ -146,6 +146,26 @@ static const union { # endif #endif
+#ifndef INFINITY +/* From wine/port.h */ +static inline float __port_infinity(void) +{
- static const unsigned __inf_bytes = 0x7f800000;
- return *(const float *)&__inf_bytes;
+} +#define INFINITY __port_infinity() +#endif
+#ifndef NAN +/* From wine/port.h */ +static inline float __port_nan(void) +{
- static const unsigned __nan_bytes = 0x7fc00000;
- return *(const float *)&__nan_bytes;
+} +#define NAN __port_nan() +#endif
#ifdef __cplusplus } #endif
In wine/port.h, we implement worst-case scenario where math.h doesn't define NAN/INFINITY. In this case, since glibc/system math.h won't be used and our msvcrt math.h will be included instead, we should try to provide better NAN/INFINITY versions when possible. Looking at how it's done in my Linux headers, there is __builtin_nanf() and __builtin_inff() guarded by GCC >= 3.3 that we could use. How is it defined on MSVC?
Jacek