133965Sjdp#include <ansidecl.h>
233965Sjdp
333965Sjdp#ifdef __IEEE_BIG_ENDIAN
433965Sjdp
533965Sjdptypedef union
633965Sjdp{
733965Sjdp  double value;
833965Sjdp  struct
933965Sjdp  {
1033965Sjdp    unsigned int sign : 1;
1133965Sjdp    unsigned int exponent: 11;
1233965Sjdp    unsigned int fraction0:4;
1333965Sjdp    unsigned int fraction1:16;
1433965Sjdp    unsigned int fraction2:16;
1533965Sjdp    unsigned int fraction3:16;
1633965Sjdp
1733965Sjdp  } number;
1833965Sjdp  struct
1933965Sjdp  {
2033965Sjdp    unsigned int sign : 1;
2133965Sjdp    unsigned int exponent: 11;
2233965Sjdp    unsigned int quiet:1;
2333965Sjdp    unsigned int function0:3;
2433965Sjdp    unsigned int function1:16;
2533965Sjdp    unsigned int function2:16;
2633965Sjdp    unsigned int function3:16;
2733965Sjdp  } nan;
2833965Sjdp  struct
2933965Sjdp  {
3033965Sjdp    unsigned long msw;
3133965Sjdp    unsigned long lsw;
3233965Sjdp  } parts;
3333965Sjdp    long aslong[2];
3433965Sjdp} __ieee_double_shape_type;
3533965Sjdp
3633965Sjdp#endif
3733965Sjdp
3833965Sjdp#ifdef __IEEE_LITTLE_ENDIAN
3933965Sjdp
4033965Sjdptypedef union
4133965Sjdp{
4233965Sjdp  double value;
4333965Sjdp  struct
4433965Sjdp  {
4533965Sjdp#ifdef __SMALL_BITFIELDS
4633965Sjdp    unsigned int fraction3:16;
4733965Sjdp    unsigned int fraction2:16;
4833965Sjdp    unsigned int fraction1:16;
4933965Sjdp    unsigned int fraction0: 4;
5033965Sjdp#else
5133965Sjdp    unsigned int fraction1:32;
5233965Sjdp    unsigned int fraction0:20;
5333965Sjdp#endif
5433965Sjdp    unsigned int exponent :11;
5533965Sjdp    unsigned int sign     : 1;
5633965Sjdp  } number;
5733965Sjdp  struct
5833965Sjdp  {
5933965Sjdp#ifdef __SMALL_BITFIELDS
6033965Sjdp    unsigned int function3:16;
6133965Sjdp    unsigned int function2:16;
6233965Sjdp    unsigned int function1:16;
6333965Sjdp    unsigned int function0:3;
6433965Sjdp#else
6533965Sjdp    unsigned int function1:32;
6633965Sjdp    unsigned int function0:19;
6733965Sjdp#endif
6833965Sjdp    unsigned int quiet:1;
6933965Sjdp    unsigned int exponent: 11;
7033965Sjdp    unsigned int sign : 1;
7133965Sjdp  } nan;
7233965Sjdp  struct
7333965Sjdp  {
7433965Sjdp    unsigned long lsw;
7533965Sjdp    unsigned long msw;
7633965Sjdp  } parts;
7733965Sjdp
7833965Sjdp  long aslong[2];
7933965Sjdp
8033965Sjdp} __ieee_double_shape_type;
8133965Sjdp
8233965Sjdp#endif
8333965Sjdp
8433965Sjdp#ifdef __IEEE_BIG_ENDIAN
8533965Sjdptypedef union
8633965Sjdp{
8733965Sjdp  float value;
8833965Sjdp  struct
8933965Sjdp  {
9033965Sjdp    unsigned int sign : 1;
9133965Sjdp    unsigned int exponent: 8;
9233965Sjdp    unsigned int fraction0: 7;
9333965Sjdp    unsigned int fraction1: 16;
9433965Sjdp  } number;
9533965Sjdp  struct
9633965Sjdp  {
9733965Sjdp    unsigned int sign:1;
9833965Sjdp    unsigned int exponent:8;
9933965Sjdp    unsigned int quiet:1;
10033965Sjdp    unsigned int function0:6;
10133965Sjdp    unsigned int function1:16;
10233965Sjdp  } nan;
10333965Sjdp  long p1;
10433965Sjdp
10533965Sjdp} __ieee_float_shape_type;
10633965Sjdp#endif
10733965Sjdp
10833965Sjdp#ifdef __IEEE_LITTLE_ENDIAN
10933965Sjdptypedef union
11033965Sjdp{
11133965Sjdp  float value;
11233965Sjdp  struct
11333965Sjdp  {
11433965Sjdp    unsigned int fraction0: 7;
11533965Sjdp    unsigned int fraction1: 16;
11633965Sjdp    unsigned int exponent: 8;
11733965Sjdp    unsigned int sign : 1;
11833965Sjdp  } number;
11933965Sjdp  struct
12033965Sjdp  {
12133965Sjdp    unsigned int function1:16;
12233965Sjdp    unsigned int function0:6;
12333965Sjdp    unsigned int quiet:1;
12433965Sjdp    unsigned int exponent:8;
12533965Sjdp    unsigned int sign:1;
12633965Sjdp  } nan;
12733965Sjdp  long p1;
12833965Sjdp
12933965Sjdp} __ieee_float_shape_type;
13033965Sjdp#endif
13133965Sjdp
13289857Sobrien#if defined(__IEEE_BIG_ENDIAN) || defined(__IEEE_LITTLE_ENDIAN)
13333965Sjdp
134130561Sobriendouble
135218822Sdimcopysign (double x, double y)
13633965Sjdp{
13733965Sjdp  __ieee_double_shape_type a,b;
13833965Sjdp  b.value = y;
13933965Sjdp  a.value = x;
14033965Sjdp  a.number.sign =b.number.sign;
14133965Sjdp  return a.value;
14233965Sjdp}
14389857Sobrien
14489857Sobrien#else
14589857Sobrien
146130561Sobriendouble
147218822Sdimcopysign (double x, double y)
14889857Sobrien{
14989857Sobrien  if ((x < 0 && y > 0) || (x > 0 && y < 0))
15089857Sobrien    return -x;
15189857Sobrien  return x;
15289857Sobrien}
15389857Sobrien
15489857Sobrien#endif
155