Why doesnt this work

it doesnt detect intersections when the line goes above or below the cirlce

/*

*returns true if the specified line segment intersects the specified circle

*/

public final boolean lineIntersectsCircle(

float x, float y, float x1, float y1, //line segment from (x, y) to (x1, y1)

float a, float b, float r){ //circle at (a, b) with radius r

//gradient of the line

float m = (y-y1)/(x-x1);

//find the part to be sqrted

float sqrtedPart = r*r - ((m*(x-x1)+y1)-b)*((m*(x-x1)+y1)-b);

//check for negativeness

if(sqrtedPart < 0) return false;

//work out the square root part

float sqrtPart = (float) Math.sqrt(sqrtedPart);

//positive root answer

float intersectX1 = sqrtPart + a;

//neg root answer

float intersectX2 = (-1*sqrtPart) + a;

//sort the x values of the line segment so x < x1

if(x > x1){

float temp = x;

x = x1;

x1 = temp;

}

//check intersection is within line segment bound

return (intersectX1 >= x && intersectX1 < x1)

|| (intersectX2 >= x && intersectX2 < x1);

}