J
Jonathan Burd
Sethalicious said:I'm thinking that your getting a silent error on the code. I don't
believe an integer can handle the value 1000000000 in the following:
So what's happening is your integer "i" is overflowing and getting set
to an unpredictable value (possibly negative). You might have better
luck using an "unsigned long" or even "std::size_t".
I'm not sure what the standard says, but I think most compilers
implement 32 bit integers. So an "unsigned" int is 0 - 2^32, and the
"signed" int is -2^16 to 2^16. (Subtract or add a 1 where needed).
Check your compiler's docs to see the sizes of the integral data types.
Otherwise, there should be no real difference in performance of the
code with optimizations on. When you measure the time, remember to
record cpu clock cycles instead of time in seconds.
Hope this helps!
Chris J. (aka Sethalicious)
Duplicate posts? Get Thunderbird and subscribe to this newsgroup
using a decent NG server (news.individual.net is good.)
Secondly, please keep C in c.l.c and C++ in c.l.c++.
A bit can have one of two states (values). A total of 2^1 states.
Range: 0 to 2^1-1.
An octet byte has 8 bits, each bit of which can have one of two
states. A total of 2^8 states. Unsigned Range: 0 to 2^8-1.
Signed range: -2^7 to (2^7-1).
32-bit number:
Unsigned Range: 0 to 2^32-1
Signed range: -2^31 to (2^31-1)
Total numbers: 2^32
% grep "INT_MAX" /mingw/include/limits.h
#define INT_MAX 2147483647
#define INT_MIN (-INT_MAX-1)
#define UINT_MAX 0xffffffff
1000000000
<
2147483647
Regards,
Jonathan.