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 #ifndef __math_68881
00043 #define __math_68881
00044
00045 #include <errno.h>
00046
00047 #undef HUGE_VAL
00048 #ifdef __sun__
00049
00050 #define HUGE_VAL \
00051 ({ \
00052 static union { int i[2]; double d; } u = { {0x7ff00000, 0} }; \
00053 u.d; \
00054 })
00055 #else
00056 #define HUGE_VAL \
00057 ({ \
00058 double huge_val; \
00059 \
00060 __asm ("fmove%.d %#0x7ff0000000000000,%0" \
00061 : "=f" (huge_val) \
00062 : ); \
00063 huge_val; \
00064 })
00065 #endif
00066
00067 __inline extern double
00068 sin (double x)
00069 {
00070 double value;
00071
00072 __asm ("fsin%.x %1,%0"
00073 : "=f" (value)
00074 : "f" (x));
00075 return value;
00076 }
00077
00078 __inline extern double
00079 cos (double x)
00080 {
00081 double value;
00082
00083 __asm ("fcos%.x %1,%0"
00084 : "=f" (value)
00085 : "f" (x));
00086 return value;
00087 }
00088
00089 __inline extern double
00090 tan (double x)
00091 {
00092 double value;
00093
00094 __asm ("ftan%.x %1,%0"
00095 : "=f" (value)
00096 : "f" (x));
00097 return value;
00098 }
00099
00100 __inline extern double
00101 asin (double x)
00102 {
00103 double value;
00104
00105 __asm ("fasin%.x %1,%0"
00106 : "=f" (value)
00107 : "f" (x));
00108 return value;
00109 }
00110
00111 __inline extern double
00112 acos (double x)
00113 {
00114 double value;
00115
00116 __asm ("facos%.x %1,%0"
00117 : "=f" (value)
00118 : "f" (x));
00119 return value;
00120 }
00121
00122 __inline extern double
00123 atan (double x)
00124 {
00125 double value;
00126
00127 __asm ("fatan%.x %1,%0"
00128 : "=f" (value)
00129 : "f" (x));
00130 return value;
00131 }
00132
00133 __inline extern double
00134 atan2 (double y, double x)
00135 {
00136 double pi, pi_over_2;
00137
00138 __asm ("fmovecr%.x %#0,%0"
00139 : "=f" (pi)
00140 : );
00141 __asm ("fscale%.b %#-1,%0"
00142 : "=f" (pi_over_2)
00143 : "0" (pi));
00144 if (x > 0)
00145 {
00146 if (y > 0)
00147 {
00148 if (x > y)
00149 return atan (y / x);
00150 else
00151 return pi_over_2 - atan (x / y);
00152 }
00153 else
00154 {
00155 if (x > -y)
00156 return atan (y / x);
00157 else
00158 return - pi_over_2 - atan (x / y);
00159 }
00160 }
00161 else
00162 {
00163 if (y < 0)
00164 {
00165 if (-x > -y)
00166 return - pi + atan (y / x);
00167 else
00168 return - pi_over_2 - atan (x / y);
00169 }
00170 else
00171 {
00172 if (-x > y)
00173 return pi + atan (y / x);
00174 else if (y > 0)
00175 return pi_over_2 - atan (x / y);
00176 else
00177 {
00178 double value;
00179
00180 errno = EDOM;
00181 __asm ("fmove%.d %#0x7fffffffffffffff,%0"
00182 : "=f" (value)
00183 : );
00184 return value;
00185 }
00186 }
00187 }
00188 }
00189
00190 __inline extern double
00191 sinh (double x)
00192 {
00193 double value;
00194
00195 __asm ("fsinh%.x %1,%0"
00196 : "=f" (value)
00197 : "f" (x));
00198 return value;
00199 }
00200
00201 __inline extern double
00202 cosh (double x)
00203 {
00204 double value;
00205
00206 __asm ("fcosh%.x %1,%0"
00207 : "=f" (value)
00208 : "f" (x));
00209 return value;
00210 }
00211
00212 __inline extern double
00213 tanh (double x)
00214 {
00215 double value;
00216
00217 __asm ("ftanh%.x %1,%0"
00218 : "=f" (value)
00219 : "f" (x));
00220 return value;
00221 }
00222
00223 __inline extern double
00224 atanh (double x)
00225 {
00226 double value;
00227
00228 __asm ("fatanh%.x %1,%0"
00229 : "=f" (value)
00230 : "f" (x));
00231 return value;
00232 }
00233
00234 __inline extern double
00235 exp (double x)
00236 {
00237 double value;
00238
00239 __asm ("fetox%.x %1,%0"
00240 : "=f" (value)
00241 : "f" (x));
00242 return value;
00243 }
00244
00245 __inline extern double
00246 expm1 (double x)
00247 {
00248 double value;
00249
00250 __asm ("fetoxm1%.x %1,%0"
00251 : "=f" (value)
00252 : "f" (x));
00253 return value;
00254 }
00255
00256 __inline extern double
00257 log (double x)
00258 {
00259 double value;
00260
00261 __asm ("flogn%.x %1,%0"
00262 : "=f" (value)
00263 : "f" (x));
00264 return value;
00265 }
00266
00267 __inline extern double
00268 log1p (double x)
00269 {
00270 double value;
00271
00272 __asm ("flognp1%.x %1,%0"
00273 : "=f" (value)
00274 : "f" (x));
00275 return value;
00276 }
00277
00278 __inline extern double
00279 log10 (double x)
00280 {
00281 double value;
00282
00283 __asm ("flog10%.x %1,%0"
00284 : "=f" (value)
00285 : "f" (x));
00286 return value;
00287 }
00288
00289 __inline extern double
00290 sqrt (double x)
00291 {
00292 double value;
00293
00294 __asm ("fsqrt%.x %1,%0"
00295 : "=f" (value)
00296 : "f" (x));
00297 return value;
00298 }
00299
00300 __inline extern double
00301 hypot (double x, double y)
00302 {
00303 return sqrt (x*x + y*y);
00304 }
00305
00306 __inline extern double
00307 pow (double x, double y)
00308 {
00309 if (x > 0)
00310 return exp (y * log (x));
00311 else if (x == 0)
00312 {
00313 if (y > 0)
00314 return 0.0;
00315 else
00316 {
00317 double value;
00318
00319 errno = EDOM;
00320 __asm ("fmove%.d %#0x7fffffffffffffff,%0"
00321 : "=f" (value)
00322 : );
00323 return value;
00324 }
00325 }
00326 else
00327 {
00328 double temp;
00329
00330 __asm ("fintrz%.x %1,%0"
00331 : "=f" (temp)
00332 : "f" (y));
00333 if (y == temp)
00334 {
00335 int i = (int) y;
00336
00337 if ((i & 1) == 0)
00338 return exp (y * log (-x));
00339 else
00340 return - exp (y * log (-x));
00341 }
00342 else
00343 {
00344 double value;
00345
00346 errno = EDOM;
00347 __asm ("fmove%.d %#0x7fffffffffffffff,%0"
00348 : "=f" (value)
00349 : );
00350 return value;
00351 }
00352 }
00353 }
00354
00355 __inline extern double
00356 fabs (double x)
00357 {
00358 double value;
00359
00360 __asm ("fabs%.x %1,%0"
00361 : "=f" (value)
00362 : "f" (x));
00363 return value;
00364 }
00365
00366 __inline extern double
00367 ceil (double x)
00368 {
00369 int rounding_mode, round_up;
00370 double value;
00371
00372 __asm volatile ("fmove%.l %!,%0"
00373 : "=dm" (rounding_mode)
00374 : );
00375 round_up = rounding_mode | 0x30;
00376 __asm volatile ("fmove%.l %0,%!"
00377 :
00378 : "dmi" (round_up));
00379 __asm volatile ("fint%.x %1,%0"
00380 : "=f" (value)
00381 : "f" (x));
00382 __asm volatile ("fmove%.l %0,%!"
00383 :
00384 : "dmi" (rounding_mode));
00385 return value;
00386 }
00387
00388 __inline extern double
00389 floor (double x)
00390 {
00391 int rounding_mode, round_down;
00392 double value;
00393
00394 __asm volatile ("fmove%.l %!,%0"
00395 : "=dm" (rounding_mode)
00396 : );
00397 round_down = (rounding_mode & ~0x10)
00398 | 0x20;
00399 __asm volatile ("fmove%.l %0,%!"
00400 :
00401 : "dmi" (round_down));
00402 __asm volatile ("fint%.x %1,%0"
00403 : "=f" (value)
00404 : "f" (x));
00405 __asm volatile ("fmove%.l %0,%!"
00406 :
00407 : "dmi" (rounding_mode));
00408 return value;
00409 }
00410
00411 __inline extern double
00412 rint (double x)
00413 {
00414 int rounding_mode, round_nearest;
00415 double value;
00416
00417 __asm volatile ("fmove%.l %!,%0"
00418 : "=dm" (rounding_mode)
00419 : );
00420 round_nearest = rounding_mode & ~0x30;
00421 __asm volatile ("fmove%.l %0,%!"
00422 :
00423 : "dmi" (round_nearest));
00424 __asm volatile ("fint%.x %1,%0"
00425 : "=f" (value)
00426 : "f" (x));
00427 __asm volatile ("fmove%.l %0,%!"
00428 :
00429 : "dmi" (rounding_mode));
00430 return value;
00431 }
00432
00433 __inline extern double
00434 fmod (double x, double y)
00435 {
00436 double value;
00437
00438 __asm ("fmod%.x %2,%0"
00439 : "=f" (value)
00440 : "0" (x),
00441 "f" (y));
00442 return value;
00443 }
00444
00445 __inline extern double
00446 drem (double x, double y)
00447 {
00448 double value;
00449
00450 __asm ("frem%.x %2,%0"
00451 : "=f" (value)
00452 : "0" (x),
00453 "f" (y));
00454 return value;
00455 }
00456
00457 __inline extern double
00458 scalb (double x, int n)
00459 {
00460 double value;
00461
00462 __asm ("fscale%.l %2,%0"
00463 : "=f" (value)
00464 : "0" (x),
00465 "dmi" (n));
00466 return value;
00467 }
00468
00469 __inline extern double
00470 logb (double x)
00471 {
00472 double exponent;
00473
00474 __asm ("fgetexp%.x %1,%0"
00475 : "=f" (exponent)
00476 : "f" (x));
00477 return exponent;
00478 }
00479
00480 __inline extern double
00481 ldexp (double x, int n)
00482 {
00483 double value;
00484
00485 __asm ("fscale%.l %2,%0"
00486 : "=f" (value)
00487 : "0" (x),
00488 "dmi" (n));
00489 return value;
00490 }
00491
00492 __inline extern double
00493 frexp (double x, int *exp)
00494 {
00495 double float_exponent;
00496 int int_exponent;
00497 double mantissa;
00498
00499 __asm ("fgetexp%.x %1,%0"
00500 : "=f" (float_exponent)
00501 : "f" (x));
00502 int_exponent = (int) float_exponent;
00503 __asm ("fgetman%.x %1,%0"
00504 : "=f" (mantissa)
00505 : "f" (x));
00506 if (mantissa != 0)
00507 {
00508 __asm ("fscale%.b %#-1,%0"
00509 : "=f" (mantissa)
00510 : "0" (mantissa));
00511 int_exponent += 1;
00512 }
00513 *exp = int_exponent;
00514 return mantissa;
00515 }
00516
00517 __inline extern double
00518 modf (double x, double *ip)
00519 {
00520 double temp;
00521
00522 __asm ("fintrz%.x %1,%0"
00523 : "=f" (temp)
00524 : "f" (x));
00525 *ip = temp;
00526 return x - temp;
00527 }
00528
00529 #endif