Branch Coverage

prime_counts.c
Criterion Covered Total %
branch 272 344 79.0


line true false branch
72 21450 43985 if (nbytes >= 16) {
73 135769 21450 while ( word_unaligned(m,sizeof(UV)) && nbytes--)
135769 0 while ( word_unaligned(m,sizeof(UV)) && nbytes--)
75 21450 0 if (nbytes >= 8) {
81 282622 21450 while (nwords--)
87 284298 65435 while (nbytes--)
106 0 47 MPUassert(sieve != 0, "count_segment_maxcount incorrect args");
107 0 47 MPUassert(pos != 0, "count_segment_maxcount incorrect args");
109 47 0 if ( (nbytes == 0) || (maxcount == 0) )
0 47 if ( (nbytes == 0) || (maxcount == 0) )
113 158 47 while ((count+64) < maxcount && sieveptr < maxsieve) {
158 0 while ((count+64) < maxcount && sieveptr < maxsieve) {
115 102 56 UV div = (top < 8000) ? 8 : /* 8 cannot overcount */
17 85 UV div = (top < 8000) ? 8 : /* 8 cannot overcount */
6 11 UV div = (top < 8000) ? 8 : /* 8 cannot overcount */
119 0 158 if (minbytes > (UV)(maxsieve-sieveptr)) minbytes = maxsieve-sieveptr;
124 750 0 while ( (sieveptr < maxsieve) && (count < maxcount) )
703 47 while ( (sieveptr < maxsieve) && (count < maxcount) )
127 47 47 while (count >= maxcount)
132 0 47 MPUassert(count < maxcount, "count_segment_maxcount wrong count");
134 0 47 if (byte == nbytes)
138 506 0 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, byte*30+1, nbytes*30-1)
0 506 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, byte*30+1, nbytes*30-1)
103 403 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, byte*30+1, nbytes*30-1)
506 0 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, byte*30+1, nbytes*30-1)
47 0 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, byte*30+1, nbytes*30-1)
139 47 56 if (++count == maxcount) { *pos = p; return count; }
153 0 80207 MPUassert( sieve != 0, "count_segment_ranged incorrect args");
154 0 80207 if (nbytes == 0) return 0;
159 0 80207 if (hi_d >= nbytes) {
164 0 80207 if (highp < lowp)
178 77569 2638 if (lo_m > 1) {
180 593888 0 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, upper)
77434 516454 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, upper)
502313 14141 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, upper)
593888 135 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, upper)
77569 77569 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, upper)
186 9377 70830 if (highp < lowp)
193 65277 5553 if (count_bytes > 0) {
198 4638 66192 if (highp < lowp)
202 1441801 0 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, highp)
65841 1375960 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, highp)
170140 1205820 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, highp)
1441801 351 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, highp)
66192 66192 START_DO_FOR_EACH_SIEVE_PRIME(sieve, 0, lowp, highp)
255 94184 1293 if ((low <= 2) && (high >= 2)) count++;
94077 107 if ((low <= 2) && (high >= 2)) count++;
256 94186 1291 if ((low <= 3) && (high >= 3)) count++;
85795 8391 if ((low <= 3) && (high >= 3)) count++;
257 94188 1289 if ((low <= 5) && (high >= 5)) count++;
80985 13203 if ((low <= 5) && (high >= 5)) count++;
258 94188 1289 if (low < 7) low = 7;
260 15270 80207 if (low > high) return count;
263 78919 1288 if (low == 7 && high <= 30*NPRIME_SIEVE30) {
76353 2566 if (low == 7 && high <= 30*NPRIME_SIEVE30) {
274 2566 1288 APPLY_TABLES
2566 0 APPLY_TABLES
1400 1166 APPLY_TABLES
16743 1400 APPLY_TABLES
16743 0 APPLY_TABLES
322 844 APPLY_TABLES
63177 322 APPLY_TABLES
63177 0 APPLY_TABLES
366 478 APPLY_TABLES
136339 366 APPLY_TABLES
136339 0 APPLY_TABLES
244 234 APPLY_TABLES
92777 244 APPLY_TABLES
92777 0 APPLY_TABLES
234 0 APPLY_TABLES
96970 234 APPLY_TABLES
96970 0 APPLY_TABLES
0 0 APPLY_TABLES
0 0 APPLY_TABLES
0 0 APPLY_TABLES
0 0 APPLY_TABLES
0 0 APPLY_TABLES
283 285 3569 if (segment_size < high_d) {
285 285 0 UV endp = (high_d >= (UV_MAX/30)) ? UV_MAX-2 : 30*high_d+29;
287 2 283 if (newsize > 2642245) newsize = 2642245; /* Limit to icbrt(2^64) */
292 3854 0 if ( (segment_size > 0) && (low_d <= segment_size) ) {
3569 285 if ( (segment_size > 0) && (low_d <= segment_size) ) {
296 3569 0 if (high_d < segment_size) {
302 0 0 if (30*low_d > low) low = 30*low_d;
310 285 285 while (next_segment_primes(ctx, &seg_base, &seg_low, &seg_high)) {
322 150 0 if (lo > hi || hi < 2)
8 142 if (lo > hi || hi < 2)
330 125 17 if (hi < _MPU_LMO_CROSSOVER) return segment_prime_count(lo, hi);
334 12 5 if ( (hi-lo+1) < range_threshold )
337 0 5 return LMO_prime_count(hi) - ((lo < 2) ? 0 : LMO_prime_count(lo-1));
342 0 69634 if (n < 2) return 0;
345 68852 782 if (n < _MPU_LMO_CROSSOVER) return segment_prime_count(0, n);
352 9409 214 if (n < 3000000) return segment_prime_count(2, n);
361 6603 413 if (n < 33000) return segment_prime_count(2, n);
370 263 150 if (n <= 300070) { /* Quite accurate and avoids calling Li for speed. */
372 192 71 a = (n < 69720) ? 905 :
192 0 a = (n < 69720) ? 905 :
164 28 a = (n < 69720) ? 905 :
12 152 a = (n < 69720) ? 905 :
12 0 a = (n < 69720) ? 905 :
379 130 20 } else if (n < UVCONST(4000000000)) {
382 130 0 : (n < 300000) ? -3.0L
383 130 0 : (n < 303000) ? 5.0L
384 130 0 : (n < 1100000) ? -7.0L
385 118 12 : (n < 4500000) ? -37.0L
386 107 11 : (n < 10200000) ? -70.0L
387 92 15 : (n < 36900000) ? -53.0L
388 67 25 : (n < 38100000) ? -29.0L
389 0 67 : -84.0L;
391 18 2 } else if (fn < 1e19) { /* Büthe 2015 1.9 1511.02032v1.pdf */
434 6640 815 if (n < 33000) return segment_prime_count(2, n);
448 770 45 if (BITS_PER_WORD == 32 || fn <= 821800000.0) { /* Dusart 2010, page 2 */
449 3493 0 for (i = 0; i < (int)NUPPER_THRESH; i++)
450 770 2723 if (n < _upper_thresh[i].thresh)
452 770 0 a = (i < (int)NUPPER_THRESH) ? _upper_thresh[i].aval : 2.334L;
454 43 2 } else if (fn < 1e19) { /* Büthe 2015 1.10 Skewes number lower limit */
456 24 19 : (fn < 10010000000.0) ? 0.027 /* Empirical */
4 15 : (fn < 10010000000.0) ? 0.027 /* Empirical */
2 13 : (fn < 10010000000.0) ? 0.027 /* Empirical */
467 486 137 const long double a = (n < 228) ? .6483 : (n < 948) ? .8032 : (n < 2195) ? .8800 : (n < 39017) ? .9019 : .9484;
28 109 const long double a = (n < 228) ? .6483 : (n < 948) ? .8032 : (n < 2195) ? .8800 : (n < 39017) ? .9019 : .9484;
32 77 const long double a = (n < 228) ? .6483 : (n < 948) ? .8032 : (n < 2195) ? .8800 : (n < 39017) ? .9019 : .9484;
44 33 const long double a = (n < 228) ? .6483 : (n < 948) ? .8032 : (n < 2195) ? .8800 : (n < 39017) ? .9019 : .9484;
470 0 623 if (*hi < *lo) *hi = MPU_MAX_PRIME;
478 211 419 if (n < NPRIMES_SMALL)
480 1 418 if (n >= MPU_MAX_PRIME_IDX)
481 1 0 return n == MPU_MAX_PRIME_IDX ? MPU_MAX_PRIME : 0;
488 306 112 if (n < 15360) {
491 1971 306 while (lo < hi) {
493 1014 957 if (prime_count_lower(mid) < n) lo = mid+1;
502 18 94 if (n >= 46254381) { c = 2.00; d = 10.667; } /* Axler 2017 Cor 1.2 */
503 18 76 else if (n >= 8009824) { c = 2.00; d = 10.273; } /* Axler 2013 Kor G */
510 12 64 else if (n >= 5450000) { c = 2.00; d = 10.1335; } /*5450-8009 */
511 3 61 else if (n >= 3906280) { c = 1.67; d = 20.2675; } /*3906-5450 */
512 5 56 else if (n >= 2110840) { c = 2.51; d = -5.5714; } /*2110-3906 */
513 7 49 else if (n >= 876700) { c = 2.49; d = -4.5129; } /* 877-2110 */
514 5 44 else if (n >= 688382) { c = 3.31; d = -26.3858; } /* 688-877 */
516 0 44 else if (n >= 575750) { c =-0.79; d = 83.5215; } /* 580-688 */
517 0 44 else if (n >= 467650) { c = 0.93; d = 37.1597; } /* 467-580 */
518 4 40 else if (n >= 382440) { c = 2.92; d = -15.4768; } /* 382-467 */
519 1 39 else if (n >= 301130) { c = 5.92; d = -91.3415; } /* 301-382 */
520 3 36 else if (n >= 138630) { c = 2.01; d = 7.2842; } /* 138-301 */
521 13 23 else if (n >= 85820) { c = 2.07; d = 5.2103; } /* 86-138 */
522 17 6 else if (n >= 39016) { c = 2.76; d = -11.5918; } /* 39- 86 */
523 0 6 else if (n >= 31490) { c = 1.49; d = 15.1821; } /* 31- 39 */
524 1 5 else if (n >= 25070) { c =11.89; d =-197.8951; } /* 25- 31 */
525 5 0 else if (n >= 15359) { c = 4.80; d = -51.5928; } /* 15- 25 */
531 0 112 if (upper >= (long double)UV_MAX) {
532 0 0 if (n <= MPU_MAX_PRIME_IDX) return MPU_MAX_PRIME;
545 139 369 if (n < NPRIMES_SMALL)
547 2 367 if (n >= MPU_MAX_PRIME_IDX)
548 2 0 return n == MPU_MAX_PRIME_IDX ? MPU_MAX_PRIME : 0;
555 317 50 if (n < 2000000) {
558 2214 317 while (lo < hi) {
560 1040 1174 if (prime_count_upper(mid) < n) lo = mid+1;
567 40 10 double b1 = (n < 56000000) ? 11.200 : 11.50800000002;
576 3 23 return (n < NPRIMES_SMALL) ? primes_small[n] : inverse_R(n);
587 174 48 if (n < NPRIMES_SMALL)
589 0 48 if (n >= MPU_MAX_PRIME_IDX)
590 0 0 return n == MPU_MAX_PRIME_IDX ? MPU_MAX_PRIME : 0;
594 0 48 MPUassert(upper_limit > 0, "nth_prime got an upper limit of 0");
603 18 30 if (upper_limit <= get_prime_cache(0, 0) || upper_limit <= 32*1024*30) {
1 17 if (upper_limit <= get_prime_cache(0, 0) || upper_limit <= 32*1024*30) {
607 31 0 if (segment_size > 0)
628 1 16 if (count >= n) { /* Too far. Walk backwards */
629 0 1 if (is_prime(lower_limit)) count--;
630 1 1 for (p = 0; p <= (count-n); p++)
640 31 16 if (count == target)
647 16 16 while (count < target) {
649 15 1 if ( (30*(segbase+segment_size)+29) > upper_limit )
658 0 16 if (count < target)
662 0 16 MPUassert(count == target, "nth_prime got incorrect count");