I'm attempting to compile a code base originally intended for Linux / Unix platforms under Windows. The code uses the HUGE_VALF variable seemingly without reference to a header that would define it. The MS VC9 compiler I'm using on Windows throws:
error C2065: 'HUGE_VALF' : undeclared identifier.
What is the recommended include file or way to define HUGE_VALF for Window开发者_运维问答s? Math.h defines HUGE_VAL (the double), but not HUGE_VALF (as a float).
How about just replacing HUGE_VAL
* with *_MAX
like so:
HUGE_VAL => DOUBLE_MAX
HUGE_VALF => FLOAT_MAX
etc...
You could either define these for _WIN32
only, or just replace the HUGE_VAL
* stuff with the proper, standard replacement.
EDIT: MinGW-w64 (GCC) has these defines, probably they are C99 or C++0x things not (yet) in MSVC9. Maybe MSVC10 has them, though msdn seems to miss any information about the defines.
Most implementations define HUGE_VALF
to be +Infinity
, but it is really only required to be a "large positive value". A reasonable implementation:
#if defined(_WIN32) && !defined(HUGE_VALF)
# if defined(__cplusplus)
static float _X_huge_valf = std::numeric_limits<float>::infinity();
# define HUGE_VALF _X_huge_valf
# else
/* assumes Windows on a LE IEEE754 platform */
static union { unsigned int x; float y; } _X_huge_valf = { 0x7f800000 };
# define HUGE_VALF (_X_huge_valf.y)
# endif /* __cplusplus */
#endif /* defined(WIN32) && !defined(HUGE_VALF) */
(You'll find lots of other oddities like this so I suggest you create a shim header for VC specific problems.)
精彩评论