Confused with frexp and atangent (mathfp branch)
Wed Dec 28 20:00:00 GMT 2005
I'm working with a toolchain that uses newlib with mathfp branch used for
libm. I've encountered some problems - it seems that newlib functions give
First, frexp(0., &exp) writes -1022 to exp (instead of 0 required by standard)
as a result of calculating
*exp = ((hd & 0x7ff00000) >> 20) - 1022;
(since 0. is represented as all-zero-bits-value). Probably explicit test for
zero (together with NAN and INF) is required.
Second, there is confusing usage of branch variable in atangent() function,
resulting in incorrect results from atan2. As a result of the following code
if (u < 0.0 || branch == 2)
res = __PI - res;
if (v < 0.0 || branch == 1)
res = -res;
result is always set to PI for very small values of y/x (including y==0. due
to aforementioned behaviour of frexp) and to -PI/2 for very high numbers
("very" means that preceding exponent test sets branch to nonzero value),
since signs of u and v are effectively ignored. Seems like checks for branch
here are erroneous. I don't have the textbook mention in s_atangent.c
available, so can't check whether this snippet comes from its text and whether
there is any rationale.
Can anybody elaborate on these issues ?
With regards, Roman.
More information about the Newlib