Skip to main content
gamedev.net
🔒 Locked

Float / Double infinity

Started by Kurioes Jun 26, 2004 at 8:06 AM 1 replies 950+ views
Original Post
Kurioes
Kurioes
Are there any float / double constants for +/- infinity in C++? I haven't found anything useful using google. The only thing I found was IEEE 754 (floating-point standard); It seems 1.0 / 0.0 is defined. The only problem is that when I try declaring a const float as 1.0 / 0.0 (i.e. const float inf = 1.0 / 0.0;) MSVC++ complains about a division by zero, whereas the following code does produce the required results;

float one = 1.0;
float zero = 0.0;
float infy = one / zero;
printf("%f\n", infy);
// prints "1.#INF00"
I need infinite values; I need to compare against them. There's really no way around this unless you'd call flagging certain stuff with bools a way around; this piece of code needs to be fast. So.. any ideas? Have I missed something while googling? There must be constants for this...
Fruny
Fruny
#include <limits>float inf_f = std::numeric_limits<float>::infinity();double inf_d = std::numeric_limits<double>::infinity();

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.