Skip to content

Commit 609c48c

Browse files
committed
Another tweak.
1 parent 59f4535 commit 609c48c

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

tests/exhaustive32_midpoint.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@
44
#include <cassert>
55
#include <cmath>
66

7+
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
8+
// Anything at all that is related to cygwin, msys and so forth will
9+
// always use this fallback because we cannot rely on it behaving as normal
10+
// gcc.
11+
#include <locale>
12+
#include <sstream>
13+
// workaround for CYGWIN
14+
double cygwin_strtod_l(const char* start, char** end) {
15+
double d;
16+
std::stringstream ss;
17+
ss.imbue(std::locale::classic());
18+
ss << start;
19+
ss >> d;
20+
size_t nread = ss.tellg();
21+
*end = const_cast<char*>(start) + nread;
22+
return d;
23+
}
24+
#endif
25+
726
template <typename T> char *to_string(T d, char *buffer) {
827
auto written = std::snprintf(buffer, 64, "%.*e",
928
std::numeric_limits<T>::max_digits10 - 1, d);
@@ -12,7 +31,9 @@ template <typename T> char *to_string(T d, char *buffer) {
1231

1332
void strtod_from_string(const char * st, float& d) {
1433
char *pr = (char *)st;
15-
#ifdef _WIN32
34+
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
35+
d = cygwin_strtod_l(st, &pr, c_locale);
36+
#elif defined(_WIN32)
1637
static _locale_t c_locale = _create_locale(LC_ALL, "C");
1738
d = _strtof_l(st, &pr, c_locale);
1839
#else
@@ -73,6 +94,9 @@ void allvalues() {
7394
}
7495

7596
int main() {
97+
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
98+
std::cout << "Warning: msys/cygwin detected. This particular test is likely to generate false failures due to our reliance on the underlying runtime library." << std::endl;
99+
#endif
76100
allvalues();
77101
std::cout << std::endl;
78102
std::cout << "all ok" << std::endl;

tests/random_string.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
#include <cstdint>
33
#include <random>
44

5+
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
6+
// Anything at all that is related to cygwin, msys and so forth will
7+
// always use this fallback because we cannot rely on it behaving as normal
8+
// gcc.
9+
#include <locale>
10+
#include <sstream>
11+
// workaround for CYGWIN
12+
double cygwin_strtod_l(const char* start, char** end) {
13+
double d;
14+
std::stringstream ss;
15+
ss.imbue(std::locale::classic());
16+
ss << start;
17+
ss >> d;
18+
size_t nread = ss.tellg();
19+
*end = const_cast<char*>(start) + nread;
20+
return d;
21+
}
22+
#endif
23+
524
class RandomEngine {
625
public:
726
RandomEngine() = delete;
@@ -103,7 +122,9 @@ std::pair<double, bool> strtod_from_string(char *st) {
103122
std::pair<float, bool> strtof_from_string(char *st) {
104123
float d;
105124
char *pr;
106-
#ifdef _WIN32
125+
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
126+
d = cygwin_strtod_l(st, &pr, c_locale);
127+
#elif defined(_WIN32)
107128
static _locale_t c_locale = _create_locale(LC_ALL, "C");
108129
d = _strtof_l(st, &pr, c_locale);
109130
#else
@@ -178,6 +199,9 @@ bool tester(int seed, size_t volume) {
178199
}
179200

180201
int main() {
202+
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
203+
std::cout << "Warning: msys/cygwin detected. This particular test is likely to generate false failures due to our reliance on the underlying runtime library." << std::endl;
204+
#endif
181205
if (tester(1234344, 100000000)) {
182206
std::cout << "All tests ok." << std::endl;
183207
return EXIT_SUCCESS;

tests/string_test.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
#include <vector>
44

5+
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
6+
// Anything at all that is related to cygwin, msys and so forth will
7+
// always use this fallback because we cannot rely on it behaving as normal
8+
// gcc.
9+
#include <locale>
10+
#include <sstream>
11+
// workaround for CYGWIN
12+
double cygwin_strtod_l(const char* start, char** end) {
13+
double d;
14+
std::stringstream ss;
15+
ss.imbue(std::locale::classic());
16+
ss << start;
17+
ss >> d;
18+
size_t nread = ss.tellg();
19+
*end = const_cast<char*>(start) + nread;
20+
return d;
21+
}
22+
#endif
23+
524
inline void Assert(bool Assertion) {
625
if (!Assertion)
726
throw std::runtime_error("bug");
@@ -66,7 +85,9 @@ void strtod_from_string(const std::string &st, double& d) {
6685
template <>
6786
void strtod_from_string(const std::string &st, float& d) {
6887
char *pr = (char *)st.data();
69-
#ifdef _WIN32
88+
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
89+
d = cygwin_strtod_l(st, &pr, c_locale);
90+
#elif defined(_WIN32)
7091
static _locale_t c_locale = _create_locale(LC_ALL, "C");
7192
d = _strtof_l(st.data(), &pr, c_locale);
7293
#else
@@ -215,7 +236,9 @@ bool partow_test() {
215236

216237

217238
int main() {
218-
239+
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
240+
std::cout << "Warning: msys/cygwin detected. This particular test is likely to generate false failures due to our reliance on the underlying runtime library." << std::endl;
241+
#endif
219242
std::cout << "32 bits checks" << std::endl;
220243
Assert(partow_test<float>());
221244
Assert(test<float>());

0 commit comments

Comments
 (0)