From 4922c2682860ed568c4a093f47344fc41f8171ec Mon Sep 17 00:00:00 2001 From: dooglus Date: Wed, 10 Oct 2007 01:59:21 +0000 Subject: [PATCH] Various changes: Improve the formatting of the output. Stop the compiler optimizing out the calculations. Allow greater error when multiplying by PI if _fixed.h isn't rounding to the nearest integer. Define variable before using it. Tidy the source code layout. Prevent a core dump by not allowing numbers to wrap around to zero. git-svn-id: http://svn.voria.com/code@872 1f10aa63-cdf2-0310-b900-c93c546f37ac --- ETL/trunk/test/fixed.cpp | 201 +++++++++++++++-------------------------------- 1 file changed, 62 insertions(+), 139 deletions(-) diff --git a/ETL/trunk/test/fixed.cpp b/ETL/trunk/test/fixed.cpp index 16cca25..369f0d1 100644 --- a/ETL/trunk/test/fixed.cpp +++ b/ETL/trunk/test/fixed.cpp @@ -35,7 +35,7 @@ #define ADD_SUB_TEST 20000000 #define MUL_TEST 10000000 -#define DIV_TEST 10000000 +#define DIV_TEST 1048573 // at 1048573, fixed point numbers wrap around to zero using namespace etl; /* === C L A S S E S ======================================================= */ @@ -53,95 +53,42 @@ struct speed_test MyTimer.reset(); for(i=0;i(0.5)); + d=value_type(1); + const value_type one_and_a_half(static_cast(1.5)); int i; etl::clock MyTimer; MyTimer.reset(); - for(i=0;i0.0005) +#else + if( d>0.0025) +#endif { fprintf(stderr,"fixed: Failed test on line %d in "__FILE__".\n",__LINE__); ret++; @@ -291,11 +220,6 @@ int char_test(void) int main() { - fprintf(stderr, "\n***\n"); - fprintf(stderr, "*** tests in fixed.cpp fail - see http://wiki.synfig.com/Source:ETL_make_check for an explanation ***\n"); - fprintf(stderr, "***\n\n"); - sleep(5); - int error=0; error+=basic_test(); @@ -307,19 +231,19 @@ int main() { double flt,fix,inte; - fprintf(stderr,"Addition/subtraction test..."); + fprintf(stderr,"\nAddition/subtraction test...\n"); - fprintf(stderr,"calculating float..."); + fprintf(stderr," calculating float....."); flt=float_test.add_sub_test(); - fprintf(stderr,"float time: %fsec\n",flt); + fprintf(stderr," float time: %f sec\n",flt); - fprintf(stderr,"calculating fixed..."); + fprintf(stderr," calculating fixed....."); fix=fixed_test.add_sub_test(); - fprintf(stderr,"fixed time: %fsec\n",fix); + fprintf(stderr," fixed time: %f sec\n",fix); - fprintf(stderr,"calculating integer..."); + fprintf(stderr," calculating integer..."); inte=int_test.add_sub_test(); - fprintf(stderr,"integer time: %fsec\n",inte); + fprintf(stderr," integer time: %f sec\n",inte); if(flt>fix) fprintf(stderr,"Fixed point wins by %f seconds! (%f%% faster)\n",flt-fix,flt/fix*100.0f-100.0f); @@ -330,40 +254,39 @@ int main() { double flt,fix,inte; - fprintf(stderr,"Product test..."); - fprintf(stderr,"calculating float..."); + fprintf(stderr,"\nProduct test...\n"); + fprintf(stderr," calculating float....."); flt=float_test.mul_test(); - fprintf(stderr,"float time: %fsec\n",flt); - fprintf(stderr,"calculating fixed..."); + fprintf(stderr," float time: %f sec\n",flt); + fprintf(stderr," calculating fixed....."); fix=fixed_test.mul_test(); - fprintf(stderr,"fixed time: %fsec\n",fix); - fprintf(stderr,"calculating integer..."); + fprintf(stderr," fixed time: %f sec\n",fix); + fprintf(stderr," calculating integer..."); inte=int_test.mul_test(); - fprintf(stderr,"integer time: %fsec\n",inte); + fprintf(stderr," integer time: %f sec\n",inte); if(flt>fix) fprintf(stderr,"Fixed point wins by %f seconds! (%f%% faster)\n",flt-fix,flt/fix*100.0f-100.0f); else fprintf(stderr,"Floating point wins by %f seconds! (%f%% faster)\n",fix-flt,fix/flt*100.0f-100.0f); - } { double flt,fix,inte; - fprintf(stderr,"Division test..."); - fprintf(stderr,"calculating float..."); + fprintf(stderr,"\nDivision test...\n"); + fprintf(stderr," calculating float....."); flt=float_test.div_test(); - fprintf(stderr,"float time: %fsec\n",flt); - fprintf(stderr,"calculating fixed..."); + fprintf(stderr," float time: %f sec\n",flt); + fprintf(stderr," calculating fixed....."); fix=fixed_test.div_test(); - fprintf(stderr,"fixed time: %fsec\n",fix); - fprintf(stderr,"calculating integer..."); + fprintf(stderr," fixed time: %f sec\n",fix); + fprintf(stderr," calculating integer..."); inte=int_test.div_test(); - fprintf(stderr,"integer time: %fsec\n",inte); + fprintf(stderr," integer time: %f sec\n",inte); if(flt>fix) fprintf(stderr,"Fixed point wins by %f seconds! (%f%% faster)\n",flt-fix,flt/fix*100.0f-100.0f); else fprintf(stderr,"Floating point wins by %f seconds! (%f%% faster)\n",fix-flt,fix/flt*100.0f-100.0f); - + fprintf(stderr,"\n"); } return error; -- 2.7.4