INFINITY and NAN with Microsoft Visual Studio 2010 (solution provided)

The file src/h/internal.h contains definitions of INFINITY and NAN (lines 598 and 602 respectively, as of 5f0beddf) .

Microsoft Visual Studio 2010 (_MSC_VER 1600) fails on division by zero when compiling the file src/c/number.d that uses the definition of NAN mentioned above, on line 926 (the compiler reports the next line number).

I propose to replace the current definion of INFINITY as follows:

#ifndef INFINITY
#if _MSC_VER == 1600
union {
	uint8_t bytes [ sizeof ( float ) ];
	float inf;
} __ecl_inf = {
	{ 0, 0, 0xf0, 0x7f }
};
#define INFINITY (__ecl_inf.inf)
#else
# define INFINITY (1.0/0.0)
#endif
#endif

I propose to replace the current definion of NAN as follows:

#ifndef NAN
#if _MSC_VER == 1600
union {
	uint8_t bytes [ sizeof ( float ) ];
	float nan;
} __ecl_nan = {
	{ 0, 0, 0xc0, 0x7f }
};
#define NAN (__ecl_nan.nan)
#else
# define NAN (0.0/0.0)
#endif
#endif

The proposed modifications work only on little-endian architectures because supporting Microsoft Visual Studio on big-endian platforms does not seem to be an issue. Please note, the use of unions is critical: it prevents the compiler from generating calls to type casting functions (the solution will not work).

Later versions of Microsoft Visual Studio seem to define both INFINITY and NAN (I did not check it explicitly but ECL builds without modifications).

Assignee Loading
Time tracking Loading