Skip to content

Commit

Permalink
Fix -ffast-math failure
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Mar 9, 2024
1 parent 92cbef1 commit 48d3bb8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changes in version 12.1, 09/03/2024

CMakeLists.txt: Fix undefined reference to pthread_create #146.
PrimeSieve.cpp: Improve status output.
src/app/test.cpp: Fix -ffast-math failure.
test/count_primes2.cpp: Fix -ffast-math failure.

Changes in version 12.0, 17/02/2024
Expand Down
32 changes: 19 additions & 13 deletions src/app/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// @file test.cpp
/// @brief primesieve self tests (option: --test).
///
/// Copyright (C) 2023 Kim Walisch, <[email protected]>
/// Copyright (C) 2024 Kim Walisch, <[email protected]>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -14,7 +14,6 @@

#include <stdint.h>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -54,14 +53,13 @@ void countSmallPrimes()
};

ParallelSieve ps;
ps.setStart(0);
ps.setStop(0);
uint64_t count = 0;
uint64_t stop = 1;

for (size_t i = 0; i < primePi.size(); i++)
{
uint64_t start = ps.getStop() + 1;
uint64_t stop = (uint64_t) std::pow(10.0, i + 1);
stop *= 10;
uint64_t start = stop / 10 + 1;
count += ps.countPrimes(start, stop);
std::ostringstream oss;
oss << "PrimePi(10^" << i + 1 << ") = " << count;
Expand All @@ -81,10 +79,11 @@ void countPrimeKTuplets()
66 // PrimePi6(10^16, 10^16+10^10)
};

uint64_t start = (uint64_t) 1e12;
size_t j = 12;

for (size_t i = 0; i < kTupletCounts.size(); i++)
{
size_t j = i + 12;
uint64_t start = (uint64_t) std::pow(10.0, j);
uint64_t stop = start + (uint64_t) 1e10;
int k = (int) (i + 2);
int countKTuplet = COUNT_PRIMES << (k - 1);
Expand All @@ -97,6 +96,9 @@ void countPrimeKTuplets()
oss << "PrimePi" << k << "(10^" << j << ", 10^" << j << "+10^10) = " << count;
std::cout << std::left << std::setw(39) << oss.str();
check(count == kTupletCounts[i]);

start *= 10;
j += 1;
}
}

Expand All @@ -112,14 +114,18 @@ void countLargePrimes()
255481287 // PrimePi(10^17, 10^17+10^10)
};

uint64_t start = (uint64_t) 1e12;
size_t j = 12;

for (size_t i = 0; i < primePi.size(); i++)
{
size_t j = i + 12;
uint64_t start = (uint64_t) std::pow(10.0, j);
uint64_t stop = start + (uint64_t) 1e10;
uint64_t count = count_primes(start, stop);
std::cout << "PrimePi(10^" << j << ", 10^" << j << "+10^10) = " << count;
check(count == primePi[i]);

start *= 10;
j += 1;
}
}

Expand Down Expand Up @@ -166,14 +172,14 @@ void smallNthPrimes()
};

ParallelSieve ps;
uint64_t n = 0;
uint64_t nthPrime = 0;
uint64_t n = 1;
uint64_t nthPrime = 2;

for (size_t i = 0; i < nthPrimes.size(); i++)
{
uint64_t oldN = n;
uint64_t oldNthPrime = nthPrime;
n = (uint64_t) std::pow(10.0, i + 1);
n *= 10;
nthPrime = ps.nthPrime(n - oldN, oldNthPrime);
std::ostringstream oss;
oss << "NthPrime(10^" << i + 1 << ") = " << nthPrime;
Expand Down

0 comments on commit 48d3bb8

Please sign in to comment.