msvcrt: Add INFINITY and NAN definitions to math.h.

Francois Gouget fgouget at free.fr
Fri Jan 10 08:29:42 CST 2014


---

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
-- 
1.8.5.2




More information about the wine-patches mailing list