courseTask2-9/main.c
int z_findMinPowerGreaterThan(int base, double threshold, int startPower, int enthropy) {
	
	int power = startPower;

	short int toRight = 1;
	
	int iterations = 0; /* debug line */

	double powResult, previousPowResult;
	
	while (enthropy != 0) {
		
		if (toRight) {

			powResult = pow(base, power);
			
			while (powResult <= threshold) {
				
				iterations++;
				
				previousPowResult = powResult;
				
				powResult *= pow(base, enthropy);
				
				if (powResult < previousPowResult) {
					
					/* integer overflow */
					
					goto mark;
					
				}
				
				power += enthropy;
				
			}
			
		}
		else {
			
			/* int powResult = intPow(base, power - 1); */
            powResult = pow(base, power - 1);

			while (powResult > threshold) {
				
				powResult /= pow(base, enthropy);
				
				power -= enthropy;
				
				iterations++;
				
			}
			
		}
		
		toRight = !toRight;
		
		enthropy /= 2;
		
	}
	
	mark:
		
	printf("=======================\nIterations: %d\n", iterations);
	
	return power;
	
}
/* the greater the enthropy, the more performance on long ranges  */
the greater the enthropy, the more performance on long ranges
the greater the enthropy the more performance on long ranges
int z_findMinPowerGreaterThan(int base, double threshold, int startPower, int enthropy) {
	int power = startPower;
	short int toRight = 1;
	int iterations = 0; 
	double powResult, previousPowResult;
	while (enthropy != 0) {
		if (toRight) {
			powResult = pow(base, power);
			while (powResult <= threshold) {
				iterations++;
				previousPowResult = powResult;
				powResult *= pow(base, enthropy);
				if (powResult < previousPowResult) {
					goto mark;
				}
				power += enthropy;
			}
		}
		else {
            powResult = pow(base, power - 1);
			while (powResult > threshold) {
				powResult /= pow(base, enthropy);
				power -= enthropy;
				iterations++;
			}
		}
		toRight = !toRight;
		enthropy /= 2;
	}
	mark:
	printf("=======================\nIterations: %d\n", iterations);
	return power;
}
int z_findMinPowerGreaterThan ( int base , double threshold , int startPower , int enthropy ) { int power = startPower ; short int toRight = 1 ; int iterations = 0 ; double powResult , previousPowResult ; while ( enthropy != 0 ) { if ( toRight ) { powResult = pow ( base , power ) ; while ( powResult <= threshold ) { iterations ++ ; previousPowResult = powResult ; powResult *= pow ( base , enthropy ) ; if ( powResult < previousPowResult ) { goto mark ; } power += enthropy ; } } else { powResult = pow ( base , power - 1 ) ; while ( powResult > threshold ) { powResult /= pow ( base , enthropy ) ; power -= enthropy ; iterations ++ ; } } toRight = ! toRight ; enthropy /= 2 ; } mark : printf ( " \n \n " , iterations ) ; return power ; }
the greater the enthropy, the more performance on long ranges
the greater the enthropy the more performance on long ranges
/* debug line */ /* integer overflow */ /* int powResult = intPow(base, power - 1); */