btw, an ARB_fragment_program version of this function is actually used in

this pic
here's the ARB_fragment_program implementing a ray-sphere test
!!ARBfp1.0 #rayTracer Sphere1
TEMP origin;
TEMP direction;
PARAM sphere = { 0.0,0.0,2.0,1.0 };
TEX origin, fragment.texcoord[0], texture[0], RECT;
TEX direction, fragment.texcoord[0], texture[1], RECT;
# intersectRaySphere
TEMP distance;
SUB distance,origin,sphere;
# quadricEquation
TEMP params;
DP3 params.x,distance,direction;
DP3 params.y,distance,distance;
SUB params.y,params.y,sphere.w;
MAD params.z,params.x,params.x,-params.y;
KIL params.z;
RSQ params.z,params.z;
RCP params.z,params.z;
ADD params.x,-params.x,-params.z;
TEMP point;
MAD point,params.x,direction,origin;
TEMP normal;
SUB normal,point,sphere;
DP3 normal.w,normal,normal;
RSQ normal.w,normal.w;
MUL normal,normal,normal.w;
TEMP diffuse;
DP3 diffuse,normal,state.light[0].position;
PARAM color = { 1.0,0.5,0.25,0 };
MUL result.depth,params.x,0.125;
MUL result.color,color,diffuse;
END