tanf() can be modified according to a bugfix in tan()

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

tanf() can be modified according to a bugfix in tan()

张Angela
The calculation of tanf() which lies in
src/lib/libm/src/k_tanf.c can be modified
according to a bugfix ported on FreeBSD on GitHub:
https://github.com/freebsd/freebsd/commit/152a4c4166c18974fe1fc9d9a8535d78956aca26  

And here's the code:

- if(ix<0x31800000)    /* x < 2**-28 */
-         {if((int)x==0) {    /* generate inexact */
-                 if((ix|(iy+1))==0) return one/fabsf(x);
-                 else return (iy==1)? x: -one/x;
-         }
-         }
+ if(ix<0x31800000) {    /* x < 2**-28 */
+         if ((int) x == 0) {    /* generate inexact */
+                 if ((ix | (iy + 1)) == 0)
+                         return one / fabsf(x);
+                 else {
+                         if (iy == 1)
+                                 return x;
+                         else {    /* compute -1 / (x+y) carefully */
+                                 double a, t;
+                                 
+                                 z = w = x + y;
+                                 GET_FLOAT_WORD(ix, z);
+                                 SET_FLOAT_WORD(z, ix & 0xfffff000);
+                                 v = y - (z - x);
+                                 t = a = -one / w;
+                                 GET_FLOAT_WORD(ix, t);
+                                 SET_FLOAT_WORD(t, ix & 0xfffff000);
+                                 s = one + t * z;
+                                 return t + a * (s + t * v);
+                         }
+                 }
+         }
+ }

Although the bug really only applies to tan() and not tanf(),
there seems to be a precedent that the float versions
of the fdlibm routines should mirror their double counterparts.


Greetings!