From 92518982cc3537594b10f40f00e3ba2d606108b3 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Thu, 13 Mar 2008 17:20:08 +1100 Subject: Added mathops-test --- tests/Makefile.am | 5 +++-- tests/mathops-test.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 tests/mathops-test.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index cf309a3..7d70c99 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,9 +1,9 @@ INCLUDES = -I$(top_srcdir)/libcelt METASOURCES = AUTO -TESTS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test rotation-test +TESTS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test rotation-test mathops-test -noinst_PROGRAMS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test rotation-test +noinst_PROGRAMS = type-test ectest cwrs32-test cwrs64-test real-fft-test dft-test laplace-test mdct-test rotation-test mathops-test type_test_SOURCES = type-test.c ectest_SOURCES = ectest.c @@ -14,6 +14,7 @@ dft_test_SOURCES = dft-test.c laplace_test_SOURCES = laplace-test.c mdct_test_SOURCES = mdct-test.c rotation_test_SOURCES = rotation-test.c +mathops_test_SOURCES = mathops-test.c LDFLAGS = -static LDADD = $(top_builddir)/libcelt/libcelt.la diff --git a/tests/mathops-test.c b/tests/mathops-test.c new file mode 100644 index 0000000..7044913 --- /dev/null +++ b/tests/mathops-test.c @@ -0,0 +1,63 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "mathops.h" +#include +#include + +#ifdef FIXED_POINT +#define WORD "%d" +#else +#define WORD "%f" +#endif + +int ret = 0; + +void testdiv() +{ + celt_int32_t i; + for (i=-327670;i<=327670;i++) + { + double prod; + celt_word32_t val; + if (i==0) + continue; + val = celt_rcp(i); +#ifdef FIXED_POINT + prod = (1./32768./65526.)*val*i; +#else + prod = val*i; +#endif + if (fabs(prod-1) > .001) + { + fprintf (stderr, "div failed: 1/%d="WORD" (product = %f)\n", i, val, prod); + ret = 1; + } + } +} + +void testsqrt() +{ + celt_int32_t i; + for (i=1;i<=1000000000;i++) + { + double ratio; + celt_word16_t val; + val = celt_sqrt(i); + ratio = val/sqrt(i); + if (fabs(ratio - 1) > .001 && fabs(val-sqrt(i)) > 2) + { + fprintf (stderr, "sqrt failed: sqrt(%d)="WORD" (ratio = %f)\n", i, val, ratio); + ret = 1; + } + i+= i>>10; + } +} + +int main() +{ + testdiv(); + testsqrt(); + return 0; +} -- cgit v1.2.3