





'''simple docstring'''




from collections.abc import Callable
def 	UpperCAmelCase_							(					__lowercase							:      Callable[[float], float]			,     __lowercase							:      float			,     __lowercase							:      float       )		->       float:


     '''simple docstring'''



     _UpperCAmelCase     							=   a
     _UpperCAmelCase     							=   b
     if function(__lowercase       ) == 0:  # one of the a or b is a root for the function
          return a
     elif function(__lowercase       ) == 0:
          return b
     elif (
         function(__lowercase       ) * function(__lowercase       ) > 0
     ):  # if none of these are root and they are both positive or negative,
          # then this algorithm can't find the root
          raise ValueError("could not find root in given interval."       )
     else:
          _UpperCAmelCase     							=   start + (end - start) / 2.0
          while abs(start - mid       ) > 10**-7:  # until precisely equals to 10^-7
               if function(__lowercase       ) == 0:
                    return mid
               elif function(__lowercase       ) * function(__lowercase       ) < 0:
                    _UpperCAmelCase     							=   mid
               else:
                    _UpperCAmelCase     							=   mid
               _UpperCAmelCase     							=   start + (end - start) / 2.0
          return mid
def 	UpperCAmelCase_							(					__lowercase							:      float       )		->       float:


     '''simple docstring'''



     return x**3 - 2 * x - 5


if __name__ == "__main__":
  print(bisection(f, 1, 1000))

  import doctest

  doctest.testmod()











'''simple docstring'''




def 	UpperCAmelCase_							(					__lowercase							:      int       )		->       int:


     '''simple docstring'''



     if not isinstance(__lowercase			,     __lowercase       ) or number < 0:
          raise ValueError("Input must be a non-negative integer"       )

     _UpperCAmelCase     							=   0
     while number:
          # This way we arrive at next set bit (next 1) instead of looping
          # through each bit and checking for 1s hence the
          # loop won't run 32 times it will only run the number of `1` times
          number &= number - 1
          count += 1
     return count


if __name__ == "__main__":
  import doctest

  doctest.testmod()




