From df39a0ceddaa3baa0d9da923ebfa7c68344b54d7 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 29 Dec 2011 18:36:54 +0000 Subject: [PATCH] math: make everything clean for a LolRemez release. --- Makefile.am | 23 +++++++++++++++++++++++ configure.ac | 2 ++ src/lol/math/matrix.h | 1 + src/lol/math/remez.h | 17 ++++++++++++++--- test/math/remez.cpp | 25 +++++-------------------- 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7b8d3e0c..e8f9c646 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,7 +11,9 @@ bench: .PHONY: bench dist: lolunit-$(LOLUNIT_VERSION).tar.gz +dist: lolremez-$(LOLREMEZ_VERSION).tar.gz +.PHONY: lolunit-$(LOLUNIT_VERSION).tar.gz lolunit-$(LOLUNIT_VERSION).tar.gz: rm -rf lolunit-$(LOLUNIT_VERSION) mkdir lolunit-$(LOLUNIT_VERSION) @@ -20,3 +22,24 @@ lolunit-$(LOLUNIT_VERSION).tar.gz: tar cvzf lolunit-$(LOLUNIT_VERSION).tar.gz lolunit-$(LOLUNIT_VERSION) rm -rf lolunit-$(LOLUNIT_VERSION) +.PHONY: lolremez-$(LOLREMEZ_VERSION).tar.gz +lolremez-$(LOLREMEZ_VERSION).tar.gz: + rm -rf lolremez-$(LOLREMEZ_VERSION) + mkdir lolremez-$(LOLREMEZ_VERSION) + mkdir lolremez-$(LOLREMEZ_VERSION)/lol + mkdir lolremez-$(LOLREMEZ_VERSION)/lol/math + cp $(top_srcdir)/src/real.cpp $(top_srcdir)/test/math/remez.cpp \ + lolremez-$(LOLREMEZ_VERSION) + cat $(top_srcdir)/src/real.cpp | sed 's@core.h@lol/math/real.h@' > \ + lolremez-$(LOLREMEZ_VERSION)/real.cpp + cp $(top_srcdir)/src/lol/math/real.h \ + $(top_srcdir)/src/lol/math/matrix.h \ + $(top_srcdir)/src/lol/math/remez.h \ + lolremez-$(LOLREMEZ_VERSION)/lol/math + printf 'remez: real.cpp remez.cpp\n' > lolremez-$(LOLREMEZ_VERSION)/Makefile + printf '\t$$(CXX) -I. -O2 -g -ggdb $$^ -o $$@\n' >> lolremez-$(LOLREMEZ_VERSION)/Makefile + printf 'clean:\n' >> lolremez-$(LOLREMEZ_VERSION)/Makefile + printf '\trm -f remez\n' >> lolremez-$(LOLREMEZ_VERSION)/Makefile + tar cvzf lolremez-$(LOLREMEZ_VERSION).tar.gz lolremez-$(LOLREMEZ_VERSION) + rm -rf lolremez-$(LOLREMEZ_VERSION) + diff --git a/configure.ac b/configure.ac index 3dd79dbf..e7933774 100644 --- a/configure.ac +++ b/configure.ac @@ -10,6 +10,8 @@ dnl AM_MAINTAINER_MODE dnl Versioning of the separate software we ship LOLUNIT_VERSION=0.1 AC_SUBST(LOLUNIT_VERSION) +LOLREMEZ_VERSION=0.1 +AC_SUBST(LOLREMEZ_VERSION) AM_CONFIG_HEADER(config.h) diff --git a/src/lol/math/matrix.h b/src/lol/math/matrix.h index fc520516..810fe39e 100644 --- a/src/lol/math/matrix.h +++ b/src/lol/math/matrix.h @@ -16,6 +16,7 @@ #if !defined __LOL_MATH_MATRIX_H__ #define __LOL_MATH_MATRIX_H__ +#include #include #if !defined __ANDROID__ # include diff --git a/src/lol/math/remez.h b/src/lol/math/remez.h index 4714151f..bb5f2959 100644 --- a/src/lol/math/remez.h +++ b/src/lol/math/remez.h @@ -9,13 +9,17 @@ // // -// The Remez class -// --------------- +// The RemezSolver class +// --------------------- // #if !defined __LOL_MATH_REMEZ_H__ #define __LOL_MATH_REMEZ_H__ +#include + +#include "lol/math/matrix.h" + namespace lol { @@ -57,6 +61,11 @@ public: PrintPoly(); } + inline void Run(T a, T b, RealFunc *func, int steps) + { + Run(a, b, func, NULL, steps); + } + T ChebyEval(T const &x) { T ret = 0.0, xn = 1.0; @@ -319,7 +328,9 @@ public: T Weight(T const &x) { - return m_weight(x * m_k2 + m_k1); + if (m_weight) + return m_weight(x * m_k2 + m_k1); + return 1; } /* ORDER + 1 Chebyshev coefficients and 1 error value */ diff --git a/test/math/remez.cpp b/test/math/remez.cpp index 4f5dc276..d8f8871f 100644 --- a/test/math/remez.cpp +++ b/test/math/remez.cpp @@ -12,38 +12,23 @@ # include "config.h" #endif -#include -#include - #if USE_SDL && defined __APPLE__ # include #endif #include "lol/math/real.h" -#include "lol/math/matrix.h" #include "lol/math/remez.h" using lol::real; using lol::RemezSolver; -/* The function we want to approximate */ -real myfun(real const &y) -{ - real x = sqrt(y); - return (sin(x) - x) / (x * y); -} - -real myerr(real const &y) -{ - real x = sqrt(y); - return sin(x) / (x * y); -} +/* See the tutorial at http://lol.zoy.org/wiki/doc/maths/remez */ +real f(real const &x) { return exp(x); } int main(int argc, char **argv) { - RemezSolver<2, real> solver; - solver.Run(real::R_1 >> 400, real::R_PI_2 * real::R_PI_2, myfun, myerr, 40); - - return EXIT_SUCCESS; + RemezSolver<4, real> solver; + solver.Run(-1, 1, f, 30); + return 0; }