|
-
June 4th, 2009, 08:26 AM
#1
Initializing a double to INT_MAX + 1
Hi,
I'd like to set a double's start value at the maximum possible value a int can hold, +1.
i.e., if the int is 32 bit long, I'd like to write:
Code:
double a = 0x100000000;
However, I get a compile error of "integer constant is too large for "long" type "
At best, I can write this:
Code:
double a = static_cast<double>(0xffffffff) + 1;
Also, since I'd like the code to be portable, using 0xffffffff doesn't really work, so I use this:
Code:
double b = static_cast<double>(static_cast<unsigned int>(-1)) + 1;
This not only doesn't look very clean, I'm pretty sure it's not even accurate if my long is 8 bytes. Also, I'd like my double to be evaluated at compile time, not run time.
Can anybody help?
I thought at worst, I can do something like:
Code:
double c = pow(2,8*sizeof(int));
But I'd like to avoid anything that excessive (plus it is probably not evaluated at compile time).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|