Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created January 18, 2013 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/4567330 to your computer and use it in GitHub Desktop.
Save isaacs/4567330 to your computer and use it in GitHub Desktop.
commit 01a4be45542d6130b422991f035409d9a2d846ae
Author: isaacs <i@izs.me>
Date: Fri Jan 18 10:03:54 2013 -0800
buffer: Define INFINITY for MSVC compiler
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index f495247..ed26569 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -31,6 +31,30 @@
#include <float.h> // float limits
#include <math.h> // infinity
+// Windows does not define INFINITY in math.h
+// Copy V8's approach and use HUGE_VAL instead
+#ifndef INFINITY
+# ifdef HUGE_VALF
+# define INFINITY HUGE_VALF
+# else
+
+// MSVC. No INFINITY, no HUGE_VALF
+// There's HUGE_VAL, but that's a double, not a float.
+// Assign the bytes and float-ify it.
+
+typedef union { unsigned char __c[4]; float __f; } __huge_valf_t;
+# if __BYTE_ORDER == __BIG_ENDIAN
+# define __HUGE_VALF_bytes { 0x7f, 0x80, 0, 0 }
+# endif
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+# define __HUGE_VALF_bytes { 0, 0, 0x80, 0x7f }
+# endif
+static __huge_valf_t __huge_valf = { __HUGE_VALF_bytes };
+# define INFINITY (__huge_valf.__f)
+
+# endif
+#endif
+
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define BUFFER_CLASS_ID (0xBABE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment