Commit 92518982 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Added mathops-test

parent 9d5b4a6f
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
#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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment