[glib/main-c89: 1/5] option-context.c: Define NAN if not defined on MSVC




commit e6afb886942ff54ca2743727c7e14c5e86721539
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Mar 31 16:52:18 2021 +0800

    option-context.c: Define NAN if not defined on MSVC
    
    This will enable the build to succeed on older Visual Studio versions
    that don't support NAN yet.  Other supported compilers should support
    this.

 glib/tests/option-context.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/glib/tests/option-context.c b/glib/tests/option-context.c
index d4ed3a94f..bb4b49f97 100644
--- a/glib/tests/option-context.c
+++ b/glib/tests/option-context.c
@@ -28,6 +28,24 @@
 #include <locale.h>
 #include <math.h>
 
+#ifdef _MSC_VER
+# ifndef NAN
+/*
+ * From the Visual Studio 2013+ math.h, we have the following:
+ * #ifndef _HUGE_ENUF
+ *    #define _HUGE_ENUF  1e+300  // _HUGE_ENUF*_HUGE_ENUF must overflow
+ * #endif
+ *
+ * #define INFINITY   ((float)(_HUGE_ENUF * _HUGE_ENUF))
+ * ...
+ * #define NAN        ((float)(INFINITY * 0.0F))
+ * ...
+ * so, HUVE_VAL * HUGE_VAL would be a good approximation of INFINITY without
+ * defining anything extra
+ */
+#  define NAN HUGE_VAL * HUGE_VAL * 0.0f
+# endif
+#endif
 
 static GOptionEntry main_entries[] = {
   { "main-switch", 0, 0,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]