瀏覽代碼

math: make everything clean for a LolRemez release.

legacy
Sam Hocevar sam 13 年之前
父節點
當前提交
df39a0cedd
共有 5 個檔案被更改,包括 45 行新增23 行删除
  1. +23
    -0
      Makefile.am
  2. +2
    -0
      configure.ac
  3. +1
    -0
      src/lol/math/matrix.h
  4. +14
    -3
      src/lol/math/remez.h
  5. +5
    -20
      test/math/remez.cpp

+ 23
- 0
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)


+ 2
- 0
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)



+ 1
- 0
src/lol/math/matrix.h 查看文件

@@ -16,6 +16,7 @@
#if !defined __LOL_MATH_MATRIX_H__
#define __LOL_MATH_MATRIX_H__

#include <stdint.h>
#include <cmath>
#if !defined __ANDROID__
# include <iostream>


+ 14
- 3
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 <cstdio>

#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 */


+ 5
- 20
test/math/remez.cpp 查看文件

@@ -12,38 +12,23 @@
# include "config.h"
#endif

#include <cstdio>
#include <cstdlib>

#if USE_SDL && defined __APPLE__
# include <SDL_main.h>
#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;
}


Loading…
取消
儲存