/* origin: FreeBSD /usr/src/lib/msun/src/s_atanf.c */1/*2* Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].3*/4/*5* ====================================================6* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.7*8* Developed at SunPro, a Sun Microsystems, Inc. business.9* Permission to use, copy, modify, and distribute this10* software is freely granted, provided that this notice11* is preserved.12* ====================================================13*/141516#include "libm.h"1718static const float atanhi[] = {194.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */207.8539812565e-01, /* atan(1.0)hi 0x3f490fda */219.8279368877e-01, /* atan(1.5)hi 0x3f7b985e */221.5707962513e+00, /* atan(inf)hi 0x3fc90fda */23};2425static const float atanlo[] = {265.0121582440e-09, /* atan(0.5)lo 0x31ac3769 */273.7748947079e-08, /* atan(1.0)lo 0x33222168 */283.4473217170e-08, /* atan(1.5)lo 0x33140fb4 */297.5497894159e-08, /* atan(inf)lo 0x33a22168 */30};3132static const float aT[] = {333.3333328366e-01,34-1.9999158382e-01,351.4253635705e-01,36-1.0648017377e-01,376.1687607318e-02,38};3940float __cdecl atanf(float x)41{42float_t w,s1,s2,z;43uint32_t ix,sign;44int id;4546GET_FLOAT_WORD(ix, x);47sign = ix>>31;48ix &= 0x7fffffff;49if (ix >= 0x4c800000) { /* if |x| >= 2**26 */50if (isnan(x))51return x;52z = atanhi[3] + 0x1p-120f;53return sign ? -z : z;54}55if (ix < 0x3ee00000) { /* |x| < 0.4375 */56if (ix < 0x39800000) { /* |x| < 2**-12 */57if (ix < 0x00800000)58/* raise underflow for subnormal x */59FORCE_EVAL(x*x);60return x;61}62id = -1;63} else {64x = fabsf(x);65if (ix < 0x3f980000) { /* |x| < 1.1875 */66if (ix < 0x3f300000) { /* 7/16 <= |x| < 11/16 */67id = 0;68x = (2.0f*x - 1.0f)/(2.0f + x);69} else { /* 11/16 <= |x| < 19/16 */70id = 1;71x = (x - 1.0f)/(x + 1.0f);72}73} else {74if (ix < 0x401c0000) { /* |x| < 2.4375 */75id = 2;76x = (x - 1.5f)/(1.0f + 1.5f*x);77} else { /* 2.4375 <= |x| < 2**26 */78id = 3;79x = -1.0f/x;80}81}82}83/* end of argument reduction */84z = x*x;85w = z*z;86/* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */87s1 = z*(aT[0]+w*(aT[2]+w*aT[4]));88s2 = w*(aT[1]+w*aT[3]);89if (id < 0)90return x - x*(s1+s2);91z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);92return sign ? -z : z;93}949596