Closed Biswa96 closed 1 year ago
Without having seen this myself, can I ask - does adding
#include <cstdlib>
near the top of TestFFT.cpp
- next to the existing cstdio
and cmath
includes - fix it?
Tried it but same error happens. The issue is srand48 and drand48 functions are not available in Windows platform. I have tried to replace those with srand and rand respectively. Here is the diff
--- a/src/test/TestFFT.cpp
+++ b/src/test/TestFFT.cpp
@@ -699,9 +699,9 @@ ALL_IMPL_AUTO_TEST_CASE(random)
double *re_compare = new double[n/2 + 1];
double *im_compare = new double[n/2 + 1];
double *back = new double[n];
- srand48(0);
+ srand(0);
for (int i = 0; i < n; ++i) {
- in[i] = drand48() * 4.0 - 2.0;
+ in[i] = rand() * 4.0 - 2.0;
}
USING_FFT(n);
if (eps < 1e-11) {
But the test failed after that modification. The log contains something like this:
../src/test/TestFFT.cpp(716): error: in "TestFFT/random_fftw": absolute value of back[cmp_i]/n - in[cmp_i]{-2.1827872842550278e-11} exceeds 9.9999999999999994e-12
drand48 and rand are not exactly equivalent. Those return double and int respectively.
OK, thanks. I'll take a look.
Found this workaround. Build and test both succeed.
--- a/src/test/TestFFT.cpp
+++ b/src/test/TestFFT.cpp
@@ -33,6 +33,11 @@
#include <cstdio>
#include <cmath>
+#ifdef _WIN32
+#define srand48(x) srand(x)
+#define drand48() ((double)(rand() / (RAND_MAX + 1.0)))
+#endif
+
using namespace RubberBand;
BOOST_AUTO_TEST_SUITE(TestFFT)
Should be fixed in the repo now - I did something similar except it's not conditional for Windows, since we don't really care enough to use drand48
expressly (as opposed to rand
) on any platform.