From: Enlightenment S. <no-...@en...> - 2009-12-07 17:48:53
|
Log: * eina: Fix precision of eina_f32p32_div. Author: cedric Date: 2009-12-07 09:48:40 -0800 (Mon, 07 Dec 2009) New Revision: 44252 Modified: trunk/eina/src/include/eina_inline_f32p32.x Modified: trunk/eina/src/include/eina_inline_f32p32.x =================================================================== --- trunk/eina/src/include/eina_inline_f32p32.x 2009-12-07 17:23:41 UTC (rev 44251) +++ trunk/eina/src/include/eina_inline_f32p32.x 2009-12-07 17:48:40 UTC (rev 44252) @@ -58,8 +58,19 @@ static inline Eina_F32p32 eina_f32p32_div(Eina_F32p32 a, Eina_F32p32 b) { - /* If a > 2³², you will have a wrong result due to overflow. */ - return (a << 32) / b; + /* Prevent overflow and do '(a << 32) / b' */ + /* f32p64 / f32p32 = f32p32 */ + /* f32p32 / f32p32 = f32p0 */ + Eina_F32p32 up; + Eina_F32p32 down; + Eina_F32p32 result; + + up = (a / b) << 32; + down = (a << 32) / b; + + result = up + down; + + return result; } static inline Eina_F32p32 |