- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to define an IEEE floating-point constant whose value should be +infinity, but I'm getting errors from icc 7.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:
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_.
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
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
2. Accept 1.0/0.0 with a _warning_, not an _error_.
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
#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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Please drop a line if any of them works.
Regards, Anna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>> 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
icpc (v7.0.86) accepts this definition with warning, icc gives error.
CP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have the same problem (with icc 11.1) but as I can see noone has answered this question since 2003?
-michael
-michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could try
#define INFINITY 9.9e99999f
That avoids the divide by zero exception.
#define INFINITY 9.9e99999f
That avoids the divide by zero exception.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It looks like you can use__builtin_inf() on Mac or Linux, cf.http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
Dale

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page