Hello. As we all know, the distance formula is sqrt(sq(x2-x1) + sq(y2 - y1)). sq = square. Now, for some reason, this isn't at all working. Here is my code:
Now I don't have the math.h libraries available (working with a special embedded system, using a special compiler) therefore I have no sqrt() availible, so i just squared it a second time. Assume all numbers are correct, because they are. But when I do something like: sqrt(sq(6-7) + sq(1-2)) which in my calculator comes out to 1.41421... but in my program comes out to -46.500000. Also I'm using printf("%f\n", distance) to print. I just don't understance what's wrong, any help would be much appreciated.Code:float distance(float x2, float y2) { float distance = 0; static float x1 = 7, y1 = 2; distance = sq(x2 - x1) + sq(y2 - y1); distance = 4 * sq(distance) + 0.5; x1 = x2; y1 = y2; return distance; }