++ version for winding number