Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <errno.h>
00037 #include <inttypes.h>
00038 #include "quad.h"
00039
00040 static long double __qldexp(long double, int);
00041
00042 typedef union
00043 {
00044 struct
00045 {
00046 uint32_t hi[2];
00047 uint32_t lo[2];
00048 } word;
00049
00050 long double ld;
00051 } ldu;
00052
00053 static long double qatn2dres1[2][2] =
00054 {90.0L, -90.0L, 90.0L, -90.0L};
00055
00056 static long double qatn2dres2[2][2] =
00057 {0.0L, -0.0L, 180.0L, -180.0L};
00058
00059 static long double qatn2dres3[4][4] =
00060 {0.0L, 0.0L, 90.0L, 90.0L,
00061 0.0L, 0.0L, 90.0L, 90.0L,
00062 0.0L, -0.0L, 45.0L, 45.0L,
00063 180.0L, -180.0L, 135.0L, 135.0L,
00064 };
00065
00066 static const ldu degprad =
00067 {0x404ca5dc, 0x1a63c1f8,
00068 0xbce1e7ab, 0x456405f9};
00069
00070 long double __qatan2d(long double arg1, long double arg2)
00071 {
00072 ldquad x, y;
00073 ldquad x1, y1;
00074 int ix, xptx;
00075 int iy, xpty;
00076 int signx, signy;
00077 int i, j;
00078 long double result;
00079
00080 y.ld = arg1;
00081 x.ld = arg2;
00082
00083 if ((y.q.hi != y.q.hi) || (x.q.hi != x.q.hi)) {
00084
00085 #ifdef _IP_NAN_SETS_ERRNO
00086 *__errnoaddr = EDOM;
00087 #endif
00088 return (__libm_qnan_ld);
00089 }
00090
00091
00092 iy = *(int *)&y.q.hi;
00093 xpty = (iy >> 20);
00094 xpty &= 0x7ff;
00095 ix = *(int *)&x.q.hi;
00096 xptx = (ix >> 20);
00097 xptx &= 0x7ff;
00098 signy = (iy >> 31);
00099 signy = (signy & 1);
00100 signx = (ix >> 31);
00101 signx = (signx & 1);
00102
00103
00104 if (x.q.hi == 0.0) {
00105 if (y.q.hi == 0.0) {
00106 return (0.0L);
00107 }
00108 return (qatn2dres1[signx][signy]);
00109 } else if (y.q.hi == 0.0) {
00110 return (qatn2dres2[signx][signy]);
00111 }
00112
00113
00114 i = (xptx == 0x7ff);
00115 j = (xpty == 0x7ff);
00116 if ((i + j) != 0) {
00117 i = i + i;
00118 i = i + signx;
00119 j = j + j;
00120 j = j + signy;
00121 return (qatn2dres3[i][j]);
00122 }
00123
00124 y1.ld = __qabs(y.ld);
00125 x1.ld = __qabs(x.ld);
00126
00127 if (y1.q.hi < x1.q.hi) {
00128
00129 if (y1.ld <= __qldexp(x1.ld, -1075)) {
00130
00131 return (qatn2dres2[signx][signy]);
00132 }
00133 } else {
00134
00135
00136 if (xpty > xptx + 108)
00137 return ((signy == 0) ? 90.0L : -90.0L);
00138 }
00139 result = __qatan2(y.ld, x.ld);
00140 return (result*degprad.ld);
00141 }
00142
00143 long double __q_atn2d(long double *arg1, long double *arg2)
00144 {
00145 return(__qatan2d(*arg1, *arg2));
00146 }
00147
00148 static long double __qldexp(long double x, int n)
00149 {
00150 ldquad z;
00151 ldquad result;
00152 double ldexp(double, int);
00153
00154
00155 z.ld = x;
00156 result.q.hi = ldexp(z.q.hi, n);
00157 if (result.q.hi == 0.0)
00158 result.q.lo = 0.0;
00159 else
00160 result.q.lo = ldexp(z.q.lo, n);
00161 if (result.q.lo == 0.0)
00162 result.q.lo = 0.0;
00163 *__errnoaddr = 0;
00164 return(result.ld);
00165 }