With GCC you can also use the GCC built-ins:
Code:
static const double negative_infinityd = -__builtin_inf();
static const float negative_infinityf = -__builtin_inff();
This will also generate a warning if the current architecture or compiler options do not support 'infinity'.
If you need a fallback, you can use -HUGE_VAL (for doubles) or -HUGE_VALF (for floats) defined in math.h for the smallest possible finite negative value instead. If using GCC, you can also fetch them using the built-ins
Code:
#ifndef HUGE_VAL
#define HUGE_VAL __builtin_huge_val()
#endif
#ifndef HUGE_VALF
#define HUGE_VALF __builtin_huge_valf()
#endif
For portable code (and when writing highly optimized timing-sensitive code, telling the compiler to relax the IEEE floating-point rules), you can use -HUGE_VAL and HUGE_VAL as sentinels, as long as you make sure all data is within the range (-HUGE_VAL < data && data < HUGE_VAL), when reading or generating the values. That way you also know all your data is finite.