Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 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 /* filter out Nans */ 00083 if ((y.q.hi != y.q.hi) || (x.q.hi != x.q.hi)) { 00084 /* y or x is a NaN; return a quiet NaN */ 00085 #ifdef _IP_NAN_SETS_ERRNO 00086 *__errnoaddr = EDOM; 00087 #endif 00088 return (__libm_qnan_ld); 00089 } 00090 00091 /* extract exponents of y and x for some quick screening */ 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 /* filter out zero arguments */ 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 /* filter out infinities */ 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 /* |y/x| < 1.0 */ 00129 if (y1.ld <= __qldexp(x1.ld, -1075)) { 00130 /* |y/x| underflows */ 00131 return (qatn2dres2[signx][signy]); 00132 } 00133 } else { 00134 /* |y/x| >= 1.0 */ 00135 /* a crude check to avoid underflow of x/y */ 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 }