diff --git a/ttmath/ttmath.h b/ttmath/ttmath.h index b807564..3883108 100644 --- a/ttmath/ttmath.h +++ b/ttmath/ttmath.h @@ -1902,13 +1902,16 @@ namespace ttmath while( !carry && multiplerWasStopSignal() ) + if( stop && (multipler & 127)==0 ) // it means 'stop && (multipler % 128)==0' { - if( err ) - *err = err_interrupt; + // after each 128 iterations we make a test + if( stop->WasStopSignal() ) + { + if( err ) + *err = err_interrupt; - return 2; + return 2; + } } ++multipler; @@ -1932,20 +1935,25 @@ namespace ttmath one.SetOne(); uint carry = 0; + uint iter = 1; // only for testing the stop object while( !carry && multipler < x ) { - // !! the test here we don't have to make in all iterations (performance) - if( stop && stop->WasStopSignal() ) + if( stop && (iter & 31)==0 ) // it means 'stop && (iter % 32)==0' { - if( err ) - *err = err_interrupt; + // after each 32 iterations we make a test + if( stop->WasStopSignal() ) + { + if( err ) + *err = err_interrupt; - return 2; + return 2; + } } carry += multipler.Add(one); carry += result.Mul(multipler); + ++iter; } if( err ) diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index 422d563..2b5057a 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -1399,19 +1399,17 @@ public: denominator.SetOne(); denominator_i.SetOne(); - // every 'step_test' times we make a test - const uint step_test = 5; uint i; old_value = *this; - // we begin from 1 in order to not testing at the beginning + // we begin from 1 in order to not test at the beginning #ifdef TTMATH_CONSTANTSGENERATOR for(i=1 ; true ; ++i) #else for(i=1 ; i<=TTMATH_ARITHMETIC_MAX_LOOP ; ++i) #endif { - bool testing = ((i % step_test) == 0); + bool testing = ((i & 3) == 0); // it means '(i % 4) == 0' next_part = numerator; @@ -1567,20 +1565,17 @@ public: SetZero(); old_value = *this; - - // every 'step_test' times we make a test - const uint step_test = 5; uint i; #ifdef TTMATH_CONSTANTSGENERATOR for(i=1 ; true ; ++i) #else - // we begin from 1 in order to not testing at the beginning + // we begin from 1 in order to not test at the beginning for(i=1 ; i<=TTMATH_ARITHMETIC_MAX_LOOP ; ++i) #endif { - bool testing = ((i % step_test) == 0); + bool testing = ((i & 3) == 0); // it means '(i % 4) == 0' next_part = x1;