+infinity constant

+infinity constant

I'm trying to define an IEEE floating-point constant whose value should be +infinity, but I'm getting errors from icc 7.0:

foo.c(3): error: floating-point operation result is out of range
  static const double totor=1.0/0.0;

The same code is accepted without a complaint by gcc.

C99 defines the constant INFINITY, but the definition from glibc is not accepted by icc:

foo.c(3): error: expression must have a constant value
  static const double totor=INFINITY;

My opinion is that icc should

1. (Re)define INFINITY in its if it cannot cope with the definition from glibc.

2. Accept 1.0/0.0 with a _warning_, not an _error_.

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The following is more likely to work on other C compilers (but doesn't with icc 7.0):
#include
static const double totor=DBL_MAX+DBL_MAX;

If you are simply trying to do a comparison to detect +infinity,
if(x > DBL_MAX)
might do the job.

Just short propositions. I can't test if they work, as I don't have ICC7 installed (yet, I'm going to buy one this week), and ICC6 trial works fine with just warning.
1)
static const double totor0 = (double)((long double)((long double)DBL_MAX + (long double)DBL_MAX));
2)
static const double totor1; // without initializer! must cause warning
*((__int64*)&totor1) = 0x7ff0000000000000;
3)
#include
using namespace std;
static const double totor2 = numeric_limits::infinity();

Please drop a line if any of them works.
Regards, Anna

>> 2. Accept 1.0/0.0 with a _warning_, not an _error_.

icpc (v7.0.86) accepts this definition with warning, icc gives error.

CP

I have the same problem (with icc 11.1) but as I can see noone has answered this question since 2003?

-michael

R/D High-Performance Computing and Engineering

You could try
#define INFINITY 9.9e99999f

That avoids the divide by zero exception.

It looks like you can use__builtin_inf() on Mac or Linux, cf.http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.htmlDale

Login to leave a comment.