[glib/vs2012-2-68: 1/4] option-context.c: Define NAN if not defined on MSVC
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/vs2012-2-68: 1/4] option-context.c: Define NAN if not defined on MSVC
- Date: Wed, 31 Mar 2021 13:49:51 +0000 (UTC)
commit 20bd716d4cf1679a02f82570685ca23d3050212c
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 1c588d742..13d3ffc76 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]