-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c95e45
commit 930073a
Showing
8 changed files
with
524 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/// | ||
/// @file pi_cache.cpp | ||
/// @brief Test the pi_cache(x) function. | ||
/// | ||
/// Copyright (C) 2023 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
/// | ||
|
||
#include <primecount-internal.hpp> | ||
|
||
#include <stdint.h> | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include <vector> | ||
|
||
using namespace primecount; | ||
|
||
std::vector<int64_t> pix = | ||
{ | ||
0, 0, 1, 2, 2, 3, 3, 4, 4, 4, | ||
4, 5, 5, 6, 6, 6, 6, 7, 7, 8, | ||
8, 8, 8, 9, 9, 9, 9, 9, 9, 10, | ||
10, 11, 11, 11, 11, 11, 11, 12, 12, 12, | ||
12, 13, 13, 14, 14, 14, 14, 15, 15, 15, | ||
15, 15, 15, 16, 16, 16, 16, 16, 16, 17, | ||
17, 18, 18, 18, 18, 18, 18, 19, 19, 19, | ||
19, 20, 20, 21, 21, 21, 21, 21, 21 | ||
}; | ||
|
||
void check(bool OK) | ||
{ | ||
std::cout << " " << (OK ? "OK" : "ERROR") << "\n"; | ||
if (!OK) | ||
std::exit(1); | ||
} | ||
|
||
int main() | ||
{ | ||
{ | ||
int64_t x = -1; | ||
int64_t res = pi_cache(x); | ||
std::cout << "pi_cache(" << x << ") = " << res; | ||
check(res == 0); | ||
} | ||
|
||
for (int64_t x = 0; x < (int64_t) pix.size(); x++) | ||
{ | ||
int64_t res = pi_cache(x); | ||
std::cout << "pi_cache(" << x << ") = " << res; | ||
check(res == pix[x]); | ||
} | ||
|
||
std::cout << std::endl; | ||
std::cout << "All tests passed successfully!" << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/// | ||
/// @file pi_deleglise_rivat.cpp | ||
/// @brief Test the pi_deleglise_rivat_64(x) function. | ||
/// | ||
/// Copyright (C) 2023 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
/// | ||
|
||
#include <primecount.hpp> | ||
#include <primecount-internal.hpp> | ||
|
||
#include <stdint.h> | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include <random> | ||
#include <vector> | ||
|
||
using namespace primecount; | ||
|
||
std::vector<int64_t> pix = | ||
{ | ||
0, 0, 1, 2, 2, 3, 3, 4, 4, 4, | ||
4, 5, 5, 6, 6, 6, 6, 7, 7, 8, | ||
8, 8, 8, 9, 9, 9, 9, 9, 9, 10, | ||
10, 11, 11, 11, 11, 11, 11, 12, 12, 12, | ||
12, 13, 13, 14, 14, 14, 14, 15, 15, 15, | ||
15, 15, 15, 16, 16, 16, 16, 16, 16, 17, | ||
17, 18, 18, 18, 18, 18, 18, 19, 19, 19, | ||
19, 20, 20, 21, 21, 21, 21, 21, 21 | ||
}; | ||
|
||
void check(bool OK) | ||
{ | ||
std::cout << " " << (OK ? "OK" : "ERROR") << "\n"; | ||
if (!OK) | ||
std::exit(1); | ||
} | ||
|
||
int main() | ||
{ | ||
int threads = get_num_threads(); | ||
|
||
{ | ||
int64_t x = -1; | ||
int64_t res = pi_deleglise_rivat_64(x, threads); | ||
std::cout << "pi_deleglise_rivat_64(" << x << ") = " << res; | ||
check(res == 0); | ||
} | ||
|
||
for (int64_t x = 0; x < (int64_t) pix.size(); x++) | ||
{ | ||
int64_t res = pi_deleglise_rivat_64(x, threads); | ||
std::cout << "pi_deleglise_rivat_64(" << x << ") = " << res; | ||
check(res == pix[x]); | ||
} | ||
|
||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<int64_t> dist(0, 1 << 28); | ||
|
||
for (int i = 0; i < 1000; i++) | ||
{ | ||
int64_t x = dist(gen); | ||
int64_t res1 = pi_deleglise_rivat_64(x, threads); | ||
int64_t res2 = pi_legendre(x, threads); | ||
std::cout << "pi_deleglise_rivat_64(" << x << ") = " << res1; | ||
check(res1 == res2); | ||
} | ||
|
||
std::cout << std::endl; | ||
std::cout << "All tests passed successfully!" << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/// | ||
/// @file pi_gourdon.cpp | ||
/// @brief Test the pi_gourdon_64(x) function. | ||
/// | ||
/// Copyright (C) 2023 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
/// | ||
|
||
#include <primecount.hpp> | ||
#include <primecount-internal.hpp> | ||
#include <gourdon.hpp> | ||
|
||
#include <stdint.h> | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include <random> | ||
#include <vector> | ||
|
||
using namespace primecount; | ||
|
||
std::vector<int64_t> pix = | ||
{ | ||
0, 0, 1, 2, 2, 3, 3, 4, 4, 4, | ||
4, 5, 5, 6, 6, 6, 6, 7, 7, 8, | ||
8, 8, 8, 9, 9, 9, 9, 9, 9, 10, | ||
10, 11, 11, 11, 11, 11, 11, 12, 12, 12, | ||
12, 13, 13, 14, 14, 14, 14, 15, 15, 15, | ||
15, 15, 15, 16, 16, 16, 16, 16, 16, 17, | ||
17, 18, 18, 18, 18, 18, 18, 19, 19, 19, | ||
19, 20, 20, 21, 21, 21, 21, 21, 21 | ||
}; | ||
|
||
void check(bool OK) | ||
{ | ||
std::cout << " " << (OK ? "OK" : "ERROR") << "\n"; | ||
if (!OK) | ||
std::exit(1); | ||
} | ||
|
||
int main() | ||
{ | ||
int threads = get_num_threads(); | ||
|
||
{ | ||
int64_t x = -1; | ||
int64_t res = pi_gourdon_64(x, threads); | ||
std::cout << "pi_gourdon_64(" << x << ") = " << res; | ||
check(res == 0); | ||
} | ||
|
||
for (int64_t x = 0; x < (int64_t) pix.size(); x++) | ||
{ | ||
int64_t res = pi_gourdon_64(x, threads); | ||
std::cout << "pi_gourdon_64(" << x << ") = " << res; | ||
check(res == pix[x]); | ||
} | ||
|
||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<int64_t> dist(0, 1 << 28); | ||
|
||
for (int i = 0; i < 1000; i++) | ||
{ | ||
int64_t x = dist(gen); | ||
int64_t res1 = pi_gourdon_64(x, threads); | ||
int64_t res2 = pi_legendre(x, threads); | ||
std::cout << "pi_gourdon_64(" << x << ") = " << res1; | ||
check(res1 == res2); | ||
} | ||
|
||
std::cout << std::endl; | ||
std::cout << "All tests passed successfully!" << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/// | ||
/// @file pi_legendre.cpp | ||
/// @brief Test the pi_legendre(x) function. | ||
/// | ||
/// Copyright (C) 2023 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
/// | ||
|
||
#include <primecount.hpp> | ||
#include <primecount-internal.hpp> | ||
#include <PiTable.hpp> | ||
|
||
#include <stdint.h> | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include <random> | ||
#include <vector> | ||
|
||
using namespace primecount; | ||
|
||
std::vector<int64_t> pix = | ||
{ | ||
0, 0, 1, 2, 2, 3, 3, 4, 4, 4, | ||
4, 5, 5, 6, 6, 6, 6, 7, 7, 8, | ||
8, 8, 8, 9, 9, 9, 9, 9, 9, 10, | ||
10, 11, 11, 11, 11, 11, 11, 12, 12, 12, | ||
12, 13, 13, 14, 14, 14, 14, 15, 15, 15, | ||
15, 15, 15, 16, 16, 16, 16, 16, 16, 17, | ||
17, 18, 18, 18, 18, 18, 18, 19, 19, 19, | ||
19, 20, 20, 21, 21, 21, 21, 21, 21 | ||
}; | ||
|
||
void check(bool OK) | ||
{ | ||
std::cout << " " << (OK ? "OK" : "ERROR") << "\n"; | ||
if (!OK) | ||
std::exit(1); | ||
} | ||
|
||
int main() | ||
{ | ||
int threads = get_num_threads(); | ||
|
||
{ | ||
int64_t x = -1; | ||
int64_t res = pi_legendre(x, threads); | ||
std::cout << "pi_legendre(" << x << ") = " << res; | ||
check(res == 0); | ||
} | ||
|
||
for (int64_t x = 0; x < (int64_t) pix.size(); x++) | ||
{ | ||
int64_t res = pi_legendre(x, threads); | ||
std::cout << "pi_legendre(" << x << ") = " << res; | ||
check(res == pix[x]); | ||
} | ||
|
||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<int64_t> dist(0, PiTable::max_cached()); | ||
|
||
for (int i = 0; i < 1000; i++) | ||
{ | ||
int64_t x = dist(gen); | ||
int64_t res1 = pi_legendre(x, threads); | ||
int64_t res2 = pi_cache(x); | ||
std::cout << "pi_legendre(" << x << ") = " << res1; | ||
check(res1 == res2); | ||
} | ||
|
||
std::cout << std::endl; | ||
std::cout << "All tests passed successfully!" << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/// | ||
/// @file pi_lmo5.cpp | ||
/// @brief Test the pi_lmo5(x) function. | ||
/// | ||
/// Copyright (C) 2023 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
/// | ||
|
||
#include <primecount.hpp> | ||
#include <primecount-internal.hpp> | ||
|
||
#include <stdint.h> | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include <random> | ||
#include <vector> | ||
|
||
using namespace primecount; | ||
|
||
std::vector<int64_t> pix = | ||
{ | ||
0, 0, 1, 2, 2, 3, 3, 4, 4, 4, | ||
4, 5, 5, 6, 6, 6, 6, 7, 7, 8, | ||
8, 8, 8, 9, 9, 9, 9, 9, 9, 10, | ||
10, 11, 11, 11, 11, 11, 11, 12, 12, 12, | ||
12, 13, 13, 14, 14, 14, 14, 15, 15, 15, | ||
15, 15, 15, 16, 16, 16, 16, 16, 16, 17, | ||
17, 18, 18, 18, 18, 18, 18, 19, 19, 19, | ||
19, 20, 20, 21, 21, 21, 21, 21, 21 | ||
}; | ||
|
||
void check(bool OK) | ||
{ | ||
std::cout << " " << (OK ? "OK" : "ERROR") << "\n"; | ||
if (!OK) | ||
std::exit(1); | ||
} | ||
|
||
int main() | ||
{ | ||
int threads = get_num_threads(); | ||
|
||
{ | ||
int64_t x = -1; | ||
int64_t res = pi_lmo5(x); | ||
std::cout << "pi_lmo5(" << x << ") = " << res; | ||
check(res == 0); | ||
} | ||
|
||
for (int64_t x = 0; x < (int64_t) pix.size(); x++) | ||
{ | ||
int64_t res = pi_lmo5(x); | ||
std::cout << "pi_lmo5(" << x << ") = " << res; | ||
check(res == pix[x]); | ||
} | ||
|
||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<int64_t> dist(0, 1 << 28); | ||
|
||
for (int i = 0; i < 1000; i++) | ||
{ | ||
int64_t x = dist(gen); | ||
int64_t res1 = pi_lmo5(x); | ||
int64_t res2 = pi_legendre(x, threads); | ||
std::cout << "pi_lmo5(" << x << ") = " << res1; | ||
check(res1 == res2); | ||
} | ||
|
||
std::cout << std::endl; | ||
std::cout << "All tests passed successfully!" << std::endl; | ||
|
||
return 0; | ||
} |
Oops, something went wrong.