1 /* This is a software floating point library which can be used instead of
2 the floating point routines in libgcc1.c for targets without hardware
5 /* Copyright (C) 1994, 1995 Free Software Foundation, Inc.
7 This file is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file with other programs, and to distribute
15 those programs without any restriction coming from the use of this
16 file. (The General Public License restrictions do apply in other
17 respects; for example, they cover modification of the file, and
18 distribution when not linked into another program.)
20 This file is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; see the file COPYING. If not, write to
27 the Free Software Foundation, 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
30 /* As a special exception, if you link this library with other files,
31 some of which are compiled with GCC, to produce an executable,
32 this library does not by itself cause the resulting executable
33 to be covered by the GNU General Public License.
34 This exception does not however invalidate any other reasons why
35 the executable file might be covered by the GNU General Public License. */
37 /* This implements IEEE 754 format arithmetic, but does not provide a
38 mechanism for setting the rounding mode, or for generating or handling
41 The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
42 Wilson, all of Cygnus Support. */
44 /* The intended way to use this file is to make two copies, add `#define FLOAT'
45 to one copy, then compile both copies and add them to libgcc.a. */
47 /* The following macros can be defined to change the behaviour of this file:
48 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
49 defined, then this file implements a `double', aka DFmode, fp library.
50 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
51 don't include float->double conversion which requires the double library.
52 This is useful only for machines which can't support doubles, e.g. some
54 CMPtype: Specify the type that floating point compares should return.
55 This defaults to SItype, aka int.
56 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
57 US Software goFast library. If this is not defined, the entry points use
58 the same names as libgcc1.c.
59 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
60 two integers to the FLO_union_type.
61 NO_NANS: Disable nan and infinity handling
62 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
65 typedef SFtype __attribute__ ((mode (SF)));
66 typedef DFtype __attribute__ ((mode (DF)));
68 typedef int HItype __attribute__ ((mode (HI)));
69 typedef int SItype __attribute__ ((mode (SI)));
70 typedef int DItype __attribute__ ((mode (DI)));
72 /* The type of the result of a fp compare */
74 #define CMPtype SItype
77 typedef unsigned int UHItype __attribute__ ((mode (HI)));
78 typedef unsigned int USItype __attribute__ ((mode (SI)));
79 typedef unsigned int UDItype __attribute__ ((mode (DI)));
81 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
82 #define MAX_USI_INT ((USItype) ~0)
91 # define GARDROUND 0x3f
92 # define GARDMASK 0x7f
97 # define EXPMAX (0xff)
98 # define QUIET_NAN 0x100000L
99 # define FRAC_NBITS 32
100 # define FRACHIGH 0x80000000L
101 # define FRACHIGH2 0xc0000000L
102 # define pack_d pack_f
103 # define unpack_d unpack_f
104 typedef USItype fractype;
105 typedef UHItype halffractype;
106 typedef SFtype FLO_type;
107 typedef SItype intfrac;
110 # define PREFIXFPDP dp
111 # define PREFIXSFDF df
113 # define GARDROUND 0x7f
114 # define GARDMASK 0xff
115 # define GARDMSB 0x80
117 # define EXPBIAS 1023
119 # define EXPMAX (0x7ff)
120 # define QUIET_NAN 0x8000000000000LL
121 # define FRAC_NBITS 64
122 # define FRACHIGH 0x8000000000000000LL
123 # define FRACHIGH2 0xc000000000000000LL
124 typedef UDItype fractype;
125 typedef USItype halffractype;
126 typedef DFtype FLO_type;
127 typedef DItype intfrac;
130 #ifdef US_SOFTWARE_GOFAST
134 # define multiply fpmul
135 # define divide fpdiv
136 # define compare fpcmp
137 # define si_to_float sitofp
138 # define float_to_si fptosi
139 # define float_to_usi fptoui
140 # define negate __negsf2
141 # define sf_to_df fptodp
142 # define dptofp dptofp
146 # define multiply dpmul
147 # define divide dpdiv
148 # define compare dpcmp
149 # define si_to_float litodp
150 # define float_to_si dptoli
151 # define float_to_usi dptoul
152 # define negate __negdf2
153 # define df_to_sf dptofp
157 # define add __addsf3
158 # define sub __subsf3
159 # define multiply __mulsf3
160 # define divide __divsf3
161 # define compare __cmpsf2
162 # define _eq_f2 __eqsf2
163 # define _ne_f2 __nesf2
164 # define _gt_f2 __gtsf2
165 # define _ge_f2 __gesf2
166 # define _lt_f2 __ltsf2
167 # define _le_f2 __lesf2
168 # define si_to_float __floatsisf
169 # define float_to_si __fixsfsi
170 # define float_to_usi __fixunssfsi
171 # define negate __negsf2
172 # define sf_to_df __extendsfdf2
174 # define add __adddf3
175 # define sub __subdf3
176 # define multiply __muldf3
177 # define divide __divdf3
178 # define compare __cmpdf2
179 # define _eq_f2 __eqdf2
180 # define _ne_f2 __nedf2
181 # define _gt_f2 __gtdf2
182 # define _ge_f2 __gedf2
183 # define _lt_f2 __ltdf2
184 # define _le_f2 __ledf2
185 # define si_to_float __floatsidf
186 # define float_to_si __fixdfsi
187 # define float_to_usi __fixunsdfsi
188 # define negate __negdf2
189 # define df_to_sf __truncdfsf2
194 #define INLINE __inline__
196 /* Preserve the sticky-bit when shifting fractions to the right. */
197 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
199 /* numeric parameters */
200 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
201 of a float and of a double. Assumes there are only two float types.
202 (double::FRAC_BITS+double::NGARGS-(float::FRAC_BITS-float::NGARDS))
204 #define F_D_BITOFF (52+8-(23+7))
207 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
208 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
209 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
246 #ifdef FLOAT_WORD_ORDER_MISMATCH
249 fractype fraction:FRACBITS __attribute__ ((packed));
250 unsigned int exp:EXPBITS __attribute__ ((packed));
251 unsigned int sign:1 __attribute__ ((packed));
256 #ifdef _DEBUG_BITFLOAT
261 unsigned int sign:1 __attribute__ ((packed));
262 unsigned int exp:EXPBITS __attribute__ ((packed));
263 fractype fraction:FRACBITS __attribute__ ((packed));
269 fractype fraction:FRACBITS __attribute__ ((packed));
270 unsigned int exp:EXPBITS __attribute__ ((packed));
271 unsigned int sign:1 __attribute__ ((packed));
281 /* IEEE "special" number predicates */
291 static fp_number_type *
294 static fp_number_type thenan;
301 isnan ( fp_number_type * x)
303 return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
308 isinf ( fp_number_type * x)
310 return x->class == CLASS_INFINITY;
317 iszero ( fp_number_type * x)
319 return x->class == CLASS_ZERO;
324 flip_sign ( fp_number_type * x)
330 pack_d ( fp_number_type * src)
333 fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
334 int sign = src->sign;
340 if (src->class == CLASS_QNAN || 1)
342 fraction |= QUIET_NAN;
345 else if (isinf (src))
350 else if (iszero (src))
355 else if (fraction == 0)
362 if (src->normal_exp < NORMAL_EXPMIN)
364 /* This number's exponent is too low to fit into the bits
365 available in the number, so we'll store 0 in the exponent and
366 shift the fraction to the right to make up for it. */
368 int shift = NORMAL_EXPMIN - src->normal_exp;
372 if (shift > FRAC_NBITS - NGARDS)
374 /* No point shifting, since it's more that 64 out. */
379 /* Shift by the value */
384 else if (src->normal_exp > EXPBIAS)
391 exp = src->normal_exp + EXPBIAS;
392 /* IF the gard bits are the all zero, but the first, then we're
393 half way between two numbers, choose the one which makes the
394 lsb of the answer 0. */
395 if ((fraction & GARDMASK) == GARDMSB)
397 if (fraction & (1 << NGARDS))
398 fraction += GARDROUND + 1;
402 /* Add a one to the guards to round up */
403 fraction += GARDROUND;
405 if (fraction >= IMPLICIT_2)
414 /* We previously used bitfields to store the number, but this doesn't
415 handle little/big endian systems conviently, so use shifts and
417 #ifdef FLOAT_WORD_ORDER_MISMATCH
418 dst.bits.fraction = fraction;
420 dst.bits.sign = sign;
422 dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
423 dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
424 dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
431 unpack_d (FLO_union_type * src, fp_number_type * dst)
433 /* We previously used bitfields to store the number, but this doesn't
434 handle little/big endian systems conviently, so use shifts and
440 #ifdef FLOAT_WORD_ORDER_MISMATCH
441 fraction = src->bits.fraction;
443 sign = src->bits.sign;
445 fraction = src->value_raw & ((((fractype)1) << FRACBITS) - (fractype)1);
446 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
447 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
453 /* Hmm. Looks like 0 */
456 /* tastes like zero */
457 dst->class = CLASS_ZERO;
461 /* Zero exponent with non zero fraction - it's denormalized,
462 so there isn't a leading implicit one - we'll shift it so
464 dst->normal_exp = exp - EXPBIAS + 1;
467 dst->class = CLASS_NUMBER;
469 while (fraction < IMPLICIT_1)
475 dst->fraction.ll = fraction;
478 else if (exp == EXPMAX)
483 /* Attached to a zero fraction - means infinity */
484 dst->class = CLASS_INFINITY;
488 /* Non zero fraction, means nan */
491 dst->class = CLASS_SNAN;
495 dst->class = CLASS_QNAN;
497 /* Keep the fraction part as the nan number */
498 dst->fraction.ll = fraction;
503 /* Nothing strange about this number */
504 dst->normal_exp = exp - EXPBIAS;
505 dst->class = CLASS_NUMBER;
506 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
510 static fp_number_type *
511 _fpadd_parts (fp_number_type * a,
513 fp_number_type * tmp)
517 /* Put commonly used fields in local variables. */
533 /* Adding infinities with opposite signs yields a NaN. */
534 if (isinf (b) && a->sign != b->sign)
551 /* Got two numbers. shift the smaller and increment the exponent till
556 a_normal_exp = a->normal_exp;
557 b_normal_exp = b->normal_exp;
558 a_fraction = a->fraction.ll;
559 b_fraction = b->fraction.ll;
561 diff = a_normal_exp - b_normal_exp;
565 if (diff < FRAC_NBITS)
567 /* ??? This does shifts one bit at a time. Optimize. */
568 while (a_normal_exp > b_normal_exp)
573 while (b_normal_exp > a_normal_exp)
581 /* Somethings's up.. choose the biggest */
582 if (a_normal_exp > b_normal_exp)
584 b_normal_exp = a_normal_exp;
589 a_normal_exp = b_normal_exp;
595 if (a->sign != b->sign)
599 tfraction = -a_fraction + b_fraction;
603 tfraction = a_fraction - b_fraction;
608 tmp->normal_exp = a_normal_exp;
609 tmp->fraction.ll = tfraction;
614 tmp->normal_exp = a_normal_exp;
615 tmp->fraction.ll = -tfraction;
617 /* and renormalize it */
619 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
621 tmp->fraction.ll <<= 1;
628 tmp->normal_exp = a_normal_exp;
629 tmp->fraction.ll = a_fraction + b_fraction;
631 tmp->class = CLASS_NUMBER;
632 /* Now the fraction is added, we have to shift down to renormalize the
635 if (tmp->fraction.ll >= IMPLICIT_2)
637 LSHIFT (tmp->fraction.ll);
645 add (FLO_type arg_a, FLO_type arg_b)
652 unpack_d ((FLO_union_type *) & arg_a, &a);
653 unpack_d ((FLO_union_type *) & arg_b, &b);
655 res = _fpadd_parts (&a, &b, &tmp);
661 sub (FLO_type arg_a, FLO_type arg_b)
668 unpack_d ((FLO_union_type *) & arg_a, &a);
669 unpack_d ((FLO_union_type *) & arg_b, &b);
673 res = _fpadd_parts (&a, &b, &tmp);
678 static fp_number_type *
679 _fpmul_parts ( fp_number_type * a,
681 fp_number_type * tmp)
688 a->sign = a->sign != b->sign;
693 b->sign = a->sign != b->sign;
700 a->sign = a->sign != b->sign;
709 b->sign = a->sign != b->sign;
714 a->sign = a->sign != b->sign;
719 b->sign = a->sign != b->sign;
723 /* Calculate the mantissa by multiplying both 64bit numbers to get a
726 fractype x = a->fraction.ll;
727 fractype ylow = b->fraction.ll;
731 #if defined(NO_DI_MODE)
733 /* ??? This does multiplies one bit at a time. Optimize. */
734 for (bit = 0; bit < FRAC_NBITS; bit++)
740 carry = (low += ylow) < ylow;
741 high += yhigh + carry;
754 /* Multiplying two 32 bit numbers to get a 64 bit number on
755 a machine with DI, so we're safe */
757 DItype answer = (DItype)(a->fraction.ll) * (DItype)(b->fraction.ll);
763 /* Doing a 64*64 to 128 */
765 UDItype nl = a->fraction.ll & 0xffffffff;
766 UDItype nh = a->fraction.ll >> 32;
767 UDItype ml = b->fraction.ll & 0xffffffff;
768 UDItype mh = b->fraction.ll >>32;
769 UDItype pp_ll = ml * nl;
770 UDItype pp_hl = mh * nl;
771 UDItype pp_lh = ml * nh;
772 UDItype pp_hh = mh * nh;
775 UDItype ps_hh__ = pp_hl + pp_lh;
777 res2 += 0x100000000LL;
778 pp_hl = (ps_hh__ << 32) & 0xffffffff00000000LL;
779 res0 = pp_ll + pp_hl;
782 res2 += ((ps_hh__ >> 32) & 0xffffffffL) + pp_hh;
789 tmp->normal_exp = a->normal_exp + b->normal_exp;
790 tmp->sign = a->sign != b->sign;
792 tmp->normal_exp += 2; /* ??????????????? */
794 tmp->normal_exp += 4; /* ??????????????? */
796 while (high >= IMPLICIT_2)
806 while (high < IMPLICIT_1)
815 /* rounding is tricky. if we only round if it won't make us round later. */
819 if (((high & GARDMASK) != GARDMSB)
820 && (((high + 1) & GARDMASK) == GARDMSB))
822 /* don't round, it gets done again later. */
830 if ((high & GARDMASK) == GARDMSB)
832 if (high & (1 << NGARDS))
834 /* half way, so round to even */
835 high += GARDROUND + 1;
839 /* but we really weren't half way */
840 high += GARDROUND + 1;
843 tmp->fraction.ll = high;
844 tmp->class = CLASS_NUMBER;
849 multiply (FLO_type arg_a, FLO_type arg_b)
856 unpack_d ((FLO_union_type *) & arg_a, &a);
857 unpack_d ((FLO_union_type *) & arg_b, &b);
859 res = _fpmul_parts (&a, &b, &tmp);
864 static fp_number_type *
865 _fpdiv_parts (fp_number_type * a,
867 fp_number_type * tmp)
871 fractype r0, r1, y0, y1, bit;
874 fractype denominator;
886 if (isinf (a) || iszero (a))
888 if (a->class == b->class)
892 a->sign = a->sign ^ b->sign;
902 a->class = CLASS_INFINITY;
906 /* Calculate the mantissa by multiplying both 64bit numbers to get a
910 intfrac d0, d1; /* weren't unsigned before ??? */
913 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
916 a->normal_exp = a->normal_exp - b->normal_exp;
917 numerator = a->fraction.ll;
918 denominator = b->fraction.ll;
920 if (numerator < denominator)
922 /* Fraction will be less than 1.0 */
928 /* ??? Does divide one bit at a time. Optimize. */
931 if (numerator >= denominator)
934 numerator -= denominator;
940 if ((quotient & GARDMASK) == GARDMSB)
942 if (quotient & (1 << NGARDS))
944 /* half way, so round to even */
945 quotient += GARDROUND + 1;
949 /* but we really weren't half way, more bits exist */
950 quotient += GARDROUND + 1;
954 a->fraction.ll = quotient;
960 divide (FLO_type arg_a, FLO_type arg_b)
967 unpack_d ((FLO_union_type *) & arg_a, &a);
968 unpack_d ((FLO_union_type *) & arg_b, &b);
970 res = _fpdiv_parts (&a, &b, &tmp);
975 /* according to the demo, fpcmp returns a comparison with 0... thus
982 _fpcmp_parts (fp_number_type * a, fp_number_type * b)
985 /* either nan -> unordered. Must be checked outside of this routine. */
986 if (isnan (a) && isnan (b))
988 return 1; /* still unordered! */
992 if (isnan (a) || isnan (b))
994 return 1; /* how to indicate unordered compare? */
996 if (isinf (a) && isinf (b))
998 /* +inf > -inf, but +inf != +inf */
999 /* b \a| +inf(0)| -inf(1)
1000 ______\+--------+--------
1001 +inf(0)| a==b(0)| a<b(-1)
1002 -------+--------+--------
1003 -inf(1)| a>b(1) | a==b(0)
1004 -------+--------+--------
1005 So since unordered must be non zero, just line up the columns...
1007 return b->sign - a->sign;
1009 /* but not both... */
1012 return a->sign ? -1 : 1;
1016 return b->sign ? 1 : -1;
1018 if (iszero (a) && iszero (b))
1024 return b->sign ? 1 : -1;
1028 return a->sign ? -1 : 1;
1030 /* now both are "normal". */
1031 if (a->sign != b->sign)
1033 /* opposite signs */
1034 return a->sign ? -1 : 1;
1036 /* same sign; exponents? */
1037 if (a->normal_exp > b->normal_exp)
1039 return a->sign ? -1 : 1;
1041 if (a->normal_exp < b->normal_exp)
1043 return a->sign ? 1 : -1;
1045 /* same exponents; check size. */
1046 if (a->fraction.ll > b->fraction.ll)
1048 return a->sign ? -1 : 1;
1050 if (a->fraction.ll < b->fraction.ll)
1052 return a->sign ? 1 : -1;
1054 /* after all that, they're equal. */
1059 compare (FLO_type arg_a, FLO_type arg_b)
1064 unpack_d ((FLO_union_type *) & arg_a, &a);
1065 unpack_d ((FLO_union_type *) & arg_b, &b);
1067 return _fpcmp_parts (&a, &b);
1070 #ifndef US_SOFTWARE_GOFAST
1072 /* These should be optimized for their specific tasks someday. */
1075 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1080 unpack_d ((FLO_union_type *) & arg_a, &a);
1081 unpack_d ((FLO_union_type *) & arg_b, &b);
1083 if (isnan (&a) || isnan (&b))
1084 return 1; /* false, truth == 0 */
1086 return _fpcmp_parts (&a, &b) ;
1090 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1095 unpack_d ((FLO_union_type *) & arg_a, &a);
1096 unpack_d ((FLO_union_type *) & arg_b, &b);
1098 if (isnan (&a) || isnan (&b))
1099 return 1; /* true, truth != 0 */
1101 return _fpcmp_parts (&a, &b) ;
1105 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1110 unpack_d ((FLO_union_type *) & arg_a, &a);
1111 unpack_d ((FLO_union_type *) & arg_b, &b);
1113 if (isnan (&a) || isnan (&b))
1114 return -1; /* false, truth > 0 */
1116 return _fpcmp_parts (&a, &b);
1120 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1125 unpack_d ((FLO_union_type *) & arg_a, &a);
1126 unpack_d ((FLO_union_type *) & arg_b, &b);
1128 if (isnan (&a) || isnan (&b))
1129 return -1; /* false, truth >= 0 */
1130 return _fpcmp_parts (&a, &b) ;
1134 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1139 unpack_d ((FLO_union_type *) & arg_a, &a);
1140 unpack_d ((FLO_union_type *) & arg_b, &b);
1142 if (isnan (&a) || isnan (&b))
1143 return 1; /* false, truth < 0 */
1145 return _fpcmp_parts (&a, &b);
1149 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1154 unpack_d ((FLO_union_type *) & arg_a, &a);
1155 unpack_d ((FLO_union_type *) & arg_b, &b);
1157 if (isnan (&a) || isnan (&b))
1158 return 1; /* false, truth <= 0 */
1160 return _fpcmp_parts (&a, &b) ;
1163 #endif /* ! US_SOFTWARE_GOFAST */
1166 si_to_float (SItype arg_a)
1170 in.class = CLASS_NUMBER;
1171 in.sign = arg_a < 0;
1174 in.class = CLASS_ZERO;
1178 in.normal_exp = FRACBITS + NGARDS;
1181 /* Special case for minint, since there is no +ve integer
1182 representation for it */
1183 if (arg_a == 0x80000000)
1185 return -2147483648.0;
1187 in.fraction.ll = (-arg_a);
1190 in.fraction.ll = arg_a;
1192 while (in.fraction.ll < (1LL << (FRACBITS + NGARDS)))
1194 in.fraction.ll <<= 1;
1198 return pack_d (&in);
1202 float_to_si (FLO_type arg_a)
1207 unpack_d ((FLO_union_type *) & arg_a, &a);
1212 /* get reasonable MAX_SI_INT... */
1214 return a.sign ? MAX_SI_INT : (-MAX_SI_INT)-1;
1215 /* it is a number, but a small one */
1216 if (a.normal_exp < 0)
1218 if (a.normal_exp > 30)
1219 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1220 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1221 return a.sign ? (-tmp) : (tmp);
1224 #ifdef US_SOFTWARE_GOFAST
1225 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1226 we also define them for GOFAST because the ones in libgcc2.c have the
1227 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1228 out of libgcc2.c. We can't define these here if not GOFAST because then
1229 there'd be duplicate copies. */
1232 float_to_usi (FLO_type arg_a)
1236 unpack_d ((FLO_union_type *) & arg_a, &a);
1241 /* get reasonable MAX_USI_INT... */
1243 return a.sign ? MAX_USI_INT : 0;
1244 /* it is a negative number */
1247 /* it is a number, but a small one */
1248 if (a.normal_exp < 0)
1250 if (a.normal_exp > 31)
1252 else if (a.normal_exp > (FRACBITS + NGARDS))
1253 return a.fraction.ll << ((FRACBITS + NGARDS) - a.normal_exp);
1255 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1260 negate (FLO_type arg_a)
1264 unpack_d ((FLO_union_type *) & arg_a, &a);
1272 __make_fp(fp_class_type class,
1281 in.normal_exp = exp;
1282 in.fraction.ll = frac;
1283 return pack_d (&in);
1288 /* This enables one to build an fp library that supports float but not double.
1289 Otherwise, we would get an undefined reference to __make_dp.
1290 This is needed for some 8-bit ports that can't handle well values that
1291 are 8-bytes in size, so we just don't support double for them at all. */
1293 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype frac);
1296 sf_to_df (SFtype arg_a)
1300 unpack_d ((FLO_union_type *) & arg_a, &in);
1301 return __make_dp (in.class, in.sign, in.normal_exp,
1302 ((UDItype) in.fraction.ll) << F_D_BITOFF);
1310 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1313 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1319 in.normal_exp = exp;
1320 in.fraction.ll = frac;
1321 return pack_d (&in);
1325 df_to_sf (DFtype arg_a)
1329 unpack_d ((FLO_union_type *) & arg_a, &in);
1330 return __make_fp (in.class, in.sign, in.normal_exp,
1331 in.fraction.ll >> F_D_BITOFF);