home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / unixlib / internal / h / math next >
Encoding:
Text File  |  2006-09-17  |  13.7 KB  |  539 lines

  1. /*
  2.  * ====================================================
  3.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4.  *
  5.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  6.  * Permission to use, copy, modify, and distribute this
  7.  * software is freely granted, provided that this notice
  8.  * is preserved.
  9.  * ====================================================
  10.  */
  11.  
  12. #ifndef __INTERNAL_MATH_H
  13. #define __INTERNAL_MATH_H
  14.  
  15. #ifndef __UNIXLIB_TYPES_H
  16. #include <unixlib/types.h>
  17. #endif
  18. #include <endian.h>
  19. #include <stdint.h>
  20.  
  21. __BEGIN_DECLS
  22.  
  23. /* The original fdlibm code used statements like:
  24.     n0 = ((*(int*)&one)>>29)^1;        * index of high word *
  25.     ix0 = *(n0+(int*)&x);            * high word of x *
  26.     ix1 = *((1-n0)+(int*)&x);        * low word of x *
  27.    to dig two 32 bit words out of the 64 bit IEEE floating point
  28.    value.  That is non-ANSI, and, moreover, the gcc instruction
  29.    scheduler gets it wrong.  We instead use the following macros.
  30.    Unlike the original code, we determine the endianness at compile
  31.    time, not at run time; I don't see much benefit to selecting
  32.    endianness at run time.  */
  33.  
  34. /* A union which permits us to convert between a double and two 32 bit
  35.    ints.  */
  36.  
  37. #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  38.  
  39. typedef union
  40. {
  41.   double value;
  42.   struct
  43.   {
  44.     __uint32_t msw;
  45.     __uint32_t lsw;
  46.   } parts;
  47. } ieee_double_shape_type;
  48.  
  49. #endif
  50.  
  51. #if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
  52.  
  53. typedef union
  54. {
  55.   double value;
  56.   struct
  57.   {
  58.     __uint32_t lsw;
  59.     __uint32_t msw;
  60.   } parts;
  61. } ieee_double_shape_type;
  62.  
  63. #endif
  64.  
  65. /* Get two 32 bit ints from a double.  */
  66.  
  67. #define EXTRACT_WORDS(ix0,ix1,d)                \
  68. do {                                \
  69.   ieee_double_shape_type ew_u;                    \
  70.   ew_u.value = (d);                        \
  71.   (ix0) = ew_u.parts.msw;                    \
  72.   (ix1) = ew_u.parts.lsw;                    \
  73. } while (0)
  74.  
  75. /* Get the more significant 32 bit int from a double.  */
  76.  
  77. #define GET_HIGH_WORD(i,d)                    \
  78. do {                                \
  79.   ieee_double_shape_type gh_u;                    \
  80.   gh_u.value = (d);                        \
  81.   (i) = gh_u.parts.msw;                        \
  82. } while (0)
  83.  
  84. /* Get the less significant 32 bit int from a double.  */
  85.  
  86. #define GET_LOW_WORD(i,d)                    \
  87. do {                                \
  88.   ieee_double_shape_type gl_u;                    \
  89.   gl_u.value = (d);                        \
  90.   (i) = gl_u.parts.lsw;                        \
  91. } while (0)
  92.  
  93. /* Set a double from two 32 bit ints.  */
  94.  
  95. #define INSERT_WORDS(d,ix0,ix1)                    \
  96. do {                                \
  97.   ieee_double_shape_type iw_u;                    \
  98.   iw_u.parts.msw = (ix0);                    \
  99.   iw_u.parts.lsw = (ix1);                    \
  100.   (d) = iw_u.value;                        \
  101. } while (0)
  102.  
  103. /* Set the more significant 32 bits of a double from an int.  */
  104.  
  105. #define SET_HIGH_WORD(d,v)                    \
  106. do {                                \
  107.   ieee_double_shape_type sh_u;                    \
  108.   sh_u.value = (d);                        \
  109.   sh_u.parts.msw = (v);                        \
  110.   (d) = sh_u.value;                        \
  111. } while (0)
  112.  
  113. /* Set the less significant 32 bits of a double from an int.  */
  114.  
  115. #define SET_LOW_WORD(d,v)                    \
  116. do {                                \
  117.   ieee_double_shape_type sl_u;                    \
  118.   sl_u.value = (d);                        \
  119.   sl_u.parts.lsw = (v);                        \
  120.   (d) = sl_u.value;                        \
  121. } while (0)
  122.  
  123. /* A union which permits us to convert between a float and a 32 bit
  124.    int.  */
  125.  
  126. typedef union
  127. {
  128.   float value;
  129.   __uint32_t word;
  130. } ieee_float_shape_type;
  131.  
  132. /* Get a 32 bit int from a float.  */
  133.  
  134. #define GET_FLOAT_WORD(i,d)                    \
  135. do {                                \
  136.   ieee_float_shape_type gf_u;                    \
  137.   gf_u.value = (d);                        \
  138.   (i) = gf_u.word;                        \
  139. } while (0)
  140.  
  141. /* Set a float from a 32 bit int.  */
  142.  
  143. #define SET_FLOAT_WORD(d,i)                    \
  144. do {                                \
  145.   ieee_float_shape_type sf_u;                    \
  146.   sf_u.word = (i);                        \
  147.   (d) = sf_u.value;                        \
  148. } while (0)
  149.  
  150. /* A union which permits us to convert between a long double and
  151.    three 32 bit ints.  */
  152.  
  153. #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  154.  
  155. typedef union
  156. {
  157.   long double value;
  158.   struct
  159.   {
  160.     unsigned int exponent:15;
  161.     unsigned int empty:16;
  162.     unsigned int sign:1;
  163.     __uint32_t msw;
  164.     __uint32_t lsw;
  165.   } parts;
  166. } ieee_long_double_shape_type;
  167.  
  168. #endif
  169.  
  170. #if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
  171.  
  172. typedef union
  173. {
  174.   long double value;
  175.   struct
  176.   {
  177.     __uint32_t lsw;
  178.     __uint32_t msw;
  179.     unsigned int exponent:15;
  180.     unsigned int sign:1;
  181.     unsigned int empty:16;
  182.   } parts;
  183. } ieee_long_double_shape_type;
  184.  
  185. #endif
  186.  
  187. /* Get three 32 bit ints from a double. Hacked for ARM FPA.  */
  188.  
  189. #define GET_LDOUBLE_WORDS(exp,ix0,ix1,d)            \
  190. do {                                \
  191.   ieee_long_double_shape_type ew_u;                \
  192.   ew_u.value = (d);                        \
  193.   (exp) = ew_u.parts.exponent | (ew_u.parts.sign << 16);    \
  194.   (ix0) = ew_u.parts.msw;                    \
  195.   (ix1) = ew_u.parts.lsw;                    \
  196. } while (0)
  197.  
  198. /* Set a double from two 32 bit ints. Hacked for ARM FPA.  */
  199.  
  200. #define SET_LDOUBLE_WORDS(d,exp,ix0,ix1)            \
  201. do {                                \
  202.   ieee_long_double_shape_type iw_u;                \
  203.   iw_u.parts.sign = (exp) & (1 << 16);                \
  204.   iw_u.parts.exponent = (exp) & ((1 << 15)-1)            \
  205.   iw_u.parts.msw = (ix0);                    \
  206.   iw_u.parts.lsw = (ix1);                    \
  207.   (d) = iw_u.value;                        \
  208. } while (0)
  209.  
  210.  
  211. /* Get the more significant 32 bits of a long double mantissa.  */
  212.  
  213. #define GET_LDOUBLE_MSW(v,d)                    \
  214. do {                                \
  215.   ieee_long_double_shape_type sh_u;                \
  216.   sh_u.value = (d);                        \
  217.   (v) = sh_u.parts.msw;                        \
  218. } while (0)
  219.  
  220. /* Set the more significant 32 bits of a long double mantissa from an int.  */
  221.  
  222. #define SET_LDOUBLE_MSW(d,v)                    \
  223. do {                                \
  224.   ieee_long_double_shape_type sh_u;                \
  225.   sh_u.value = (d);                        \
  226.   sh_u.parts.msw = (v);                        \
  227.   (d) = sh_u.value;                        \
  228. } while (0)
  229.  
  230. /* Get int from the exponent of a long double.  */
  231.  
  232. #define GET_LDOUBLE_EXP(exp,d)                    \
  233. do {                                \
  234.   ieee_long_double_shape_type ge_u;                \
  235.   ge_u.value = (d);                        \
  236.   (exp) = ge_u.parts.sign_exponent;                \
  237. } while (0)
  238.  
  239. /* Set exponent of a long double from an int.  */
  240.  
  241. #define SET_LDOUBLE_EXP(d,exp)                    \
  242. do {                                \
  243.   ieee_long_double_shape_type se_u;                \
  244.   se_u.value = (d);                        \
  245.   se_u.parts.sign_exponent = (exp);                \
  246.   (d) = se_u.value;                        \
  247. } while (0)
  248.  
  249.  
  250. /* ieee style elementary functions */
  251. extern double __ieee754_sqrt (double);
  252. extern double __ieee754_acos (double);
  253. extern double __ieee754_acosh (double);
  254. extern double __ieee754_log (double);
  255. extern double __ieee754_atanh (double);
  256. extern double __ieee754_asin (double);
  257. extern double __ieee754_atan2 (double,double);
  258. extern double __ieee754_exp (double);
  259. extern double __ieee754_exp2 (double);
  260. extern double __ieee754_exp10 (double);
  261. extern double __ieee754_cosh (double);
  262. extern double __ieee754_fmod (double,double);
  263. extern double __ieee754_pow (double,double);
  264. extern double __ieee754_lgamma_r (double,int *);
  265. extern double __ieee754_gamma_r (double,int *);
  266. extern double __ieee754_lgamma (double);
  267. extern double __ieee754_gamma (double);
  268. extern double __ieee754_log10 (double);
  269. extern double __ieee754_log2 (double);
  270. extern double __ieee754_sinh (double);
  271. extern double __ieee754_hypot (double,double);
  272. extern double __ieee754_j0 (double);
  273. extern double __ieee754_j1 (double);
  274. extern double __ieee754_y0 (double);
  275. extern double __ieee754_y1 (double);
  276. extern double __ieee754_jn (int,double);
  277. extern double __ieee754_yn (int,double);
  278. extern double __ieee754_remainder (double,double);
  279. extern int32_t __ieee754_rem_pio2 (double,double*);
  280. extern double __ieee754_scalb (double,double);
  281.  
  282. /* fdlibm kernel function */
  283. extern double __kernel_standard (double,double,int);
  284. extern double __kernel_sin (double,double,int);
  285. extern double __kernel_cos (double,double);
  286. extern double __kernel_tan (double,double,int);
  287. extern int    __kernel_rem_pio2 (double*,double*,int,int,int, const int32_t*);
  288.  
  289. /* internal functions.  */
  290. extern double __copysign (double x, double __y);
  291.  
  292.  
  293. /* ieee style elementary float functions */
  294. extern float __ieee754_sqrtf (float);
  295. extern float __ieee754_acosf (float);
  296. extern float __ieee754_acoshf (float);
  297. extern float __ieee754_logf (float);
  298. extern float __ieee754_atanhf (float);
  299. extern float __ieee754_asinf (float);
  300. extern float __ieee754_atan2f (float,float);
  301. extern float __ieee754_expf (float);
  302. extern float __ieee754_exp2f (float);
  303. extern float __ieee754_exp10f (float);
  304. extern float __ieee754_coshf (float);
  305. extern float __ieee754_fmodf (float,float);
  306. extern float __ieee754_powf (float,float);
  307. extern float __ieee754_lgammaf_r (float,int *);
  308. extern float __ieee754_gammaf_r (float,int *);
  309. extern float __ieee754_lgammaf (float);
  310. extern float __ieee754_gammaf (float);
  311. extern float __ieee754_log10f (float);
  312. extern float __ieee754_log2f (float);
  313. extern float __ieee754_sinhf (float);
  314. extern float __ieee754_hypotf (float,float);
  315. extern float __ieee754_j0f (float);
  316. extern float __ieee754_j1f (float);
  317. extern float __ieee754_y0f (float);
  318. extern float __ieee754_y1f (float);
  319. extern float __ieee754_jnf (int,float);
  320. extern float __ieee754_ynf (int,float);
  321. extern float __ieee754_remainderf (float,float);
  322. extern int32_t __ieee754_rem_pio2f (float,float*);
  323. extern float __ieee754_scalbf (float,float);
  324.  
  325.  
  326. /* float versions of fdlibm kernel functions */
  327. extern float __kernel_sinf (float,float,int);
  328. extern float __kernel_cosf (float,float);
  329. extern float __kernel_tanf (float,float,int);
  330. extern int   __kernel_rem_pio2f (float*,float*,int,int,int, const int32_t*);
  331.  
  332. /* internal functions.  */
  333. extern float __copysignf (float x, float __y);
  334.  
  335. /* Prototypes for functions of the IBM Accurate Mathematical Library.  */
  336. extern double __exp1 (double __x, double __xx, double __error);
  337. extern double __sin (double __x);
  338. extern double __cos (double __x);
  339. extern int __branred (double __x, double *__a, double *__aa);
  340. extern void __doasin (double __x, double __dx, double __v[]);
  341. extern void __dubsin (double __x, double __dx, double __v[]);
  342. extern void __dubcos (double __x, double __dx, double __v[]);
  343. extern double __halfulp (double __x, double __y);
  344. extern double __sin32 (double __x, double __res, double __res1);
  345. extern double __cos32 (double __x, double __res, double __res1);
  346. extern double __mpsin (double __x, double __dx);
  347. extern double __mpcos (double __x, double __dx);
  348. extern double __mpsin1 (double __x);
  349. extern double __mpcos1 (double __x);
  350. extern double __slowexp (double __x);
  351. extern double __slowpow (double __x, double __y, double __z);
  352. extern void __docos (double __x, double __dx, double __v[]);
  353.  
  354. #if defined (__CC_NORCROFT)
  355. /* The Norcroft compiler doesn't support the idea of symbol aliasing,
  356.    or at least allowing us to pass such aliases to the assembler.  */
  357.  
  358. #define __acos acos
  359. #define __asin asin
  360. #define __atan atan
  361. #define __atan2 atan2
  362. #define __cos cos
  363. #define __sin sin
  364. #define __tan tan
  365. #define __cosh cosh
  366. #define __sinh sinh
  367. #define __tanh tanh
  368. #define __sincos sincos
  369. #define __acosh acosh
  370. #define __asinh asinh
  371. #define __atanh atanh
  372. #define __exp exp
  373. #define __frexp frexp
  374. #define __ldexp ldexp
  375. #define __log log
  376. #define __log10 log10
  377. #define __modf modf
  378. #define __exp10 exp10
  379. #define __pow10 pow10
  380. #define __expm1 expm1
  381. #define __log1p log1p
  382. #define __logb logb
  383. #define __exp2 exp2
  384. #define __log2 log2
  385. #define __pow pow
  386. #define __sqrt sqrt
  387. #define __hypot hypot
  388. #define __cbrt cbrt
  389. #define __ceil ceil
  390. #define __fabs fabs
  391. #define __floor floor
  392. #define __fmod fmod
  393. #define __isinf isinf
  394. #define __finite finite
  395. #define __drem drem
  396. #define __significand significand
  397. #define __copysign copysign
  398. #define __nan nan
  399. #define __isnan isnan
  400. #define __j0 j0
  401. #define __j1 j1
  402. #define __jn jn
  403. #define __y0 y0
  404. #define __y1 y1
  405. #define __yn yn
  406. #define __erf erf
  407. #define __erfc erfc
  408. #define __lgamma lgamma
  409. #define __tgamma tgamma
  410. #define __gamma gamma
  411. #define __lgamma_r lgamma_r
  412. #define __rint rint
  413. #define __nextafter nextafter
  414. #define __nexttoward nexttoward
  415. #define __remainder remainder
  416. #define __scalbn scalbn
  417. #define __ilogb ilogb
  418. #define __scalbln scalbln
  419. #define __nearbyint nearbyint
  420. #define __round round
  421. #define __trunc trunc
  422. #define __remquo remquo
  423. #define __lrint lrint
  424. #define __lround lround
  425. #define __fdim fdim
  426. #define __fmax fmax
  427. #define __fmin fmin
  428. #define __fma fma
  429. #define __scalb scalb
  430.  
  431. #define __acosf acosf
  432. #define __asinf asinf
  433. #define __atanf atanf
  434. #define __atan2f atan2f
  435. #define __cosf cosf
  436. #define __sinf sinf
  437. #define __tanf tanf
  438. #define __coshf coshf
  439. #define __sinhf sinhf
  440. #define __tanhf tanhf
  441. #define __sincosf sincosf
  442. #define __acoshf acoshf
  443. #define __asinhf asinhf
  444. #define __atanhf atanhf
  445. #define __expf expf
  446. #define __frexpf frexpf
  447. #define __ldexpf ldexpf
  448. #define __logf logf
  449. #define __log10f log10f
  450. #define __modff modff
  451. #define __exp10f exp10f
  452. #define __pow10f pow10f
  453. #define __expm1f expm1f
  454. #define __log1pf log1pf
  455. #define __logbf logbf
  456. #define __exp2f exp2f
  457. #define __log2f log2f
  458. #define __powf powf
  459. #define __sqrtf sqrtf
  460. #define __hypotf hypotf
  461. #define __cbrtf cbrtf
  462. #define __ceilf ceilf
  463. #define __fabsf fabsf
  464. #define __floorf floorf
  465. #define __fmodf fmodf
  466. #define __isinff isinff
  467. #define __finitef finitef
  468. #define __dremf dremf
  469. #define __significandf significandf
  470. #define __copysignf copysignf
  471. #define __nanf nanf
  472. #define __isnanf isnanf
  473. #define __j0f j0f
  474. #define __j1f j1f
  475. #define __jnf jnf
  476. #define __y0f y0f
  477. #define __y1f y1f
  478. #define __ynf ynf
  479. #define __erff erff
  480. #define __erfcf erfcf
  481. #define __lgammaf lgammaf
  482. #define __tgammaf tgammaf
  483. #define __gammaf gammaf
  484. #define __lgammaf_r lgammaf_r
  485. #define __rintf rintf
  486. #define __nextafterf nextafterf
  487. #define __nexttowardf nexttowardf
  488. #define __remainderf remainderf
  489. #define __scalbnf scalbnf
  490. #define __ilogbf ilogbf
  491. #define __scalblnf scalblnf
  492. #define __nearbyintf nearbyintf
  493. #define __roundf roundf
  494. #define __truncf truncf
  495. #define __remquof remquof
  496. #define __lrintf lrintf
  497. #define __llrintf llrintf
  498. #define __lroundf lroundf
  499. #define __llroundf llroundf
  500. #define __fdimf fdimf
  501. #define __fmaxf fmaxf
  502. #define __fminf fminf
  503. #define __fmaf fmaf
  504.  
  505.  
  506. #define __cacos cacos
  507. #define __casin casin
  508. #define __catan catan
  509. #define __ccos ccos
  510. #define __csin csin
  511. #define __ctan ctan
  512. #define __cacosh cacosh
  513. #define __casinh casinh
  514. #define __catanh catanh
  515. #define __ccosh ccosh
  516. #define __csinh csinh
  517. #define __ctanh ctanh
  518. #define __cexp cexp
  519. #define __clog clog
  520. #define __clog10 clog10
  521. #define __cpow cpow
  522. #define __csqrt csqrt
  523. #define __cabs cabs
  524. #define __carg carg
  525. #define __conj conj
  526. #define __cproj cproj
  527. #define __cimag cimag
  528. #define __creal creal
  529.  
  530. #define __matherr matherr
  531.  
  532. #undef isnan
  533.  
  534. #endif /* __CC_NORCROFT */
  535.  
  536. __END_DECLS
  537.  
  538. #endif
  539.