Solar wrote:1) A debugging rule: Subfunctions should always be tested out of context. Yes, you want to use your pfact() function in a cards context, but to test its mathematical correctness you should put it through a full boundary test (0, 1, 2, ULLONG_MAX, those kind of numbers), instead of throwing "real life" values (52) at it.
I have testet the function again and again, however not untill in should exceed 64 bit and fail.
Solar wrote:2) Taking your code verbatim, I do not see any difference between the cout and the printf output.
exactly! Never the less the result the cout and printf prints is different and basicly it look like printf just treats the %llu as 32 bit.
Solar wrote:3) Another debugging rule: Always state expected behaviour and actual behaviour, preferably by copy&pasting output. "Fails after 11 iterations" is a bit inprecise. You mean that the numbers get smaller, or does your code actually fail?
I mean that the result becomes incorrect and to me it might as well fail, but i see your point.
Solar wrote:4) "where the border is between less that 32 bit and more that 32 bits" - ?
Between 2^32-1 and 2^32
Solar wrote:5) "And finaly i have been unable to make the printf prinout in one line" - you probably mean printf( "%llu -> %llu\n", n, pfact( n, 52 ) / pfact( n, n ) );
yes but it doesnt work, the second value just prints zero.
Solar wrote:That being said, your pfact() looks good. It misbehaves if i == 0 or i > n, but other than that I can't see a problem.
i am aware the it is possible to use the functon wrong.
Solar wrote:You might want to add the following line to main():
Code: Select all
std::cout << "ull is " << sizeof( unsigned long long ) * 8 << " bits." << std::endl;
Regarding item 2) above, I tested this on a 64bit machine.
I have done the sizeof() again and again and again, that just isnt the problem.
I have allso tested it on a 64 bit machine, however running 32bit windows so...
this is the output i get:
Code: Select all
1 -> 52
1 -> 52
2 -> 1326
2 -> 1326
3 -> 22100
3 -> 22100
4 -> 270725
4 -> 270725
5 -> 2598960
5 -> 2598960
6 -> 20358520
6 -> 20358520
7 -> 133784560
7 -> 133784560
8 -> 752538150
8 -> 752538150
9 -> 3679075400
9 -> 3679075400
10 -> 15820024220
10 -> 2935122332
11 -> 60403728840
11 -> 274186696
12 -> 13825310247
12 -> 940408359
13 -> 1066226105
13 -> 1066226105
14 -> 7830577
14 -> 7830577
15 -> 5730934
15 -> 5730934
16 -> 27917
16 -> 27917
17 -> 7256
17 -> 7256
18 -> 2584
18 -> 2584
19 -> 75
19 -> 75
20 -> 3
20 -> 3
21 -> 0
21 -> 0
22 -> 0
22 -> 0
23 -> 0
23 -> 0
24 -> 1
24 -> 1
25 -> 1
25 -> 1
26 -> 0
26 -> 0
27 -> 0
27 -> 0
28 -> 0
28 -> 0
29 -> 0
29 -> 0
30 -> 1
30 -> 1
31 -> 3
31 -> 3
32 -> 1
32 -> 1
33 -> 4
33 -> 4
34 -> 1
34 -> 1
35 -> 2
35 -> 2
36 -> 0
36 -> 0
37 -> 3
37 -> 3
38 -> 1
38 -> 1
39 -> 7
39 -> 7
40 -> 0
40 -> 0
41 -> 0
41 -> 0
42 -> 1
42 -> 1
43 -> 1
43 -> 1
44 -> 3
44 -> 3
45 -> 0
45 -> 0
46 -> 9
46 -> 9
47 -> 0
47 -> 0
48 -> 0
48 -> 0
49 -> 1
49 -> 1
50 -> 0
50 -> 0
51 -> 0
51 -> 0
52 -> 1
52 -> 1
as for the expected output, it is some pretty large numbers.