From 2efd51d686e0dd911f0220ab2d595c0b3b0e18be Mon Sep 17 00:00:00 2001 From: Sam Moore Date: Tue, 29 Jul 2014 22:12:16 +0800 Subject: [PATCH] Use "Real" in CPU renderer for filled circles --- src/objectrenderer.cpp | 7 +++---- src/tests/arbint_vs_gmpint.cpp | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/objectrenderer.cpp b/src/objectrenderer.cpp index a5cd625..0770e46 100644 --- a/src/objectrenderer.cpp +++ b/src/objectrenderer.cpp @@ -179,17 +179,16 @@ void CircleFilledRenderer::RenderUsingCPU(const Objects & objects, const View & { for (int64_t y = max(0L, bounds.y); y <= min(bounds.y + bounds.h, target.h-1); ++y) { - double dx = 2.0*(double)(x - centre_x)/(double)(bounds.w); - double dy = 2.0*(double)(y - centre_y)/(double)(bounds.h); + Real dx(2); dx *= Real(x - centre_x)/Real(bounds.w); + Real dy(2); dy *= Real(y - centre_y)/Real(bounds.h); int64_t index = (x+target.w*y)*4; - if (dx*dx + dy*dy <= 1.0) + if (dx*dx + dy*dy <= Real(1)) { target.pixels[index+0] = 0; target.pixels[index+1] = 0; target.pixels[index+2] = 0; target.pixels[index+3] = 255; - } } } diff --git a/src/tests/arbint_vs_gmpint.cpp b/src/tests/arbint_vs_gmpint.cpp index 306bbb7..a30758c 100644 --- a/src/tests/arbint_vs_gmpint.cpp +++ b/src/tests/arbint_vs_gmpint.cpp @@ -7,13 +7,14 @@ #include "gmpint.h" #include "arbint.h" -#define TEST_CASES 100 + using namespace IPDF; int main(int argc, char ** argv) { - for (unsigned i = 0; i < TEST_CASES; ++i) + unsigned test_cases = (argc > 1) ? atoi(argv[1]) : 100; + for (unsigned i = 0; i < test_cases; ++i) { uint64_t a = rand(); @@ -28,6 +29,13 @@ int main(int argc, char ** argv) gmp_a *= b; } + + for (unsigned j = 0; j < 5; ++j) + { + arb_a += b; + gmp_a += b; + } + for (unsigned j = 0; j < 5; ++j) { arb_a /= b; @@ -35,6 +43,11 @@ int main(int argc, char ** argv) } + for (unsigned j = 0; j < 5; ++j) + { + arb_a -= b; + gmp_a -= b; + } } return 0; } -- 2.20.1