From 01a4be45542d6130b422991f035409d9a2d846ae Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 18 Jan 2013 10:03:54 -0800 Subject: [PATCH] buffer: Define INFINITY for MSVC compiler --- src/node_buffer.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index f49524774cc..ed2656955ab 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -31,6 +31,30 @@ #include // float limits #include // 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)