big integer adder Fibonacci Factorial complete source code c++
replaces previous source code videos. Includes latest vers. of xBigUint with enhanced Exception tracer messages, Fib , Fac , system of 3 Eqs. interface to autoDelete and autoDelete.
speed boost for both operator*=() function()'s
place n / 2 into each operator*=()
to re-place the "two line" brute-force for() Loop ,
be sure to // comment out the 2 line for() Loop code .
just after the Left Shift and zero .
17 to 20 % speed boost for *=
Make 3 static's at the top of each function() ,.....
static LHS_ORG_ShiftTemp ;
static odd ;
static count ;
// START n / 2
if( MSD_RHS Greater Then 1 )
{
// initialize static's before each re-use
odd = YES ;
count = MSD_RHS / 2 ; // floor
if( ( count + count ) == MSD_RHS )
odd = NO ;
LHS_ORG_ShiftTemp = LHS_ORG_Temp ;
for( xx = 1 ; xx Less Then count ; xx++ )
LHS_ORG_ShiftTemp = LHS_ORG_ShiftTemp + LHS_ORG_Temp ; // add one set ( half count of RHS ) / 2
LHS_ORG_ShiftTemp = LHS_ORG_ShiftTemp + LHS_ORG_ShiftTemp ; // double it , just one add+ to double it
if( odd )
LHS_ORG_ShiftTemp = LHS_ORG_ShiftTemp + LHS_ORG_Temp ; // add one more LHS( ORG ) when n is odd
*this = LHS_ORG_ShiftTemp + *this ;
}
else
{
if( 1 == MSD_RHS ) // also change the lower n / 2 to look like
*this = LHS_ORG_Temp + *this ; // as zero does nothing ,
// no for() Loop needed here .
}
// END n / 2
code re-use:
// place inside of operator*=( xUint_64 ) we could do just 3 code lines , at the very start of the try block .
static xBigUint RHS_as_xBigUint ;
// initialize static , before each re-use
RHS_as_xBigUint = ( xBigUint ) RHS ;
return( (*this).operator*=( RHS_as_xBigUint ) ) ;
// LHS RHS
// that's it .
// code re-use really makes operator*=( xUint_64 ) small .
// besure to REM-out the remaining try block.
xBigUint 2 things:
1.
inside of both operator*=()'s , and operator+() 3 places,
REM-out the catch( bad_alloc ) blocks , as only the constructors catch bad_alloc's
2.
in main() for big Fibonacci and big Factorial for() Loop's
catch( xBigUintEx e ) include these two lines ,.. just after:
isNormalMsg_OK = NO ;
if( 0 != e.whatQue( 2 ) ) // bad_alloc occured via local static throw e ; // allocation ,
// during for() Loop try block ,
// the invalid numerical result won't be shown .
// constructor throws should be "Poked" too .
// the que allows complex messages and we can poke the que
// while in main() to logically handle a particular error code\msg .