   floating-point infinity in C with MSVC2k5?
  Erggh.. yeah, I'm having a problem with this.There doesn't seem to be a way to set a float to infinity in C with MSVC2k5. INFINITY and HUGE_VALF aren't defined, and (1.0f / 0.0f) refuses to compile. I'd prefer to do this in a standard and portable manner, but it seems bit hacks are going to be my only option.Any ideas?   
  float temp = 1.0;float infinity = temp / (temp - 1.0);   ;  Thanks, that works.Is that really the only way? It seems pretty hackish.EDIT: It looks like there are a number of other solutions, such as -logf(0.0f) and powf(0.0f, -1.0f), but nothing that isn't run-time.[Edited by - Ra on December 11, 2005 9:44:56 AM];  You could simply define a const variable within your program, and then use that const to initialize a varible. That way, it will be setup at compile time.Edit: Nevermind, didn't see that big bold C.   ;  Can't you use FLT_MAX ?;Quote:Original post by Anonymous PosterCan't you use FLT_MAX ?No, why could you?CM   ;  I think the best way to do it would be to make a "VC_FIXES.h" or something like that, and then do something similar to:#if /*Check for MSVC*/ union MSVC_EVIL_FLOAT_HACK{   unsigned __int8 Bytes[4];   float Value;};static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};#define INFINITY (INFINITY_HACK.Value)#endifOf course, it's very ugly, but it's the only compile time solution I can think of (and I have only tested it on 2003, so I'm not sure it works on 2005).If 2005 supports C99s compound literals, you could change the #define to:#define INFINITY (((union MSVC_EVIL_FLOAT_HACK)({{0x00, 0x00, 0x80, 0x7F}})).Value)But if it's missing INFINITY, I doubt it does.   ;#include <float.h>#ifndef INFINITY    #define INFINITY FLT_MAX#endifCould you do this as a "nearly there" solution?   ;Quote:Original post by playmesumch00ns *** Source Snippet Removed ***Could you do this as a "nearly there" solution?You're the second person to suggest this.  No, of course not.  FLT_MAX is not INFINITY, and does not share any of its more important properties.  In particular, FLT_MAX does not preserve its value over later operations, and it does not equal actual infinity as defined by the floating point format.CM   ;Quote:Original post by RaThere doesn't seem to be a way to set a float to infinity in C with MSVC2k5.If you're willing to increment to C++, you can just use the standard numeric limits.#include <limits>float val = std::numeric_limits<float>::infinity();There is, of course, a serious difference between infinity and NaN, which is what many of the proposed solutions will give you.--smw   