diff --git a/.gitignore b/.gitignore index aa8d1d59..31e56df1 100644 --- a/.gitignore +++ b/.gitignore @@ -59,5 +59,6 @@ test/testsuite test/benchsuite test/quad test/sandbox +test/math/pi tools/make-font # Our data diff --git a/configure.ac b/configure.ac index 9cbe9330..6ca3182e 100644 --- a/configure.ac +++ b/configure.ac @@ -322,6 +322,7 @@ AC_CONFIG_FILES( [Makefile src/Makefile test/Makefile + test/math/Makefile gfx/Makefile gfx/font/Makefile tools/Makefile diff --git a/src/real.h b/src/real.h index 1f377d28..ebb13e83 100644 --- a/src/real.h +++ b/src/real.h @@ -23,8 +23,6 @@ namespace lol class real { - static int const BIGITS = 32; - public: inline real() { } @@ -60,6 +58,11 @@ public: void print() const; private: + /* XXX: changing this requires tuning real::fres (the number of + * Newton-Raphson iterations) and real::print (the number of printed + * digits) */ + static int const BIGITS = 32; + uint32_t m_size; uint32_t m_signexp; uint16_t m_mantissa[BIGITS]; diff --git a/test/Makefile.am b/test/Makefile.am index 3df808d5..78038571 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,4 +1,6 @@ +SUBDIRS = math + AM_CPPFLAGS = -I$(top_srcdir)/src bench: benchsuite$(EXEEXT) diff --git a/test/math/Makefile.am b/test/math/Makefile.am new file mode 100644 index 00000000..0f630200 --- /dev/null +++ b/test/math/Makefile.am @@ -0,0 +1,17 @@ + +AM_CPPFLAGS = -I$(top_srcdir)/src + +all-local: $(noinst_PROGRAMS) + test x$(MAKE_FSELF) = xno || make_fself pi$(EXEEXT) pi.self + +CLEANFILES = $(noinst_PROGRAMS:%$(EXEEXT)=%.self) \ + $(noinst_PROGRAMS:%$(EXEEXT)=%.elf) \ + $(noinst_PROGRAMS:%$(EXEEXT)=%.exe) + +noinst_PROGRAMS = pi + +pi_SOURCES = pi.cpp +pi_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ +pi_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ +pi_DEPENDENCIES = $(top_builddir)/src/liblol.a + diff --git a/test/math/pi.cpp b/test/math/pi.cpp new file mode 100644 index 00000000..e00379c1 --- /dev/null +++ b/test/math/pi.cpp @@ -0,0 +1,37 @@ +// +// Lol Engine - Sample math program: compute Pi +// +// Copyright: (c) 2005-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" + +using namespace lol; + +int main(int argc, char **argv) +{ + /* Approximate Pi using Machin's formula: 16*atan(1/5)-4*atan(1/239) */ + real sum = 0.0, x0 = 5.0, x1 = 239.0; + real const m0 = -x0 * x0, m1 = -x1 * x1, r16 = 16.0, r4 = 4.0; + + /* Degree 240 is required for 512-bit mantissa precision */ + for (int i = 1; i < 240; i += 2) + { + sum += r16 / (x0 * (real)i) - r4 / (x1 * (real)i); + x0 *= m0; + x1 *= m1; + } + + sum.print(); + + return EXIT_SUCCESS; +} +