shithub: opus

Download patch

ref: 92518982cc3537594b10f40f00e3ba2d606108b3
parent: 9d5b4a6f56b1bd896025444d571af76668de4f08
author: Jean-Marc Valin <[email protected]>
date: Thu Mar 13 13:20:08 EDT 2008

Added mathops-test

--- 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 @@
 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
--- /dev/null
+++ b/tests/mathops-test.c
@@ -1,0 +1,63 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "mathops.h"
+#include <stdio.h>
+#include <math.h>
+
+#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;
+}