Skip to content

Commit 01a4be4

Browse files
committed
buffer: Define INFINITY for MSVC compiler
1 parent 0459a60 commit 01a4be4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/node_buffer.cc

+24
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@
3131
#include <float.h> // float limits
3232
#include <math.h> // infinity
3333

34+
// Windows does not define INFINITY in math.h
35+
// Copy V8's approach and use HUGE_VAL instead
36+
#ifndef INFINITY
37+
# ifdef HUGE_VALF
38+
# define INFINITY HUGE_VALF
39+
# else
40+
41+
// MSVC. No INFINITY, no HUGE_VALF
42+
// There's HUGE_VAL, but that's a double, not a float.
43+
// Assign the bytes and float-ify it.
44+
45+
typedef union { unsigned char __c[4]; float __f; } __huge_valf_t;
46+
# if __BYTE_ORDER == __BIG_ENDIAN
47+
# define __HUGE_VALF_bytes { 0x7f, 0x80, 0, 0 }
48+
# endif
49+
# if __BYTE_ORDER == __LITTLE_ENDIAN
50+
# define __HUGE_VALF_bytes { 0, 0, 0x80, 0x7f }
51+
# endif
52+
static __huge_valf_t __huge_valf = { __HUGE_VALF_bytes };
53+
# define INFINITY (__huge_valf.__f)
54+
55+
# endif
56+
#endif
57+
3458
#define MIN(a,b) ((a) < (b) ? (a) : (b))
3559

3660
#define BUFFER_CLASS_ID (0xBABE)

0 commit comments

Comments
 (0)