Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
q_tand.c
Go to the documentation of this file.
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         /* intrinsic QTAND */
00041 
00042         /* by address version only */
00043 
00044 typedef union
00045 {
00046         struct
00047         {
00048                 unsigned int hi;
00049                 unsigned int lo;
00050         } word;
00051 
00052         double  d;
00053 } du;
00054 
00055 typedef union
00056 {
00057         struct
00058         {
00059                 uint32_t hi[2];
00060                 uint32_t lo[2];
00061         } word;
00062 
00063         long double     ld;
00064 } ldu;
00065 
00066 #define ROUND(d)        (int)(((d) >= 0.0) ? ((d) + 0.5) : ((d) - 0.5))
00067 
00068 static const    ldu     radspdeg =
00069 {0x3f91df46,    0xa2529d39,
00070  0x3c15c1d8,    0xbecdd290};
00071 
00072 static const    du      rninety =
00073 {0x3f86c16c,    0x16c16c17};
00074 
00075 long double __q_tand(long double *x)
00076 {
00077 ldquad  u;
00078 int     n;
00079 double  dn;
00080 long double     result;
00081 
00082         u.ld = *x;
00083 
00084         if ( u.q.hi != u.q.hi )
00085         {
00086                 /* x is a NaN; return a quiet NaN */
00087 
00088 #ifdef _IP_NAN_SETS_ERRNO
00089 
00090                 *__errnoaddr = EDOM;
00091 #endif
00092                 return ( __libm_qnan_ld );
00093         }
00094 
00095         if ( __qabs(*x) == __libm_inf_ld )
00096         {
00097                 /* x is +/-Inf; return a quiet NaN */
00098 
00099                 *__errnoaddr = EDOM;
00100 
00101                 return ( __libm_qnan_ld );
00102         }
00103 
00104         if ( *x == 0.0L )
00105                 return ( 0.0L );
00106 
00107         /* reduce arg to +/- 180 degrees */
00108 
00109         u.ld = __qmod(u.ld, 180.0L);
00110 
00111         /* next, reduce to +/-45.0 */
00112 
00113         if ( __qabs(u.ld) <= 45.0L )
00114         {
00115                 n = 0;
00116         }
00117         else
00118         {
00119                 dn = u.q.hi*rninety.d;
00120                 n = ROUND(dn);
00121                 dn = n;
00122 
00123                 u.ld = u.ld - dn*90.0;
00124         }
00125 
00126         /* convert x to radians */
00127 
00128         u.ld = u.ld*radspdeg.ld;
00129 
00130         if ( (n&1) == 0 )
00131         {
00132                 result = __qtan(u.ld);
00133         }
00134         else
00135         {
00136                 if ( u.ld == 0.0L )
00137                 {
00138                         *__errnoaddr = EDOM;
00139         
00140                         return ( __libm_qnan_ld );
00141                 }
00142 
00143                 result = -1.0L/__qtan(u.ld);
00144         }
00145 
00146         return ( result );
00147 }
00148 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines