| @@ -59,5 +59,6 @@ test/testsuite | |||||
| test/benchsuite | test/benchsuite | ||||
| test/quad | test/quad | ||||
| test/sandbox | test/sandbox | ||||
| test/math/pi | |||||
| tools/make-font | tools/make-font | ||||
| # Our data | # Our data | ||||
| @@ -322,6 +322,7 @@ AC_CONFIG_FILES( | |||||
| [Makefile | [Makefile | ||||
| src/Makefile | src/Makefile | ||||
| test/Makefile | test/Makefile | ||||
| test/math/Makefile | |||||
| gfx/Makefile | gfx/Makefile | ||||
| gfx/font/Makefile | gfx/font/Makefile | ||||
| tools/Makefile | tools/Makefile | ||||
| @@ -23,8 +23,6 @@ namespace lol | |||||
| class real | class real | ||||
| { | { | ||||
| static int const BIGITS = 32; | |||||
| public: | public: | ||||
| inline real() { } | inline real() { } | ||||
| @@ -60,6 +58,11 @@ public: | |||||
| void print() const; | void print() const; | ||||
| private: | 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_size; | ||||
| uint32_t m_signexp; | uint32_t m_signexp; | ||||
| uint16_t m_mantissa[BIGITS]; | uint16_t m_mantissa[BIGITS]; | ||||
| @@ -1,4 +1,6 @@ | |||||
| SUBDIRS = math | |||||
| AM_CPPFLAGS = -I$(top_srcdir)/src | AM_CPPFLAGS = -I$(top_srcdir)/src | ||||
| bench: benchsuite$(EXEEXT) | bench: benchsuite$(EXEEXT) | ||||
| @@ -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 | |||||
| @@ -0,0 +1,37 @@ | |||||
| // | |||||
| // Lol Engine - Sample math program: compute Pi | |||||
| // | |||||
| // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> | |||||
| // 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; | |||||
| } | |||||