This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Confused with frexp and atangent (mathfp branch)
- From: Roman Belenov <rbelenov at yandex dot ru>
- To: newlib at sourceware dot org
- Date: Wed, 28 Dec 2005 10:54:26 +0300
- Subject: Confused with frexp and atangent (mathfp branch)
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
incorrect results.
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 (arctan2)
{
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.