Different results from similar floating-point functions
问题 so i have 2 functions that should do the same thing float ver1(float a0, float a1) { float r0 = a0 - a1; if (abs(r0) > PI) { if (r0 > 0) { r0 -= PI2; } else { r0 += PI2; } } return r0; } float ver2(float a0, float a1) { float a2 = a1 - PI2; float r0 = a0 - a1; float r1 = a0 - a2; if (abs(r0) < abs(r1)) { return r0; } if (abs(r0) > abs(r1)) { return r1; } return 0; } note: PI and PI2 are float constants of pi and 2*pi The odd thing is that sometimes they produce different results, for example