Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

+infinity constant

marmotte
Beginner
634 Views
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_.
0 Kudos
6 Replies
TimP
Black Belt
634 Views
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.
0 Kudos
Anna_N_
Beginner
634 Views
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
0 Kudos
cp_jain
Beginner
634 Views
>> 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
0 Kudos
drMikeT
New Contributor I
634 Views
I have the same problem (with icc 11.1) but as I can see noone has answered this question since 2003?

-michael
0 Kudos
tydeman
Beginner
634 Views
You could try
#define INFINITY 9.9e99999f

That avoids the divide by zero exception.
0 Kudos
Dale_S_Intel
Employee
634 Views
It looks like you can use__builtin_inf() on Mac or Linux, cf.http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
Dale
0 Kudos
Reply