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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 static char *rcs_id = "$Source: /home/bos/bk/kpro64-pending/libm/mips/SCCS/s.hypotf.c $ $Revision: 1.5 $";
00060
00061 #ifdef _CALL_MATHERR
00062 #include <stdio.h>
00063 #include <math.h>
00064 #include <errno.h>
00065 #endif
00066
00067 #include "libm.h"
00068
00069 #if defined(mips) && !defined(__GNUC__)
00070 extern float fhypot(float, float);
00071 extern float hypotf(float, float);
00072
00073 #pragma weak fhypot = __hypotf
00074 #pragma weak hypotf = __hypotf
00075 #endif
00076
00077 #if defined(BUILD_OS_DARWIN)
00078 extern float __hypotf(float, float);
00079 #pragma weak hyptof
00080 float hypotf( float x, float y ) {
00081 return __hypotf( x, y );
00082 }
00083 #elif defined(__GNUC__)
00084 extern float __hypotf(float, float);
00085 float hypotf(float, float) __attribute__ ((weak, alias ("__hypotf")));
00086 #endif
00087
00088 static const du maxfltp = {D(0x47efffff, 0xf0000000)};
00089
00090 static const fu Qnan = {QNANF};
00091
00092 static const fu Inf = {0x7f800000};
00093
00094 #ifndef _HDW_SQRT
00095
00096 #define MAGIC 0x5fe6eb3b
00097
00098 #endif
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 float
00111 __hypotf( float x, float y )
00112 {
00113 int n;
00114 int ix, iy;
00115 int xptx, xpty;
00116 double dx, dy;
00117 double z, zsq, zsqby2;
00118 double q, Q;
00119 #ifdef _CALL_MATHERR
00120 struct exception exstruct;
00121 #endif
00122
00123
00124
00125
00126
00127 FLT2INT(x, ix);
00128 xptx = (ix >> MANTWIDTH);
00129 xptx &= 0xff;
00130
00131 FLT2INT(y, iy);
00132 xpty = (iy >> MANTWIDTH);
00133 xpty &= 0xff;
00134
00135 if ( (xptx < 0xff) && (xpty < 0xff) )
00136 {
00137
00138
00139 if ( xptx > xpty + 12 )
00140 return ( fabsf(x) );
00141
00142 if ( xpty > xptx + 12 )
00143 return ( fabsf(y) );
00144
00145 if ( y == 0.0f )
00146 return ( fabsf(x) );
00147
00148 if ( x == 0.0f )
00149 return ( fabsf(y) );
00150
00151 dx = x;
00152 dy = y;
00153
00154 zsq = dx*dx + dy*dy;
00155
00156 #ifdef _HDW_SQRT
00157
00158 z = sqrt(zsq);
00159 #else
00160
00161
00162
00163
00164
00165
00166
00167
00168 z = 0.0;
00169 DBLHI2INT(zsq, n);
00170 n >>= 1;
00171 n = MAGIC - n;
00172 INT2DBLHI(n, z);
00173 zsqby2 = 0.5*zsq;
00174
00175
00176
00177 z = z*(1.5 - zsqby2*z*z);
00178 z = z*(1.5 - zsqby2*z*z);
00179
00180
00181
00182 q = zsqby2*z;
00183 Q = q + q;
00184 z = Q*(1.5 - q*z);
00185 #endif
00186
00187
00188
00189
00190
00191 if ( z >= maxfltp.d )
00192 {
00193 #ifdef _CALL_MATHERR
00194 exstruct.type = OVERFLOW;
00195 exstruct.name = "hypotf";
00196 exstruct.arg1 = x;
00197 exstruct.arg2 = y;
00198 exstruct.retval = Inf.f;
00199
00200 if ( matherr( &exstruct ) == 0 )
00201 {
00202 fprintf(stderr, "overflow range error in hypotf\n");
00203 SETERRNO(ERANGE);
00204 }
00205
00206 return ( exstruct.retval );
00207 #else
00208 SETERRNO(ERANGE);
00209
00210 return ( Inf.f );
00211 #endif
00212 }
00213 else
00214 {
00215 return ( (float)z );
00216 }
00217 }
00218
00219
00220
00221 if ( (fabsf(x) == Inf.f) || (fabsf(y) == Inf.f) )
00222 {
00223 return ( Inf.f );
00224 }
00225
00226
00227
00228 #ifdef _CALL_MATHERR
00229
00230 exstruct.type = DOMAIN;
00231 exstruct.name = "hypotf";
00232 exstruct.arg1 = x;
00233 exstruct.arg2 = y;
00234 exstruct.retval = Qnan.f;
00235
00236 if ( matherr( &exstruct ) == 0 )
00237 {
00238 fprintf(stderr, "domain error in hypotf\n");
00239 SETERRNO(EDOM);
00240 }
00241
00242 return ( exstruct.retval );
00243 #else
00244 NAN_SETERRNO(EDOM);
00245
00246 return ( Qnan.f );
00247 #endif
00248 }
00249