|
-
June 5th, 2009, 02:33 AM
#9
Re: Initializing a double to INT_MAX + 1
 Originally Posted by Speedo
If you don't do the cast (either implicitly or explicitly), INT_MAX + 1 is going to overflow and become INT_MIN.... which is definitely not what you want. 
Very true. Actually, I will use UINT_MAX, and if I don't cast I will get 0
 Originally Posted by Lindley
To a certain extent, you're screwed anyway at that point. The double only has 52 bits of mantissa; once you're dealing with values larger than 2^52, a double can't be accurate to the 1s place anyway.
While it's certainly true that adding small numbers to big ones in floating point is a bad idea, in this *particular* case I'm not sure it's worth worrying about.
Not 100% true. Technically, and double can give the EXACT value of numbers like 2^300, which is exactly what I'm trying to do. However, I get your point.
The way I see it, If my ints are 32 bits, then the double will have enough bits for exact representation.
If my ints are 64 bits, then I'm pretty sure that the +1 will do nothing to the double, but that is okay, because UINT_MAX will be rounded off to UINT_MAX+1 (wich is 2^64), giving me exact values anyways.
Thankyou everyone for your input, I think I found my solution.
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
|