### counting operations

I'm trying to figure out how in the example they came up with how they added the bitops mults and adds

 ``12345678910111213`` ``````double sqrt(int x) { double tol = (double)x*1.e-17; double y = (double)x; double radicand = y; // radicand = number whose square root we seek double sqrt = y/2; // first guess bitops += 6; mults += 2; while(abs(y - sqrt) > tol) { y = sqrt; sqrt = (y + radicand/y)/2; mults +=2; adds += 2; bitops += 4; } return(sqrt); } ``````
bitops, mults and adds are not defined within the scope of this function. If this compiles, then these were declared globally.
also 'sqrt' shouldn't be used both as a variable name and the function.
Sorry I should have clarified that this was a function outside of main and that bitops, mults and adds have been declared at the beginning of the code. They are counters to assess how many operations are taking place. I am trying to understand which are the bit operations - bitops, when it multiplies and divides - mults, and the additions and subtractions - adds.
Topic archived. No new replies allowed.