Replication of the floating point equation

I would like to know if there is a way to improve the accuracy of the tilt calculation. (It appeared a few months ago here ).

It seems to change:

float get_slope(float dXa, float dXb, float dYa, float dYb) {
    return (dXa - dXb)/(dYa - dYb);
}

to

float get_slope(float dXa, float dXb, float dYa, float dYb) {
    return  dXa/(dYa - dYb) - dXb/(dYa - dYb);
}

may be an improvement. Suggestions?

Edit: this is the accuracy that I have achieved, not efficiency.

+3
source share
3 answers

Move them to double inside the function.


, , , . . , . , , y , . , - deltax deltay 1/. atan2().


, , , , , float , . , , Atari BASIC , 6502 BCD.

+5

, . ,

return  dXa/(dYa - dYb) - dXb/(dYa - dYb);

, , , . dXa dXb , .

+1

, , .

A B.

{( - (-)), ( - (-)} {( + ( - )), (Yb + (Ya - Yb) )}... A - B +.

. ( ), .

, , .

+1

Source: https://habr.com/ru/post/1709227/


All Articles