]>
gcc.gnu.org Git - gcc.git/blob - gcc/real.c
1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Contributed by Stephen L. Moshier (moshier@world.std.com).
5 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
32 /* To enable support of XFmode extended real floating point, define
33 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
35 To support cross compilation between IEEE, VAX and IBM floating
36 point formats, define REAL_ARITHMETIC in the tm.h file.
38 In either case the machine files (tm.h) must not contain any code
39 that tries to use host floating point arithmetic to convert
40 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
41 etc. In cross-compile situations a REAL_VALUE_TYPE may not
42 be intelligible to the host computer's native arithmetic.
44 The emulator defaults to the host's floating point format so that
45 its decimal conversion functions can be used if desired (see
48 The first part of this file interfaces gcc to ieee.c, which is a
49 floating point arithmetic suite that was not written with gcc in
50 mind. The interface is followed by ieee.c itself and related
51 items. Avoid changing ieee.c unless you have suitable test
52 programs available. A special version of the PARANOIA floating
53 point arithmetic tester, modified for this purpose, can be found
54 on usc.edu : /pub/C-numanal/ieeetest.zoo. Some tutorial
55 information on ieee.c is given in my book: S. L. Moshier,
56 _Methods and Programs for Mathematical Functions_, Prentice-Hall
57 or Simon & Schuster Int'l, 1989. A library of XFmode elementary
58 transcendental functions can be obtained by ftp from
59 research.att.com: netlib/cephes/ldouble.shar.Z */
61 /* Type of computer arithmetic.
62 * Only one of DEC, IBM, MIEEE, IBMPC, or UNK should get defined.
65 /* `MIEEE' refers generically to big-endian IEEE floating-point data
66 structure. This definition should work in SFmode `float' type and
67 DFmode `double' type on virtually all big-endian IEEE machines.
68 If LONG_DOUBLE_TYPE_SIZE has been defined to be 96, then MIEEE
69 also invokes the particular XFmode (`long double' type) data
70 structure used by the Motorola 680x0 series processors.
72 `IBMPC' refers generally to little-endian IEEE machines. In this
73 case, if LONG_DOUBLE_TYPE_SIZE has been defined to be 96, then
74 IBMPC also invokes the particular XFmode `long double' data
75 structure used by the Intel 80x86 series processors.
77 `DEC' refers specifically to the Digital Equipment Corp PDP-11
78 and VAX floating point data structure. This model currently
79 supports no type wider than DFmode.
81 `IBM' refers specifically to the IBM System/370 and compatible
82 floating point data structure. This model currently supports
83 no type wider than DFmode. The IBM conversions were contributed by
84 frank@atom.ansto.gov.au (Frank Crawford).
86 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
87 then `long double' and `double' are both implemented, but they
88 both mean DFmode. In this case, the software floating-point
89 support available here is activated by writing
90 #define REAL_ARITHMETIC
93 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
94 and may deactivate XFmode since `long double' is used to refer
97 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
98 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
99 separate the floating point unit's endian-ness from that of
100 the integer addressing. This permits one to define a big-endian
101 FPU on a little-endian machine (e.g., ARM). An extension to
102 BYTES_BIG_ENDIAN may be required for some machines in the future.
103 These optional macros may be defined in tm.h. In real.h, they
104 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
105 them for any normal host or target machine on which the floats
106 and the integers have the same endian-ness. */
109 /* The following converts gcc macros into the ones used by this file. */
111 /* REAL_ARITHMETIC defined means that macros in real.h are
112 defined to call emulator functions. */
113 #ifdef REAL_ARITHMETIC
115 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
116 /* PDP-11, Pro350, VAX: */
118 #else /* it's not VAX */
119 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
120 /* IBM System/370 style */
122 #else /* it's also not an IBM */
123 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
124 #if FLOAT_WORDS_BIG_ENDIAN
125 /* Motorola IEEE, high order words come first (Sun workstation): */
127 #else /* not big-endian */
128 /* Intel IEEE, low order words come first:
131 #endif /* big-endian */
132 #else /* it's not IEEE either */
133 /* UNKnown arithmetic. We don't support this and can't go on. */
134 unknown arithmetic type
136 #endif /* not IEEE */
141 /* REAL_ARITHMETIC not defined means that the *host's* data
142 structure will be used. It may differ by endian-ness from the
143 target machine's structure and will get its ends swapped
144 accordingly (but not here). Probably only the decimal <-> binary
145 functions in this file will actually be used in this case. */
146 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
148 #else /* it's not VAX */
149 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
150 /* IBM System/370 style */
152 #else /* it's also not an IBM */
153 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
154 #if HOST_FLOAT_WORDS_BIG_ENDIAN
156 #else /* not big-endian */
158 #endif /* big-endian */
159 #else /* it's not IEEE either */
160 unknown arithmetic type
162 #endif /* not IEEE */
166 #endif /* REAL_ARITHMETIC not defined */
168 /* Define INFINITY for support of infinity.
169 Define NANS for support of Not-a-Number's (NaN's). */
170 #if !defined(DEC) && !defined(IBM)
175 /* Support of NaNs requires support of infinity. */
182 /* Find a host integer type that is at least 16 bits wide,
183 and another type at least twice whatever that size is. */
185 #if HOST_BITS_PER_CHAR >= 16
186 #define EMUSHORT char
187 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
188 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
190 #if HOST_BITS_PER_SHORT >= 16
191 #define EMUSHORT short
192 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
193 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
195 #if HOST_BITS_PER_INT >= 16
197 #define EMUSHORT_SIZE HOST_BITS_PER_INT
198 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
200 #if HOST_BITS_PER_LONG >= 16
201 #define EMUSHORT long
202 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
203 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
205 /* You will have to modify this program to have a smaller unit size. */
206 #define EMU_NON_COMPILE
212 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
213 #define EMULONG short
215 #if HOST_BITS_PER_INT >= EMULONG_SIZE
218 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
221 #if HOST_BITS_PER_LONG_LONG >= EMULONG_SIZE
222 #define EMULONG long long int
224 /* You will have to modify this program to have a smaller unit size. */
225 #define EMU_NON_COMPILE
232 /* The host interface doesn't work if no 16-bit size exists. */
233 #if EMUSHORT_SIZE != 16
234 #define EMU_NON_COMPILE
237 /* OK to continue compilation. */
238 #ifndef EMU_NON_COMPILE
240 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
241 In GET_REAL and PUT_REAL, r and e are pointers.
242 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
243 in memory, with no holes. */
245 #if LONG_DOUBLE_TYPE_SIZE == 96
246 /* Number of 16 bit words in external e type format */
248 #define MAXDECEXP 4932
249 #define MINDECEXP -4956
250 #define GET_REAL(r,e) bcopy (r, e, 2*NE)
251 #define PUT_REAL(e,r) bcopy (e, r, 2*NE)
252 #else /* no XFmode */
253 #if LONG_DOUBLE_TYPE_SIZE == 128
255 #define MAXDECEXP 4932
256 #define MINDECEXP -4977
257 #define GET_REAL(r,e) bcopy (r, e, 2*NE)
258 #define PUT_REAL(e,r) bcopy (e, r, 2*NE)
261 #define MAXDECEXP 4932
262 #define MINDECEXP -4956
263 #ifdef REAL_ARITHMETIC
264 /* Emulator uses target format internally
265 but host stores it in host endian-ness. */
267 #if HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN
268 #define GET_REAL(r,e) e53toe ((r), (e))
269 #define PUT_REAL(e,r) etoe53 ((e), (r))
271 #else /* endian-ness differs */
272 /* emulator uses target endian-ness internally */
273 #define GET_REAL(r,e) \
274 do { EMUSHORT w[4]; \
275 w[3] = ((EMUSHORT *) r)[0]; \
276 w[2] = ((EMUSHORT *) r)[1]; \
277 w[1] = ((EMUSHORT *) r)[2]; \
278 w[0] = ((EMUSHORT *) r)[3]; \
279 e53toe (w, (e)); } while (0)
281 #define PUT_REAL(e,r) \
282 do { EMUSHORT w[4]; \
284 *((EMUSHORT *) r) = w[3]; \
285 *((EMUSHORT *) r + 1) = w[2]; \
286 *((EMUSHORT *) r + 2) = w[1]; \
287 *((EMUSHORT *) r + 3) = w[0]; } while (0)
289 #endif /* endian-ness differs */
291 #else /* not REAL_ARITHMETIC */
293 /* emulator uses host format */
294 #define GET_REAL(r,e) e53toe ((r), (e))
295 #define PUT_REAL(e,r) etoe53 ((e), (r))
297 #endif /* not REAL_ARITHMETIC */
298 #endif /* not TFmode */
299 #endif /* no XFmode */
302 /* Number of 16 bit words in internal format */
305 /* Array offset to exponent */
308 /* Array offset to high guard word */
311 /* Number of bits of precision */
312 #define NBITS ((NI-4)*16)
314 /* Maximum number of decimal digits in ASCII conversion
317 #define NDEC (NBITS*8/27)
319 /* The exponent of 1.0 */
320 #define EXONE (0x3fff)
323 extern int extra_warnings
;
324 int ecmp (), enormlz (), eshift ();
325 int eisneg (), eisinf (), eisnan (), eiisinf (), eiisnan (), eiisneg ();
326 void eadd (), esub (), emul (), ediv ();
327 void eshup1 (), eshup8 (), eshup6 (), eshdn1 (), eshdn8 (), eshdn6 ();
328 void eabs (), eneg (), emov (), eclear (), einfin (), efloor ();
329 void eldexp (), efrexp (), eifrac (), euifrac (), ltoe (), ultoe ();
330 void ereal_to_decimal (), eiinfin (), einan ();
331 void esqrt (), elog (), eexp (), etanh (), epow ();
332 void asctoe (), asctoe24 (), asctoe53 (), asctoe64 (), asctoe113 ();
333 void etoasc (), e24toasc (), e53toasc (), e64toasc (), e113toasc ();
334 void etoe64 (), etoe53 (), etoe24 (), e64toe (), e53toe (), e24toe ();
335 void etoe113 (), e113toe ();
336 void mtherr (), make_nan ();
338 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
339 extern unsigned EMUSHORT elog2
[], esqrt2
[];
341 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
342 swapping ends if required, into output array of longs. The
343 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
346 unsigned EMUSHORT e
[];
348 enum machine_mode mode
;
352 #if FLOAT_WORDS_BIG_ENDIAN
357 /* Swap halfwords in the fourth long. */
358 th
= (unsigned long) e
[6] & 0xffff;
359 t
= (unsigned long) e
[7] & 0xffff;
365 /* Swap halfwords in the third long. */
366 th
= (unsigned long) e
[4] & 0xffff;
367 t
= (unsigned long) e
[5] & 0xffff;
370 /* fall into the double case */
374 /* swap halfwords in the second word */
375 th
= (unsigned long) e
[2] & 0xffff;
376 t
= (unsigned long) e
[3] & 0xffff;
379 /* fall into the float case */
383 /* swap halfwords in the first word */
384 th
= (unsigned long) e
[0] & 0xffff;
385 t
= (unsigned long) e
[1] & 0xffff;
396 /* Pack the output array without swapping. */
403 /* Pack the fourth long. */
404 th
= (unsigned long) e
[7] & 0xffff;
405 t
= (unsigned long) e
[6] & 0xffff;
411 /* Pack the third long.
412 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
414 th
= (unsigned long) e
[5] & 0xffff;
415 t
= (unsigned long) e
[4] & 0xffff;
418 /* fall into the double case */
422 /* pack the second long */
423 th
= (unsigned long) e
[3] & 0xffff;
424 t
= (unsigned long) e
[2] & 0xffff;
427 /* fall into the float case */
431 /* pack the first long */
432 th
= (unsigned long) e
[1] & 0xffff;
433 t
= (unsigned long) e
[0] & 0xffff;
446 /* This is the implementation of the REAL_ARITHMETIC macro.
449 earith (value
, icode
, r1
, r2
)
450 REAL_VALUE_TYPE
*value
;
455 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
461 /* Return NaN input back to the caller. */
464 PUT_REAL (d1
, value
);
469 PUT_REAL (d2
, value
);
473 code
= (enum tree_code
) icode
;
481 esub (d2
, d1
, v
); /* d1 - d2 */
489 #ifndef REAL_INFINITY
490 if (ecmp (d2
, ezero
) == 0)
493 enan (v
, eisneg (d1
) ^ eisneg (d2
));
500 ediv (d2
, d1
, v
); /* d1/d2 */
503 case MIN_EXPR
: /* min (d1,d2) */
504 if (ecmp (d1
, d2
) < 0)
510 case MAX_EXPR
: /* max (d1,d2) */
511 if (ecmp (d1
, d2
) > 0)
524 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT
525 * implements REAL_VALUE_RNDZINT (x) (etrunci (x))
531 unsigned EMUSHORT f
[NE
], g
[NE
];
547 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT
548 * implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x))
554 unsigned EMUSHORT f
[NE
], g
[NE
];
556 unsigned HOST_WIDE_INT l
;
570 /* This is the REAL_VALUE_ATOF function.
571 * It converts a decimal string to binary, rounding off
572 * as indicated by the machine_mode argument. Then it
573 * promotes the rounded value to REAL_VALUE_TYPE.
580 unsigned EMUSHORT tem
[NE
], e
[NE
];
609 /* Expansion of REAL_NEGATE.
615 unsigned EMUSHORT e
[NE
];
625 /* Round real toward zero to HOST_WIDE_INT
626 * implements REAL_VALUE_FIX (x).
632 unsigned EMUSHORT f
[NE
], g
[NE
];
639 warning ("conversion from NaN to int");
647 /* Round real toward zero to unsigned HOST_WIDE_INT
648 * implements REAL_VALUE_UNSIGNED_FIX (x).
649 * Negative input returns zero.
651 unsigned HOST_WIDE_INT
655 unsigned EMUSHORT f
[NE
], g
[NE
];
656 unsigned HOST_WIDE_INT l
;
662 warning ("conversion from NaN to unsigned int");
671 /* REAL_VALUE_FROM_INT macro.
674 ereal_from_int (d
, i
, j
)
678 unsigned EMUSHORT df
[NE
], dg
[NE
];
679 HOST_WIDE_INT low
, high
;
687 /* complement and add 1 */
694 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
705 /* REAL_VALUE_FROM_UNSIGNED_INT macro.
708 ereal_from_uint (d
, i
, j
)
710 unsigned HOST_WIDE_INT i
, j
;
712 unsigned EMUSHORT df
[NE
], dg
[NE
];
713 unsigned HOST_WIDE_INT low
, high
;
717 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
726 /* REAL_VALUE_TO_INT macro
729 ereal_to_int (low
, high
, rr
)
730 HOST_WIDE_INT
*low
, *high
;
733 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
740 warning ("conversion from NaN to int");
746 /* convert positive value */
753 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
754 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
755 euifrac (dg
, high
, dh
);
756 emul (df
, dh
, dg
); /* fractional part is the low word */
757 euifrac (dg
, low
, dh
);
760 /* complement and add 1 */
770 /* REAL_VALUE_LDEXP macro.
777 unsigned EMUSHORT e
[NE
], y
[NE
];
790 /* These routines are conditionally compiled because functions
791 * of the same names may be defined in fold-const.c. */
792 #ifdef REAL_ARITHMETIC
794 /* Check for infinity in a REAL_VALUE_TYPE. */
799 unsigned EMUSHORT e
[NE
];
810 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
816 unsigned EMUSHORT e
[NE
];
827 /* Check for a negative REAL_VALUE_TYPE number.
828 * this means strictly less than zero, not -0.
835 unsigned EMUSHORT e
[NE
];
838 if (ecmp (e
, ezero
) == -1)
843 /* Expansion of REAL_VALUE_TRUNCATE.
844 * The result is in floating point, rounded to nearest or even.
847 real_value_truncate (mode
, arg
)
848 enum machine_mode mode
;
851 unsigned EMUSHORT e
[NE
], t
[NE
];
893 #endif /* REAL_ARITHMETIC defined */
895 /* Used for debugging--print the value of R in human-readable format
904 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
905 fprintf (stderr
, "%s", dstr
);
909 /* Target values are arrays of host longs. A long is guaranteed
910 to be at least 32 bits wide. */
912 /* 128-bit long double */
918 unsigned EMUSHORT e
[NE
];
922 endian (e
, l
, TFmode
);
925 /* 80-bit long double */
931 unsigned EMUSHORT e
[NE
];
935 endian (e
, l
, XFmode
);
943 unsigned EMUSHORT e
[NE
];
947 endian (e
, l
, DFmode
);
954 unsigned EMUSHORT e
[NE
];
959 endian (e
, &l
, SFmode
);
964 ereal_to_decimal (x
, s
)
968 unsigned EMUSHORT e
[NE
];
976 REAL_VALUE_TYPE x
, y
;
978 unsigned EMUSHORT ex
[NE
], ey
[NE
];
982 return (ecmp (ex
, ey
));
989 unsigned EMUSHORT ex
[NE
];
992 return (eisneg (ex
));
995 /* End of REAL_ARITHMETIC interface */
999 * Extended precision IEEE binary floating point arithmetic routines
1001 * Numbers are stored in C language as arrays of 16-bit unsigned
1002 * short integers. The arguments of the routines are pointers to
1006 * External e type data structure, simulates Intel 8087 chip
1007 * temporary real format but possibly with a larger significand:
1009 * NE-1 significand words (least significant word first,
1010 * most significant bit is normally set)
1011 * exponent (value = EXONE for 1.0,
1012 * top bit is the sign)
1015 * Internal data structure of a number (a "word" is 16 bits):
1017 * ei[0] sign word (0 for positive, 0xffff for negative)
1018 * ei[1] biased exponent (value = EXONE for the number 1.0)
1019 * ei[2] high guard word (always zero after normalization)
1021 * to ei[NI-2] significand (NI-4 significand words,
1022 * most significant word first,
1023 * most significant bit is set)
1024 * ei[NI-1] low guard word (0x8000 bit is rounding place)
1028 * Routines for external format numbers
1030 * asctoe (string, e) ASCII string to extended double e type
1031 * asctoe64 (string, &d) ASCII string to long double
1032 * asctoe53 (string, &d) ASCII string to double
1033 * asctoe24 (string, &f) ASCII string to single
1034 * asctoeg (string, e, prec) ASCII string to specified precision
1035 * e24toe (&f, e) IEEE single precision to e type
1036 * e53toe (&d, e) IEEE double precision to e type
1037 * e64toe (&d, e) IEEE long double precision to e type
1038 * e113toe (&d, e) 128-bit long double precision to e type
1039 * eabs (e) absolute value
1040 * eadd (a, b, c) c = b + a
1042 * ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1043 * -1 if a < b, -2 if either a or b is a NaN.
1044 * ediv (a, b, c) c = b / a
1045 * efloor (a, b) truncate to integer, toward -infinity
1046 * efrexp (a, exp, s) extract exponent and significand
1047 * eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1048 * euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1049 * einfin (e) set e to infinity, leaving its sign alone
1050 * eldexp (a, n, b) multiply by 2**n
1052 * emul (a, b, c) c = b * a
1054 * eround (a, b) b = nearest integer value to a
1055 * esub (a, b, c) c = b - a
1056 * e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1057 * e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1058 * e64toasc (&d, str, n) 80-bit long double to ASCII string
1059 * e113toasc (&d, str, n) 128-bit long double to ASCII string
1060 * etoasc (e, str, n) e to ASCII string, n digits after decimal
1061 * etoe24 (e, &f) convert e type to IEEE single precision
1062 * etoe53 (e, &d) convert e type to IEEE double precision
1063 * etoe64 (e, &d) convert e type to IEEE long double precision
1064 * ltoe (&l, e) HOST_WIDE_INT to e type
1065 * ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1066 * eisneg (e) 1 if sign bit of e != 0, else 0
1067 * eisinf (e) 1 if e has maximum exponent (non-IEEE)
1068 * or is infinite (IEEE)
1069 * eisnan (e) 1 if e is a NaN
1072 * Routines for internal format numbers
1074 * eaddm (ai, bi) add significands, bi = bi + ai
1075 * ecleaz (ei) ei = 0
1076 * ecleazs (ei) set ei = 0 but leave its sign alone
1077 * ecmpm (ai, bi) compare significands, return 1, 0, or -1
1078 * edivm (ai, bi) divide significands, bi = bi / ai
1079 * emdnorm (ai,l,s,exp) normalize and round off
1080 * emovi (a, ai) convert external a to internal ai
1081 * emovo (ai, a) convert internal ai to external a
1082 * emovz (ai, bi) bi = ai, low guard word of bi = 0
1083 * emulm (ai, bi) multiply significands, bi = bi * ai
1084 * enormlz (ei) left-justify the significand
1085 * eshdn1 (ai) shift significand and guards down 1 bit
1086 * eshdn8 (ai) shift down 8 bits
1087 * eshdn6 (ai) shift down 16 bits
1088 * eshift (ai, n) shift ai n bits up (or down if n < 0)
1089 * eshup1 (ai) shift significand and guards up 1 bit
1090 * eshup8 (ai) shift up 8 bits
1091 * eshup6 (ai) shift up 16 bits
1092 * esubm (ai, bi) subtract significands, bi = bi - ai
1093 * eiisinf (ai) 1 if infinite
1094 * eiisnan (ai) 1 if a NaN
1095 * eiisneg (ai) 1 if sign bit of ai != 0, else 0
1096 * einan (ai) set ai = NaN
1097 * eiinfin (ai) set ai = infinity
1100 * The result is always normalized and rounded to NI-4 word precision
1101 * after each arithmetic operation.
1103 * Exception flags are NOT fully supported.
1105 * Signaling NaN's are NOT supported; they are treated the same
1108 * Define INFINITY for support of infinity; otherwise a
1109 * saturation arithmetic is implemented.
1111 * Define NANS for support of Not-a-Number items; otherwise the
1112 * arithmetic will never produce a NaN output, and might be confused
1114 * If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1115 * either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1116 * may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1119 * Denormals are always supported here where appropriate (e.g., not
1120 * for conversion to DEC numbers).
1127 * Common include file for math routines
1133 * #include "mconf.h"
1139 * This file contains definitions for error codes that are
1140 * passed to the common error handling routine mtherr
1143 * The file also includes a conditional assembly definition
1144 * for the type of computer arithmetic (Intel IEEE, DEC, Motorola
1145 * IEEE, or UNKnown).
1147 * For Digital Equipment PDP-11 and VAX computers, certain
1148 * IBM systems, and others that use numbers with a 56-bit
1149 * significand, the symbol DEC should be defined. In this
1150 * mode, most floating point constants are given as arrays
1151 * of octal integers to eliminate decimal to binary conversion
1152 * errors that might be introduced by the compiler.
1154 * For computers, such as IBM PC, that follow the IEEE
1155 * Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1156 * Std 754-1985), the symbol IBMPC or MIEEE should be defined.
1157 * These numbers have 53-bit significands. In this mode, constants
1158 * are provided as arrays of hexadecimal 16 bit integers.
1160 * To accommodate other types of computer arithmetic, all
1161 * constants are also provided in a normal decimal radix
1162 * which one can hope are correctly converted to a suitable
1163 * format by the available C language compiler. To invoke
1164 * this mode, the symbol UNK is defined.
1166 * An important difference among these modes is a predefined
1167 * set of machine arithmetic constants for each. The numbers
1168 * MACHEP (the machine roundoff error), MAXNUM (largest number
1169 * represented), and several other parameters are preset by
1170 * the configuration symbol. Check the file const.c to
1171 * ensure that these values are correct for your computer.
1173 * For ANSI C compatibility, define ANSIC equal to 1. Currently
1174 * this affects only the atan2 function and others that use it.
1177 /* Constant definitions for math error conditions. */
1179 #define DOMAIN 1 /* argument domain error */
1180 #define SING 2 /* argument singularity */
1181 #define OVERFLOW 3 /* overflow range error */
1182 #define UNDERFLOW 4 /* underflow range error */
1183 #define TLOSS 5 /* total loss of precision */
1184 #define PLOSS 6 /* partial loss of precision */
1185 #define INVALID 7 /* NaN-producing operation */
1187 /* e type constants used by high precision check routines */
1189 #if LONG_DOUBLE_TYPE_SIZE == 128
1191 unsigned EMUSHORT ezero
[NE
] =
1192 {0x0000, 0x0000, 0x0000, 0x0000,
1193 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1194 extern unsigned EMUSHORT ezero
[];
1197 unsigned EMUSHORT ehalf
[NE
] =
1198 {0x0000, 0x0000, 0x0000, 0x0000,
1199 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1200 extern unsigned EMUSHORT ehalf
[];
1203 unsigned EMUSHORT eone
[NE
] =
1204 {0x0000, 0x0000, 0x0000, 0x0000,
1205 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1206 extern unsigned EMUSHORT eone
[];
1209 unsigned EMUSHORT etwo
[NE
] =
1210 {0x0000, 0x0000, 0x0000, 0x0000,
1211 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1212 extern unsigned EMUSHORT etwo
[];
1215 unsigned EMUSHORT e32
[NE
] =
1216 {0x0000, 0x0000, 0x0000, 0x0000,
1217 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1218 extern unsigned EMUSHORT e32
[];
1220 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1221 unsigned EMUSHORT elog2
[NE
] =
1222 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1223 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1224 extern unsigned EMUSHORT elog2
[];
1226 /* 1.41421356237309504880168872420969807856967187537695E0 */
1227 unsigned EMUSHORT esqrt2
[NE
] =
1228 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1229 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1230 extern unsigned EMUSHORT esqrt2
[];
1232 /* 3.14159265358979323846264338327950288419716939937511E0 */
1233 unsigned EMUSHORT epi
[NE
] =
1234 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1235 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1236 extern unsigned EMUSHORT epi
[];
1239 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1240 unsigned EMUSHORT ezero
[NE
] =
1241 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1242 unsigned EMUSHORT ehalf
[NE
] =
1243 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1244 unsigned EMUSHORT eone
[NE
] =
1245 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1246 unsigned EMUSHORT etwo
[NE
] =
1247 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1248 unsigned EMUSHORT e32
[NE
] =
1249 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1250 unsigned EMUSHORT elog2
[NE
] =
1251 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1252 unsigned EMUSHORT esqrt2
[NE
] =
1253 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1254 unsigned EMUSHORT epi
[NE
] =
1255 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1260 /* Control register for rounding precision.
1261 * This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits.
1266 void eaddm (), esubm (), emdnorm (), asctoeg ();
1267 static void toe24 (), toe53 (), toe64 (), toe113 ();
1268 void eremain (), einit (), eiremain ();
1269 int ecmpm (), edivm (), emulm ();
1270 void emovi (), emovo (), emovz (), ecleaz (), ecleazs (), eadd1 ();
1272 void etodec (), todec (), dectoe ();
1275 void etoibm (), toibm (), ibmtoe ();
1285 ; Clear out entire external format number.
1287 ; unsigned EMUSHORT x[];
1293 register unsigned EMUSHORT
*x
;
1297 for (i
= 0; i
< NE
; i
++)
1303 /* Move external format number from a to b.
1310 register unsigned EMUSHORT
*a
, *b
;
1314 for (i
= 0; i
< NE
; i
++)
1320 ; Absolute value of external format number
1328 unsigned EMUSHORT x
[]; /* x is the memory address of a short */
1331 x
[NE
- 1] &= 0x7fff; /* sign is top bit of last word of external format */
1338 ; Negate external format number
1340 ; unsigned EMUSHORT x[NE];
1346 unsigned EMUSHORT x
[];
1349 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1354 /* Return 1 if sign bit of external format number is nonzero,
1359 unsigned EMUSHORT x
[];
1362 if (x
[NE
- 1] & 0x8000)
1369 /* Return 1 if external format number is infinity.
1374 unsigned EMUSHORT x
[];
1381 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1388 /* Check if e-type number is not a number.
1389 The bit pattern is one that we defined, so we know for sure how to
1394 unsigned EMUSHORT x
[];
1399 /* NaN has maximum exponent */
1400 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1402 /* ... and non-zero significand field. */
1403 for (i
= 0; i
< NE
- 1; i
++)
1412 /* Fill external format number with infinity pattern (IEEE)
1413 or largest possible number (non-IEEE). */
1417 register unsigned EMUSHORT
*x
;
1422 for (i
= 0; i
< NE
- 1; i
++)
1426 for (i
= 0; i
< NE
- 1; i
++)
1455 /* Output an e-type NaN.
1456 This generates Intel's quiet NaN pattern for extended real.
1457 The exponent is 7fff, the leading mantissa word is c000. */
1461 register unsigned EMUSHORT
*x
;
1466 for (i
= 0; i
< NE
- 2; i
++)
1469 *x
= (sign
<< 15) | 0x7fff;
1473 /* Move in external format number,
1474 * converting it to internal format.
1478 unsigned EMUSHORT
*a
, *b
;
1480 register unsigned EMUSHORT
*p
, *q
;
1484 p
= a
+ (NE
- 1); /* point to last word of external number */
1485 /* get the sign bit */
1490 /* get the exponent */
1492 *q
++ &= 0x7fff; /* delete the sign bit */
1494 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1500 for (i
= 3; i
< NI
; i
++)
1505 for (i
= 2; i
< NI
; i
++)
1510 /* clear high guard word */
1512 /* move in the significand */
1513 for (i
= 0; i
< NE
- 1; i
++)
1515 /* clear low guard word */
1520 /* Move internal format number out,
1521 * converting it to external format.
1525 unsigned EMUSHORT
*a
, *b
;
1527 register unsigned EMUSHORT
*p
, *q
;
1528 unsigned EMUSHORT i
;
1532 q
= b
+ (NE
- 1); /* point to output exponent */
1533 /* combine sign and exponent */
1536 *q
-- = *p
++ | 0x8000;
1540 if (*(p
- 1) == 0x7fff)
1545 enan (b
, eiisneg (a
));
1553 /* skip over guard word */
1555 /* move the significand */
1556 for (j
= 0; j
< NE
- 1; j
++)
1563 /* Clear out internal format number.
1568 register unsigned EMUSHORT
*xi
;
1572 for (i
= 0; i
< NI
; i
++)
1577 /* same, but don't touch the sign. */
1581 register unsigned EMUSHORT
*xi
;
1586 for (i
= 0; i
< NI
- 1; i
++)
1592 /* Move internal format number from a to b.
1596 register unsigned EMUSHORT
*a
, *b
;
1600 for (i
= 0; i
< NI
- 1; i
++)
1602 /* clear low guard word */
1606 /* Generate internal format NaN.
1607 The explicit pattern for this is maximum exponent and
1608 top two significand bits set. */
1612 unsigned EMUSHORT x
[];
1620 /* Return nonzero if internal format number is a NaN. */
1624 unsigned EMUSHORT x
[];
1628 if ((x
[E
] & 0x7fff) == 0x7fff)
1630 for (i
= M
+ 1; i
< NI
; i
++)
1639 /* Return nonzero if sign of internal format number is nonzero. */
1643 unsigned EMUSHORT x
[];
1649 /* Fill internal format number with infinity pattern.
1650 This has maximum exponent and significand all zeros. */
1654 unsigned EMUSHORT x
[];
1661 /* Return nonzero if internal format number is infinite. */
1665 unsigned EMUSHORT x
[];
1672 if ((x
[E
] & 0x7fff) == 0x7fff)
1679 ; Compare significands of numbers in internal format.
1680 ; Guard words are included in the comparison.
1682 ; unsigned EMUSHORT a[NI], b[NI];
1685 ; for the significands:
1686 ; returns +1 if a > b
1692 register unsigned EMUSHORT
*a
, *b
;
1696 a
+= M
; /* skip up to significand area */
1698 for (i
= M
; i
< NI
; i
++)
1706 if (*(--a
) > *(--b
))
1714 ; Shift significand down by 1 bit
1719 register unsigned EMUSHORT
*x
;
1721 register unsigned EMUSHORT bits
;
1724 x
+= M
; /* point to significand area */
1727 for (i
= M
; i
< NI
; i
++)
1742 ; Shift significand up by 1 bit
1747 register unsigned EMUSHORT
*x
;
1749 register unsigned EMUSHORT bits
;
1755 for (i
= M
; i
< NI
; i
++)
1770 ; Shift significand down by 8 bits
1775 register unsigned EMUSHORT
*x
;
1777 register unsigned EMUSHORT newbyt
, oldbyt
;
1782 for (i
= M
; i
< NI
; i
++)
1793 ; Shift significand up by 8 bits
1798 register unsigned EMUSHORT
*x
;
1801 register unsigned EMUSHORT newbyt
, oldbyt
;
1806 for (i
= M
; i
< NI
; i
++)
1817 ; Shift significand up by 16 bits
1822 register unsigned EMUSHORT
*x
;
1825 register unsigned EMUSHORT
*p
;
1830 for (i
= M
; i
< NI
- 1; i
++)
1837 ; Shift significand down by 16 bits
1842 register unsigned EMUSHORT
*x
;
1845 register unsigned EMUSHORT
*p
;
1850 for (i
= M
; i
< NI
- 1; i
++)
1863 unsigned EMUSHORT
*x
, *y
;
1865 register unsigned EMULONG a
;
1872 for (i
= M
; i
< NI
; i
++)
1874 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
1879 *y
= (unsigned EMUSHORT
) a
;
1886 ; Subtract significands
1892 unsigned EMUSHORT
*x
, *y
;
1901 for (i
= M
; i
< NI
; i
++)
1903 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
1908 *y
= (unsigned EMUSHORT
) a
;
1915 static unsigned EMUSHORT equot
[NI
];
1919 /* Radix 2 shift-and-add versions of multiply and divide */
1922 /* Divide significands */
1926 unsigned EMUSHORT den
[], num
[];
1929 register unsigned EMUSHORT
*p
, *q
;
1930 unsigned EMUSHORT j
;
1936 for (i
= M
; i
< NI
; i
++)
1941 /* Use faster compare and subtraction if denominator
1942 * has only 15 bits of significance.
1947 for (i
= M
+ 3; i
< NI
; i
++)
1952 if ((den
[M
+ 1] & 1) != 0)
1960 for (i
= 0; i
< NBITS
+ 2; i
++)
1978 /* The number of quotient bits to calculate is
1979 * NBITS + 1 scaling guard bit + 1 roundoff bit.
1984 for (i
= 0; i
< NBITS
+ 2; i
++)
1986 if (ecmpm (den
, num
) <= 0)
1989 j
= 1; /* quotient bit = 1 */
2003 /* test for nonzero remainder after roundoff bit */
2006 for (i
= M
; i
< NI
; i
++)
2014 for (i
= 0; i
< NI
; i
++)
2020 /* Multiply significands */
2023 unsigned EMUSHORT a
[], b
[];
2025 unsigned EMUSHORT
*p
, *q
;
2030 for (i
= M
; i
< NI
; i
++)
2035 while (*p
== 0) /* significand is not supposed to be all zero */
2040 if ((*p
& 0xff) == 0)
2048 for (i
= 0; i
< k
; i
++)
2052 /* remember if there were any nonzero bits shifted out */
2059 for (i
= 0; i
< NI
; i
++)
2062 /* return flag for lost nonzero bits */
2068 /* Radix 65536 versions of multiply and divide */
2071 /* Multiply significand of e-type number b
2072 by 16-bit quantity a, e-type result to c. */
2077 unsigned short b
[], c
[];
2079 register unsigned short *pp
;
2080 register unsigned long carry
;
2082 unsigned short p
[NI
];
2083 unsigned long aa
, m
;
2092 for (i
=M
+1; i
<NI
; i
++)
2102 m
= (unsigned long) aa
* *ps
--;
2103 carry
= (m
& 0xffff) + *pp
;
2104 *pp
-- = (unsigned short)carry
;
2105 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2106 *pp
= (unsigned short)carry
;
2107 *(pp
-1) = carry
>> 16;
2110 for (i
=M
; i
<NI
; i
++)
2115 /* Divide significands. Neither the numerator nor the denominator
2116 is permitted to have its high guard word nonzero. */
2120 unsigned short den
[], num
[];
2123 register unsigned short *p
;
2125 unsigned short j
, tdenm
, tquot
;
2126 unsigned short tprod
[NI
+1];
2132 for (i
=M
; i
<NI
; i
++)
2138 for (i
=M
; i
<NI
; i
++)
2140 /* Find trial quotient digit (the radix is 65536). */
2141 tnum
= (((unsigned long) num
[M
]) << 16) + num
[M
+1];
2143 /* Do not execute the divide instruction if it will overflow. */
2144 if ((tdenm
* 0xffffL
) < tnum
)
2147 tquot
= tnum
/ tdenm
;
2148 /* Multiply denominator by trial quotient digit. */
2149 m16m (tquot
, den
, tprod
);
2150 /* The quotient digit may have been overestimated. */
2151 if (ecmpm (tprod
, num
) > 0)
2155 if (ecmpm (tprod
, num
) > 0)
2165 /* test for nonzero remainder after roundoff bit */
2168 for (i
=M
; i
<NI
; i
++)
2175 for (i
=0; i
<NI
; i
++)
2183 /* Multiply significands */
2186 unsigned short a
[], b
[];
2188 unsigned short *p
, *q
;
2189 unsigned short pprod
[NI
];
2195 for (i
=M
; i
<NI
; i
++)
2201 for (i
=M
+1; i
<NI
; i
++)
2209 m16m (*p
--, b
, pprod
);
2210 eaddm(pprod
, equot
);
2216 for (i
=0; i
<NI
; i
++)
2219 /* return flag for lost nonzero bits */
2226 * Normalize and round off.
2228 * The internal format number to be rounded is "s".
2229 * Input "lost" indicates whether or not the number is exact.
2230 * This is the so-called sticky bit.
2232 * Input "subflg" indicates whether the number was obtained
2233 * by a subtraction operation. In that case if lost is nonzero
2234 * then the number is slightly smaller than indicated.
2236 * Input "exp" is the biased exponent, which may be negative.
2237 * the exponent field of "s" is ignored but is replaced by
2238 * "exp" as adjusted by normalization and rounding.
2240 * Input "rcntrl" is the rounding control.
2243 /* For future reference: In order for emdnorm to round off denormal
2244 significands at the right point, the input exponent must be
2245 adjusted to be the actual value it would have after conversion to
2246 the final floating point type. This adjustment has been
2247 implemented for all type conversions (etoe53, etc.) and decimal
2248 conversions, but not for the arithmetic functions (eadd, etc.).
2249 Data types having standard 15-bit exponents are not affected by
2250 this, but SFmode and DFmode are affected. For example, ediv with
2251 rndprc = 24 will not round correctly to 24-bit precision if the
2252 result is denormal. */
2254 static int rlast
= -1;
2256 static unsigned EMUSHORT rmsk
= 0;
2257 static unsigned EMUSHORT rmbit
= 0;
2258 static unsigned EMUSHORT rebit
= 0;
2260 static unsigned EMUSHORT rbit
[NI
];
2263 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2264 unsigned EMUSHORT s
[];
2271 unsigned EMUSHORT r
;
2276 /* a blank significand could mean either zero or infinity. */
2289 if ((j
> NBITS
) && (exp
< 32767))
2297 if (exp
> (EMULONG
) (-NBITS
- 1))
2310 /* Round off, unless told not to by rcntrl. */
2313 /* Set up rounding parameters if the control register changed. */
2314 if (rndprc
!= rlast
)
2321 rw
= NI
- 1; /* low guard word */
2341 /* For DEC or IBM arithmetic */
2368 /* Shift down 1 temporarily if the data structure has an implied
2369 most significant bit and the number is denormal. */
2370 if ((exp
<= 0) && (rndprc
!= 64) && (rndprc
!= NBITS
))
2372 lost
|= s
[NI
- 1] & 1;
2375 /* Clear out all bits below the rounding bit,
2376 remembering in r if any were nonzero. */
2390 if ((r
& rmbit
) != 0)
2395 { /* round to even */
2396 if ((s
[re
] & rebit
) == 0)
2408 if ((exp
<= 0) && (rndprc
!= 64) && (rndprc
!= NBITS
))
2413 { /* overflow on roundoff */
2426 for (i
= 2; i
< NI
- 1; i
++)
2429 warning ("floating point overflow");
2433 for (i
= M
+ 1; i
< NI
- 1; i
++)
2436 if ((rndprc
< 64) || (rndprc
== 113))
2451 s
[1] = (unsigned EMUSHORT
) exp
;
2457 ; Subtract external format numbers.
2459 ; unsigned EMUSHORT a[NE], b[NE], c[NE];
2460 ; esub (a, b, c); c = b - a
2463 static int subflg
= 0;
2467 unsigned EMUSHORT
*a
, *b
, *c
;
2481 /* Infinity minus infinity is a NaN.
2482 Test for subtracting infinities of the same sign. */
2483 if (eisinf (a
) && eisinf (b
)
2484 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2486 mtherr ("esub", INVALID
);
2499 ; unsigned EMUSHORT a[NE], b[NE], c[NE];
2500 ; eadd (a, b, c); c = b + a
2504 unsigned EMUSHORT
*a
, *b
, *c
;
2508 /* NaN plus anything is a NaN. */
2519 /* Infinity minus infinity is a NaN.
2520 Test for adding infinities of opposite signs. */
2521 if (eisinf (a
) && eisinf (b
)
2522 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2524 mtherr ("esub", INVALID
);
2535 unsigned EMUSHORT
*a
, *b
, *c
;
2537 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2539 EMULONG lt
, lta
, ltb
;
2560 /* compare exponents */
2565 { /* put the larger number in bi */
2575 if (lt
< (EMULONG
) (-NBITS
- 1))
2576 goto done
; /* answer same as larger addend */
2578 lost
= eshift (ai
, k
); /* shift the smaller number down */
2582 /* exponents were the same, so must compare significands */
2585 { /* the numbers are identical in magnitude */
2586 /* if different signs, result is zero */
2592 /* if same sign, result is double */
2593 /* double denomalized tiny number */
2594 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2599 /* add 1 to exponent unless both are zero! */
2600 for (j
= 1; j
< NI
- 1; j
++)
2604 /* This could overflow, but let emovo take care of that. */
2609 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2613 { /* put the larger number in bi */
2629 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2640 ; unsigned EMUSHORT a[NE], b[NE], c[NE];
2641 ; ediv (a, b, c); c = b / a
2645 unsigned EMUSHORT
*a
, *b
, *c
;
2647 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2649 EMULONG lt
, lta
, ltb
;
2652 /* Return any NaN input. */
2663 /* Zero over zero, or infinity over infinity, is a NaN. */
2664 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2665 || (eisinf (a
) && eisinf (b
)))
2667 mtherr ("ediv", INVALID
);
2668 enan (c
, eisneg (a
) ^ eisneg (b
));
2672 /* Infinity over anything else is infinity. */
2676 if (eisneg (a
) ^ eisneg (b
))
2677 *(c
+ (NE
- 1)) = 0x8000;
2679 *(c
+ (NE
- 1)) = 0;
2683 /* Anything else over infinity is zero. */
2695 { /* See if numerator is zero. */
2696 for (i
= 1; i
< NI
- 1; i
++)
2700 ltb
-= enormlz (bi
);
2710 { /* possible divide by zero */
2711 for (i
= 1; i
< NI
- 1; i
++)
2715 lta
-= enormlz (ai
);
2720 *(c
+ (NE
- 1)) = 0;
2722 *(c
+ (NE
- 1)) = 0x8000;
2723 /* Divide by zero is not an invalid operation.
2724 It is a divide-by-zero operation! */
2726 mtherr ("ediv", SING
);
2732 /* calculate exponent */
2733 lt
= ltb
- lta
+ EXONE
;
2734 emdnorm (bi
, i
, 0, lt
, 64);
2748 ; unsigned EMUSHORT a[NE], b[NE], c[NE];
2749 ; emul (a, b, c); c = b * a
2753 unsigned EMUSHORT
*a
, *b
, *c
;
2755 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2757 EMULONG lt
, lta
, ltb
;
2760 /* NaN times anything is the same NaN. */
2771 /* Zero times infinity is a NaN. */
2772 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2773 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2775 mtherr ("emul", INVALID
);
2776 enan (c
, eisneg (a
) ^ eisneg (b
));
2780 /* Infinity times anything else is infinity. */
2782 if (eisinf (a
) || eisinf (b
))
2784 if (eisneg (a
) ^ eisneg (b
))
2785 *(c
+ (NE
- 1)) = 0x8000;
2787 *(c
+ (NE
- 1)) = 0;
2798 for (i
= 1; i
< NI
- 1; i
++)
2802 lta
-= enormlz (ai
);
2813 for (i
= 1; i
< NI
- 1; i
++)
2817 ltb
-= enormlz (bi
);
2826 /* Multiply significands */
2828 /* calculate exponent */
2829 lt
= lta
+ ltb
- (EXONE
- 1);
2830 emdnorm (bi
, j
, 0, lt
, 64);
2831 /* calculate sign of product */
2843 ; Convert IEEE double precision to e type
2845 ; unsigned EMUSHORT x[N+2];
2850 unsigned EMUSHORT
*pe
, *y
;
2854 dectoe (pe
, y
); /* see etodec.c */
2859 ibmtoe (pe
, y
, DFmode
);
2862 register unsigned EMUSHORT r
;
2863 register unsigned EMUSHORT
*e
, *p
;
2864 unsigned EMUSHORT yy
[NI
];
2868 denorm
= 0; /* flag if denormalized number */
2877 yy
[M
] = (r
& 0x0f) | 0x10;
2878 r
&= ~0x800f; /* strip sign and 4 significand bits */
2884 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
2885 || (pe
[1] != 0) || (pe
[0] != 0))
2887 enan (y
, yy
[0] != 0);
2891 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
2892 || (pe
[2] != 0) || (pe
[3] != 0))
2894 enan (y
, yy
[0] != 0);
2905 #endif /* INFINITY */
2907 /* If zero exponent, then the significand is denormalized.
2908 * So, take back the understood high significand bit. */
2930 { /* if zero exponent, then normalize the significand */
2931 if ((k
= enormlz (yy
)) > NBITS
)
2934 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
2937 #endif /* not IBM */
2938 #endif /* not DEC */
2943 unsigned EMUSHORT
*pe
, *y
;
2945 unsigned EMUSHORT yy
[NI
];
2946 unsigned EMUSHORT
*e
, *p
, *q
;
2951 for (i
= 0; i
< NE
- 5; i
++)
2954 for (i
= 0; i
< 5; i
++)
2957 /* This precision is not ordinarily supported on DEC or IBM. */
2959 for (i
= 0; i
< 5; i
++)
2963 p
= &yy
[0] + (NE
- 1);
2966 for (i
= 0; i
< 5; i
++)
2970 p
= &yy
[0] + (NE
- 1);
2973 for (i
= 0; i
< 4; i
++)
2983 for (i
= 0; i
< 4; i
++)
2987 enan (y
, (*p
& 0x8000) != 0);
2992 for (i
= 1; i
<= 4; i
++)
2996 enan (y
, (*p
& 0x8000) != 0);
3008 #endif /* INFINITY */
3009 for (i
= 0; i
< NE
; i
++)
3016 unsigned EMUSHORT
*pe
, *y
;
3018 register unsigned EMUSHORT r
;
3019 unsigned EMUSHORT
*e
, *p
;
3020 unsigned EMUSHORT yy
[NI
];
3039 for (i
= 0; i
< 7; i
++)
3043 enan (y
, yy
[0] != 0);
3048 for (i
= 1; i
< 8; i
++)
3052 enan (y
, yy
[0] != 0);
3064 #endif /* INFINITY */
3068 for (i
= 0; i
< 7; i
++)
3073 for (i
= 0; i
< 7; i
++)
3076 /* If denormal, remove the implied bit; else shift down 1. */
3091 ; Convert IEEE single precision to e type
3093 ; unsigned EMUSHORT x[N+2];
3098 unsigned EMUSHORT
*pe
, *y
;
3102 ibmtoe (pe
, y
, SFmode
);
3105 register unsigned EMUSHORT r
;
3106 register unsigned EMUSHORT
*e
, *p
;
3107 unsigned EMUSHORT yy
[NI
];
3111 denorm
= 0; /* flag if denormalized number */
3123 yy
[M
] = (r
& 0x7f) | 0200;
3124 r
&= ~0x807f; /* strip sign and 7 significand bits */
3130 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3132 enan (y
, yy
[0] != 0);
3136 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3138 enan (y
, yy
[0] != 0);
3149 #endif /* INFINITY */
3151 /* If zero exponent, then the significand is denormalized.
3152 * So, take back the understood high significand bit. */
3173 { /* if zero exponent, then normalize the significand */
3174 if ((k
= enormlz (yy
)) > NBITS
)
3177 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3180 #endif /* not IBM */
3186 unsigned EMUSHORT
*x
, *e
;
3188 unsigned EMUSHORT xi
[NI
];
3195 make_nan (e
, eisneg (x
), TFmode
);
3200 exp
= (EMULONG
) xi
[E
];
3205 /* round off to nearest or even */
3208 emdnorm (xi
, 0, 0, exp
, 64);
3214 /* move out internal format to ieee long double */
3217 unsigned EMUSHORT
*a
, *b
;
3219 register unsigned EMUSHORT
*p
, *q
;
3220 unsigned EMUSHORT i
;
3225 make_nan (b
, eiisneg (a
), TFmode
);
3233 q
= b
+ 7; /* point to output exponent */
3236 /* If not denormal, delete the implied bit. */
3241 /* combine sign and exponent */
3245 *q
++ = *p
++ | 0x8000;
3250 *q
-- = *p
++ | 0x8000;
3254 /* skip over guard word */
3256 /* move the significand */
3258 for (i
= 0; i
< 7; i
++)
3261 for (i
= 0; i
< 7; i
++)
3268 unsigned EMUSHORT
*x
, *e
;
3270 unsigned EMUSHORT xi
[NI
];
3277 make_nan (e
, eisneg (x
), XFmode
);
3282 /* adjust exponent for offset */
3283 exp
= (EMULONG
) xi
[E
];
3288 /* round off to nearest or even */
3291 emdnorm (xi
, 0, 0, exp
, 64);
3297 /* move out internal format to ieee long double */
3300 unsigned EMUSHORT
*a
, *b
;
3302 register unsigned EMUSHORT
*p
, *q
;
3303 unsigned EMUSHORT i
;
3308 make_nan (b
, eiisneg (a
), XFmode
);
3313 #if defined(MIEEE) || defined(IBM)
3316 q
= b
+ 4; /* point to output exponent */
3317 #if LONG_DOUBLE_TYPE_SIZE == 96
3318 /* Clear the last two bytes of 12-byte Intel format */
3323 /* combine sign and exponent */
3325 #if defined(MIEEE) || defined(IBM)
3327 *q
++ = *p
++ | 0x8000;
3333 *q
-- = *p
++ | 0x8000;
3337 /* skip over guard word */
3339 /* move the significand */
3340 #if defined(MIEEE) || defined(IBM)
3341 for (i
= 0; i
< 4; i
++)
3344 for (i
= 0; i
< 4; i
++)
3351 ; e type to IEEE double precision
3353 ; unsigned EMUSHORT x[NE];
3361 unsigned EMUSHORT
*x
, *e
;
3363 etodec (x
, e
); /* see etodec.c */
3368 unsigned EMUSHORT
*x
, *y
;
3378 unsigned EMUSHORT
*x
, *e
;
3380 etoibm (x
, e
, DFmode
);
3385 unsigned EMUSHORT
*x
, *y
;
3387 toibm (x
, y
, DFmode
);
3390 #else /* it's neither DEC nor IBM */
3394 unsigned EMUSHORT
*x
, *e
;
3396 unsigned EMUSHORT xi
[NI
];
3403 make_nan (e
, eisneg (x
), DFmode
);
3408 /* adjust exponent for offsets */
3409 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3414 /* round off to nearest or even */
3417 emdnorm (xi
, 0, 0, exp
, 64);
3426 unsigned EMUSHORT
*x
, *y
;
3428 unsigned EMUSHORT i
;
3429 unsigned EMUSHORT
*p
;
3434 make_nan (y
, eiisneg (x
), DFmode
);
3442 *y
= 0; /* output high order */
3444 *y
= 0x8000; /* output sign bit */
3447 if (i
>= (unsigned int) 2047)
3448 { /* Saturate at largest number less than infinity. */
3463 *y
|= (unsigned EMUSHORT
) 0x7fef;
3487 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3488 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3502 #endif /* not IBM */
3503 #endif /* not DEC */
3508 ; e type to IEEE single precision
3510 ; unsigned EMUSHORT x[N+2];
3517 unsigned EMUSHORT
*x
, *e
;
3519 etoibm (x
, e
, SFmode
);
3524 unsigned EMUSHORT
*x
, *y
;
3526 toibm (x
, y
, SFmode
);
3533 unsigned EMUSHORT
*x
, *e
;
3536 unsigned EMUSHORT xi
[NI
];
3542 make_nan (e
, eisneg (x
), SFmode
);
3547 /* adjust exponent for offsets */
3548 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3553 /* round off to nearest or even */
3556 emdnorm (xi
, 0, 0, exp
, 64);
3564 unsigned EMUSHORT
*x
, *y
;
3566 unsigned EMUSHORT i
;
3567 unsigned EMUSHORT
*p
;
3572 make_nan (y
, eiisneg (x
), SFmode
);
3583 *y
= 0; /* output high order */
3585 *y
= 0x8000; /* output sign bit */
3588 /* Handle overflow cases. */
3592 *y
|= (unsigned EMUSHORT
) 0x7f80;
3603 #else /* no INFINITY */
3604 *y
|= (unsigned EMUSHORT
) 0x7f7f;
3618 #endif /* no INFINITY */
3630 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
3631 *y
|= i
; /* high order output already has sign bit set */
3643 #endif /* not IBM */
3645 /* Compare two e type numbers.
3647 * unsigned EMUSHORT a[NE], b[NE];
3650 * returns +1 if a > b
3653 * -2 if either a or b is a NaN.
3657 unsigned EMUSHORT
*a
, *b
;
3659 unsigned EMUSHORT ai
[NI
], bi
[NI
];
3660 register unsigned EMUSHORT
*p
, *q
;
3665 if (eisnan (a
) || eisnan (b
))
3674 { /* the signs are different */
3676 for (i
= 1; i
< NI
- 1; i
++)
3690 /* both are the same sign */
3705 return (0); /* equality */
3711 if (*(--p
) > *(--q
))
3712 return (msign
); /* p is bigger */
3714 return (-msign
); /* p is littler */
3720 /* Find nearest integer to x = floor (x + 0.5)
3722 * unsigned EMUSHORT x[NE], y[NE]
3727 unsigned EMUSHORT
*x
, *y
;
3737 ; convert HOST_WIDE_INT to e type
3740 ; unsigned EMUSHORT x[NE];
3742 ; note &l is the memory address of l
3747 unsigned EMUSHORT
*y
;
3749 unsigned EMUSHORT yi
[NI
];
3750 unsigned HOST_WIDE_INT ll
;
3756 /* make it positive */
3757 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
3758 yi
[0] = 0xffff; /* put correct sign in the e type number */
3762 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
3764 /* move the long integer to yi significand area */
3765 #if HOST_BITS_PER_WIDE_INT == 64
3766 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
3767 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
3768 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
3769 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
3770 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
3772 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
3773 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
3774 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
3777 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
3778 ecleaz (yi
); /* it was zero */
3780 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
3781 emovo (yi
, y
); /* output the answer */
3785 ; convert unsigned HOST_WIDE_INT to e type
3787 ; unsigned HOST_WIDE_INT l;
3788 ; unsigned EMUSHORT x[NE];
3790 ; note &l is the memory address of l
3794 unsigned HOST_WIDE_INT
*lp
;
3795 unsigned EMUSHORT
*y
;
3797 unsigned EMUSHORT yi
[NI
];
3798 unsigned HOST_WIDE_INT ll
;
3804 /* move the long integer to ayi significand area */
3805 #if HOST_BITS_PER_WIDE_INT == 64
3806 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
3807 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
3808 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
3809 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
3810 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
3812 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
3813 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
3814 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
3817 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
3818 ecleaz (yi
); /* it was zero */
3820 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
3821 emovo (yi
, y
); /* output the answer */
3826 ; Find signed HOST_WIDE_INT integer and floating point fractional parts
3829 ; unsigned EMUSHORT x[NE], frac[NE];
3830 ; xifrac (x, &i, frac);
3832 The integer output has the sign of the input. The fraction is
3833 the positive fractional part of abs (x).
3837 unsigned EMUSHORT
*x
;
3839 unsigned EMUSHORT
*frac
;
3841 unsigned EMUSHORT xi
[NI
];
3843 unsigned HOST_WIDE_INT ll
;
3846 k
= (int) xi
[E
] - (EXONE
- 1);
3849 /* if exponent <= 0, integer = 0 and real output is fraction */
3854 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
3856 /* long integer overflow: output large integer
3857 and correct fraction */
3859 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
3861 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
3864 warning ("overflow on truncation to integer");
3868 /* Shift more than 16 bits: first shift up k-16 mod 16,
3869 then shift up by 16's. */
3870 j
= k
- ((k
>> 4) << 4);
3877 ll
= (ll
<< 16) | xi
[M
];
3879 while ((k
-= 16) > 0);
3886 /* shift not more than 16 bits */
3888 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
3895 if ((k
= enormlz (xi
)) > NBITS
)
3898 xi
[E
] -= (unsigned EMUSHORT
) k
;
3904 /* Find unsigned HOST_WIDE_INT integer and floating point fractional parts.
3905 A negative e type input yields integer output = 0
3906 but correct fraction. */
3909 euifrac (x
, i
, frac
)
3910 unsigned EMUSHORT
*x
;
3911 unsigned HOST_WIDE_INT
*i
;
3912 unsigned EMUSHORT
*frac
;
3914 unsigned HOST_WIDE_INT ll
;
3915 unsigned EMUSHORT xi
[NI
];
3919 k
= (int) xi
[E
] - (EXONE
- 1);
3922 /* if exponent <= 0, integer = 0 and argument is fraction */
3927 if (k
> HOST_BITS_PER_WIDE_INT
)
3929 /* Long integer overflow: output large integer
3930 and correct fraction.
3931 Note, the BSD microvax compiler says that ~(0UL)
3932 is a syntax error. */
3936 warning ("overflow on truncation to unsigned integer");
3940 /* Shift more than 16 bits: first shift up k-16 mod 16,
3941 then shift up by 16's. */
3942 j
= k
- ((k
>> 4) << 4);
3949 ll
= (ll
<< 16) | xi
[M
];
3951 while ((k
-= 16) > 0);
3956 /* shift not more than 16 bits */
3958 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
3961 if (xi
[0]) /* A negative value yields unsigned integer 0. */
3967 if ((k
= enormlz (xi
)) > NBITS
)
3970 xi
[E
] -= (unsigned EMUSHORT
) k
;
3980 ; Shifts significand area up or down by the number of bits
3981 ; given by the variable sc.
3985 unsigned EMUSHORT
*x
;
3988 unsigned EMUSHORT lost
;
3989 unsigned EMUSHORT
*p
;
4002 lost
|= *p
; /* remember lost bits */
4043 return ((int) lost
);
4051 ; Shift normalizes the significand area pointed to by argument
4052 ; shift count (up = positive) is returned.
4056 unsigned EMUSHORT x
[];
4058 register unsigned EMUSHORT
*p
;
4067 return (0); /* already normalized */
4072 /* With guard word, there are NBITS+16 bits available.
4073 * return true if all are zero.
4078 /* see if high byte is zero */
4079 while ((*p
& 0xff00) == 0)
4084 /* now shift 1 bit at a time */
4085 while ((*p
& 0x8000) == 0)
4091 mtherr ("enormlz", UNDERFLOW
);
4097 /* Normalize by shifting down out of the high guard word
4098 of the significand */
4113 mtherr ("enormlz", OVERFLOW
);
4123 /* Convert e type number to decimal format ASCII string.
4124 * The constants are for 64 bit precision.
4130 #if LONG_DOUBLE_TYPE_SIZE == 128
4131 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4133 {0x6576, 0x4a92, 0x804a, 0x153f,
4134 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4135 {0x6a32, 0xce52, 0x329a, 0x28ce,
4136 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4137 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4138 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4139 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4140 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4141 {0x851e, 0xeab7, 0x98fe, 0x901b,
4142 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4143 {0x0235, 0x0137, 0x36b1, 0x336c,
4144 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4145 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4146 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4147 {0x0000, 0x0000, 0x0000, 0x0000,
4148 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4149 {0x0000, 0x0000, 0x0000, 0x0000,
4150 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4151 {0x0000, 0x0000, 0x0000, 0x0000,
4152 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4153 {0x0000, 0x0000, 0x0000, 0x0000,
4154 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4155 {0x0000, 0x0000, 0x0000, 0x0000,
4156 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4157 {0x0000, 0x0000, 0x0000, 0x0000,
4158 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4161 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4163 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4164 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4165 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4166 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4167 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4168 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4169 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4170 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4171 {0xa23e, 0x5308, 0xfefb, 0x1155,
4172 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4173 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4174 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4175 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4176 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4177 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4178 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4179 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4180 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4181 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4182 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4183 {0xc155, 0xa4a8, 0x404e, 0x6113,
4184 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4185 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4186 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4187 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4188 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4191 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4192 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4194 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4195 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4196 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4197 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4198 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4199 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4200 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4201 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4202 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4203 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4204 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4205 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4206 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4209 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4211 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4212 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4213 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4214 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4215 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4216 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4217 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4218 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4219 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4220 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4221 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4222 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4223 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4228 e24toasc (x
, string
, ndigs
)
4229 unsigned EMUSHORT x
[];
4233 unsigned EMUSHORT w
[NI
];
4236 etoasc (w
, string
, ndigs
);
4241 e53toasc (x
, string
, ndigs
)
4242 unsigned EMUSHORT x
[];
4246 unsigned EMUSHORT w
[NI
];
4249 etoasc (w
, string
, ndigs
);
4254 e64toasc (x
, string
, ndigs
)
4255 unsigned EMUSHORT x
[];
4259 unsigned EMUSHORT w
[NI
];
4262 etoasc (w
, string
, ndigs
);
4266 e113toasc (x
, string
, ndigs
)
4267 unsigned EMUSHORT x
[];
4271 unsigned EMUSHORT w
[NI
];
4274 etoasc (w
, string
, ndigs
);
4278 static char wstring
[80]; /* working storage for ASCII output */
4281 etoasc (x
, string
, ndigs
)
4282 unsigned EMUSHORT x
[];
4287 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4288 unsigned EMUSHORT
*p
, *r
, *ten
;
4289 unsigned EMUSHORT sign
;
4290 int i
, j
, k
, expon
, rndsav
;
4292 unsigned EMUSHORT m
;
4303 sprintf (wstring
, " NaN ");
4307 rndprc
= NBITS
; /* set to full precision */
4308 emov (x
, y
); /* retain external format */
4309 if (y
[NE
- 1] & 0x8000)
4312 y
[NE
- 1] &= 0x7fff;
4319 ten
= &etens
[NTEN
][0];
4321 /* Test for zero exponent */
4324 for (k
= 0; k
< NE
- 1; k
++)
4327 goto tnzro
; /* denormalized number */
4329 goto isone
; /* legal all zeros */
4333 /* Test for infinity. */
4334 if (y
[NE
- 1] == 0x7fff)
4337 sprintf (wstring
, " -Infinity ");
4339 sprintf (wstring
, " Infinity ");
4343 /* Test for exponent nonzero but significand denormalized.
4344 * This is an error condition.
4346 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4348 mtherr ("etoasc", DOMAIN
);
4349 sprintf (wstring
, "NaN");
4353 /* Compare to 1.0 */
4362 { /* Number is greater than 1 */
4363 /* Convert significand to an integer and strip trailing decimal zeros. */
4365 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4367 p
= &etens
[NTEN
- 4][0];
4373 for (j
= 0; j
< NE
- 1; j
++)
4386 /* Rescale from integer significand */
4387 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4389 /* Find power of 10 */
4393 /* An unordered compare result shouldn't happen here. */
4394 while (ecmp (ten
, u
) <= 0)
4396 if (ecmp (p
, u
) <= 0)
4409 { /* Number is less than 1.0 */
4410 /* Pad significand with trailing decimal zeros. */
4413 while ((y
[NE
- 2] & 0x8000) == 0)
4422 for (i
= 0; i
< NDEC
+ 1; i
++)
4424 if ((w
[NI
- 1] & 0x7) != 0)
4426 /* multiply by 10 */
4439 if (eone
[NE
- 1] <= u
[1])
4451 while (ecmp (eone
, w
) > 0)
4453 if (ecmp (p
, w
) >= 0)
4468 /* Find the first (leading) digit. */
4474 digit
= equot
[NI
- 1];
4475 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4483 digit
= equot
[NI
- 1];
4491 /* Examine number of digits requested by caller. */
4509 *s
++ = (char)digit
+ '0';
4512 /* Generate digits after the decimal point. */
4513 for (k
= 0; k
<= ndigs
; k
++)
4515 /* multiply current number by 10, without normalizing */
4522 *s
++ = (char) equot
[NI
- 1] + '0';
4524 digit
= equot
[NI
- 1];
4527 /* round off the ASCII string */
4530 /* Test for critical rounding case in ASCII output. */
4534 if (ecmp (t
, ezero
) != 0)
4535 goto roun
; /* round to nearest */
4536 if ((*(s
- 1) & 1) == 0)
4537 goto doexp
; /* round to even */
4539 /* Round up and propagate carry-outs */
4543 /* Carry out to most significant digit? */
4550 /* Most significant digit carries to 10? */
4558 /* Round up and carry out from less significant digits */
4570 sprintf (ss, "e+%d", expon);
4572 sprintf (ss, "e%d", expon);
4574 sprintf (ss
, "e%d", expon
);
4577 /* copy out the working string */
4580 while (*ss
== ' ') /* strip possible leading space */
4582 while ((*s
++ = *ss
++) != '\0')
4591 ; ASCTOQ.MAC LATEST REV: 11 JAN 84
4594 ; Convert ASCII string to quadruple precision floating point
4596 ; Numeric input is free field decimal number
4597 ; with max of 15 digits with or without
4598 ; decimal point entered as ASCII from teletype.
4599 ; Entering E after the number followed by a second
4600 ; number causes the second number to be interpreted
4601 ; as a power of 10 to be multiplied by the first number
4602 ; (i.e., "scientific" notation).
4605 ; asctoq (string, q);
4608 /* ASCII to single */
4612 unsigned EMUSHORT
*y
;
4618 /* ASCII to double */
4622 unsigned EMUSHORT
*y
;
4624 #if defined(DEC) || defined(IBM)
4632 /* ASCII to long double */
4636 unsigned EMUSHORT
*y
;
4641 /* ASCII to 128-bit long double */
4645 unsigned EMUSHORT
*y
;
4647 asctoeg (s
, y
, 113);
4650 /* ASCII to super double */
4654 unsigned EMUSHORT
*y
;
4656 asctoeg (s
, y
, NBITS
);
4660 /* ASCII to e type, with specified rounding precision = oprec. */
4662 asctoeg (ss
, y
, oprec
)
4664 unsigned EMUSHORT
*y
;
4667 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
4668 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
4669 int k
, trail
, c
, rndsav
;
4671 unsigned EMUSHORT nsign
, *p
;
4672 char *sp
, *s
, *lstr
;
4674 /* Copy the input string. */
4675 lstr
= (char *) alloca (strlen (ss
) + 1);
4677 while (*s
== ' ') /* skip leading spaces */
4680 while ((*sp
++ = *s
++) != '\0')
4685 rndprc
= NBITS
; /* Set to full precision */
4698 if ((k
>= 0) && (k
<= 9))
4700 /* Ignore leading zeros */
4701 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
4703 /* Identify and strip trailing zeros after the decimal point. */
4704 if ((trail
== 0) && (decflg
!= 0))
4707 while ((*sp
>= '0') && (*sp
<= '9'))
4709 /* Check for syntax error */
4711 if ((c
!= 'e') && (c
!= 'E') && (c
!= '\0')
4712 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
4722 /* If enough digits were given to more than fill up the yy register,
4723 * continuing until overflow into the high guard word yy[2]
4724 * guarantees that there will be a roundoff bit at the top
4725 * of the low guard word after normalization.
4730 nexp
+= 1; /* count digits after decimal point */
4731 eshup1 (yy
); /* multiply current number by 10 */
4737 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
4742 /* Mark any lost non-zero digit. */
4744 /* Count lost digits before the decimal point. */
4759 case '.': /* decimal point */
4789 mtherr ("asctoe", DOMAIN
);
4798 /* Exponent interpretation */
4804 /* check for + or - */
4812 while ((*s
>= '0') && (*s
<= '9'))
4816 if (exp
> -(MINDECEXP
))
4826 if (exp
> MAXDECEXP
)
4830 yy
[E
] = 0x7fff; /* infinity */
4833 if (exp
< MINDECEXP
)
4842 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
4843 while ((nexp
> 0) && (yy
[2] == 0))
4855 if ((k
= enormlz (yy
)) > NBITS
)
4860 lexp
= (EXONE
- 1 + NBITS
) - k
;
4861 emdnorm (yy
, lost
, 0, lexp
, 64);
4862 /* convert to external format */
4865 /* Multiply by 10**nexp. If precision is 64 bits,
4866 * the maximum relative error incurred in forming 10**n
4867 * for 0 <= n <= 324 is 8.2e-20, at 10**180.
4868 * For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
4869 * For 0 >= n >= -999, it is -1.55e-19 at 10**-435.
4883 { /* Punt. Can't handle this without 2 divides. */
4884 emovi (etens
[0], tt
);
4891 p
= &etens
[NTEN
][0];
4901 while (exp
<= MAXP
);
4919 /* Round and convert directly to the destination type */
4921 lexp
-= EXONE
- 0x3ff;
4923 else if (oprec
== 24 || oprec
== 56)
4924 lexp
-= EXONE
- (0x41 << 2);
4926 else if (oprec
== 24)
4927 lexp
-= EXONE
- 0177;
4930 else if (oprec
== 56)
4931 lexp
-= EXONE
- 0201;
4934 emdnorm (yy
, k
, 0, lexp
, 64);
4944 todec (yy
, y
); /* see etodec.c */
4949 toibm (yy
, y
, DFmode
);
4972 /* y = largest integer not greater than x
4973 * (truncated toward minus infinity)
4975 * unsigned EMUSHORT x[NE], y[NE]
4979 static unsigned EMUSHORT bmask
[] =
5002 unsigned EMUSHORT x
[], y
[];
5004 register unsigned EMUSHORT
*p
;
5006 unsigned EMUSHORT f
[NE
];
5008 emov (x
, f
); /* leave in external format */
5009 expon
= (int) f
[NE
- 1];
5010 e
= (expon
& 0x7fff) - (EXONE
- 1);
5016 /* number of bits to clear out */
5028 /* clear the remaining bits */
5030 /* truncate negatives toward minus infinity */
5033 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5035 for (i
= 0; i
< NE
- 1; i
++)
5047 /* unsigned EMUSHORT x[], s[];
5050 * efrexp (x, exp, s);
5052 * Returns s and exp such that s * 2**exp = x and .5 <= s < 1.
5053 * For example, 1.1 = 0.55 * 2**1
5054 * Handles denormalized numbers properly using long integer exp.
5058 unsigned EMUSHORT x
[];
5060 unsigned EMUSHORT s
[];
5062 unsigned EMUSHORT xi
[NI
];
5066 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5074 *exp
= (int) (li
- 0x3ffe);
5079 /* unsigned EMUSHORT x[], y[];
5082 * eldexp (x, pwr2, y);
5084 * Returns y = x * 2**pwr2.
5088 unsigned EMUSHORT x
[];
5090 unsigned EMUSHORT y
[];
5092 unsigned EMUSHORT xi
[NI
];
5100 emdnorm (xi
, i
, i
, li
, 64);
5105 /* c = remainder after dividing b by a
5106 * Least significant integer quotient bits left in equot[].
5110 unsigned EMUSHORT a
[], b
[], c
[];
5112 unsigned EMUSHORT den
[NI
], num
[NI
];
5116 || (ecmp (a
, ezero
) == 0)
5124 if (ecmp (a
, ezero
) == 0)
5126 mtherr ("eremain", SING
);
5132 eiremain (den
, num
);
5133 /* Sign of remainder = sign of quotient */
5143 unsigned EMUSHORT den
[], num
[];
5146 unsigned EMUSHORT j
;
5149 ld
-= enormlz (den
);
5151 ln
-= enormlz (num
);
5155 if (ecmpm (den
, num
) <= 0)
5169 emdnorm (num
, 0, 0, ln
, 0);
5174 * Library common error handling routine
5184 * mtherr (fctnam, code);
5190 * This routine may be called to report one of the following
5191 * error conditions (in the include file mconf.h).
5193 * Mnemonic Value Significance
5195 * DOMAIN 1 argument domain error
5196 * SING 2 function singularity
5197 * OVERFLOW 3 overflow range error
5198 * UNDERFLOW 4 underflow range error
5199 * TLOSS 5 total loss of precision
5200 * PLOSS 6 partial loss of precision
5201 * INVALID 7 NaN - producing operation
5202 * EDOM 33 Unix domain error code
5203 * ERANGE 34 Unix range error code
5205 * The default version of the file prints the function name,
5206 * passed to it by the pointer fctnam, followed by the
5207 * error condition. The display is directed to the standard
5208 * output device. The routine then returns to the calling
5209 * program. Users may wish to modify the program to abort by
5210 * calling exit under severe error conditions such as domain
5213 * Since all error conditions pass control to this function,
5214 * the display may be easily changed, eliminated, or directed
5215 * to an error logging device.
5224 Cephes Math Library Release 2.0: April, 1987
5225 Copyright 1984, 1987 by Stephen L. Moshier
5226 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
5229 /* include "mconf.h" */
5231 /* Notice: the order of appearance of the following
5232 * messages is bound to the error codes defined
5236 static char *ermsg
[NMSGS
] =
5238 "unknown", /* error code 0 */
5239 "domain", /* error code 1 */
5240 "singularity", /* et seq. */
5243 "total loss of precision",
5244 "partial loss of precision",
5258 /* Display string passed by calling program,
5259 * which is supposed to be the name of the
5260 * function in which the error occurred.
5263 /* Display error message defined
5264 * by the code argument.
5266 if ((code
<= 0) || (code
>= NMSGS
))
5268 sprintf (errstr
, " %s %s error", name
, ermsg
[code
]);
5271 /* Set global error message word */
5274 /* Return to calling
5280 /* Here is etodec.c .
5285 ; convert DEC double precision to e type
5292 unsigned EMUSHORT
*d
;
5293 unsigned EMUSHORT
*e
;
5295 unsigned EMUSHORT y
[NI
];
5296 register unsigned EMUSHORT r
, *p
;
5298 ecleaz (y
); /* start with a zero */
5299 p
= y
; /* point to our number */
5300 r
= *d
; /* get DEC exponent word */
5301 if (*d
& (unsigned int) 0x8000)
5302 *p
= 0xffff; /* fill in our sign */
5303 ++p
; /* bump pointer to our exponent word */
5304 r
&= 0x7fff; /* strip the sign bit */
5305 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5309 r
>>= 7; /* shift exponent word down 7 bits */
5310 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5311 /* add our e type exponent offset */
5312 *p
++ = r
; /* to form our exponent */
5314 r
= *d
++; /* now do the high order mantissa */
5315 r
&= 0177; /* strip off the DEC exponent and sign bits */
5316 r
|= 0200; /* the DEC understood high order mantissa bit */
5317 *p
++ = r
; /* put result in our high guard word */
5319 *p
++ = *d
++; /* fill in the rest of our mantissa */
5323 eshdn8 (y
); /* shift our mantissa down 8 bits */
5331 ; convert e type to DEC double precision
5339 unsigned EMUSHORT
*x
, *d
;
5341 unsigned EMUSHORT xi
[NI
];
5346 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201); /* adjust exponent for offsets */
5347 /* round off to nearest or even */
5350 emdnorm (xi
, 0, 0, exp
, 64);
5357 unsigned EMUSHORT
*x
, *y
;
5359 unsigned EMUSHORT i
;
5360 unsigned EMUSHORT
*p
;
5404 ; convert IBM single/double precision to e type
5407 ; enum machine_mode mode; SFmode/DFmode
5408 ; ibmtoe (&d, e, mode);
5412 unsigned EMUSHORT
*d
;
5413 unsigned EMUSHORT
*e
;
5414 enum machine_mode mode
;
5416 unsigned EMUSHORT y
[NI
];
5417 register unsigned EMUSHORT r
, *p
;
5420 ecleaz (y
); /* start with a zero */
5421 p
= y
; /* point to our number */
5422 r
= *d
; /* get IBM exponent word */
5423 if (*d
& (unsigned int) 0x8000)
5424 *p
= 0xffff; /* fill in our sign */
5425 ++p
; /* bump pointer to our exponent word */
5426 r
&= 0x7f00; /* strip the sign bit */
5427 r
>>= 6; /* shift exponent word down 6 bits */
5428 /* in fact shift by 8 right and 2 left */
5429 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5430 /* add our e type exponent offset */
5431 *p
++ = r
; /* to form our exponent */
5433 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5434 /* strip off the IBM exponent and sign bits */
5435 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5437 *p
++ = *d
++; /* fill in the rest of our mantissa */
5442 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5445 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5446 /* handle change in RADIX */
5453 ; convert e type to IBM single/double precision
5456 ; enum machine_mode mode; SFmode/DFmode
5457 ; etoibm (e, &d, mode);
5462 unsigned EMUSHORT
*x
, *d
;
5463 enum machine_mode mode
;
5465 unsigned EMUSHORT xi
[NI
];
5470 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5471 /* round off to nearest or even */
5474 emdnorm (xi
, 0, 0, exp
, 64);
5476 toibm (xi
, d
, mode
);
5481 unsigned EMUSHORT
*x
, *y
;
5482 enum machine_mode mode
;
5484 unsigned EMUSHORT i
;
5485 unsigned EMUSHORT
*p
;
5533 /* Output a binary NaN bit pattern in the target machine's format. */
5535 /* If special NaN bit patterns are required, define them in tm.h
5536 as arrays of unsigned 16-bit shorts. Otherwise, use the default
5542 unsigned EMUSHORT TFnan
[8] =
5543 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5546 unsigned EMUSHORT TFnan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
5554 unsigned EMUSHORT XFnan
[6] = {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5557 unsigned EMUSHORT XFnan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
5565 unsigned EMUSHORT DFnan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
5568 unsigned EMUSHORT DFnan
[4] = {0, 0, 0, 0xfff8};
5576 unsigned EMUSHORT SFnan
[2] = {0x7fff, 0xffff};
5579 unsigned EMUSHORT SFnan
[2] = {0, 0xffc0};
5585 make_nan (nan
, sign
, mode
)
5586 unsigned EMUSHORT
*nan
;
5588 enum machine_mode mode
;
5591 unsigned EMUSHORT
*p
;
5595 /* Possibly the `reserved operand' patterns on a VAX can be
5596 used like NaN's, but probably not in the same way as IEEE. */
5597 #if !defined(DEC) && !defined(IBM)
5619 *nan
++ = (sign
<< 15) | *p
++;
5624 *nan
= (sign
<< 15) | *p
;
5628 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
5629 This is the inverse of the function `etarsingle' invoked by
5630 REAL_VALUE_TO_TARGET_SINGLE. */
5633 ereal_from_float (f
)
5637 unsigned EMUSHORT s
[2];
5638 unsigned EMUSHORT e
[NE
];
5640 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
5641 This is the inverse operation to what the function `endian' does. */
5642 #if FLOAT_WORDS_BIG_ENDIAN
5643 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
5644 s
[1] = (unsigned EMUSHORT
) f
;
5646 s
[0] = (unsigned EMUSHORT
) f
;
5647 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
5649 /* Convert and promote the target float to E-type. */
5651 /* Output E-type to REAL_VALUE_TYPE. */
5657 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
5658 This is the inverse of the function `etardouble' invoked by
5659 REAL_VALUE_TO_TARGET_DOUBLE.
5661 The DFmode is stored as an array of long ints
5662 with 32 bits of the value per each long. The first element
5663 of the input array holds the bits that would come first in the
5664 target computer's memory. */
5667 ereal_from_double (d
)
5671 unsigned EMUSHORT s
[4];
5672 unsigned EMUSHORT e
[NE
];
5674 /* Convert array of 32 bit pieces to equivalent array of 16 bit pieces.
5675 This is the inverse of `endian'. */
5676 #if FLOAT_WORDS_BIG_ENDIAN
5677 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
5678 s
[1] = (unsigned EMUSHORT
) d
[0];
5679 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
5680 s
[3] = (unsigned EMUSHORT
) d
[1];
5682 s
[0] = (unsigned EMUSHORT
) d
[0];
5683 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
5684 s
[2] = (unsigned EMUSHORT
) d
[1];
5685 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
5687 /* Convert target double to E-type. */
5689 /* Output E-type to REAL_VALUE_TYPE. */
5695 /* Convert target computer unsigned 64-bit integer to e-type.
5696 The endian-ness of DImode follows the convention for integers,
5697 so we use WORDS_BIG_ENDIAN here, not FLOAT_WORDS_BIG_ENDIAN. */
5701 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
5702 unsigned EMUSHORT
*e
;
5704 unsigned EMUSHORT yi
[NI
];
5708 #if WORDS_BIG_ENDIAN
5709 for (k
= M
; k
< M
+ 4; k
++)
5712 for (k
= M
+ 3; k
>= M
; k
--)
5715 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
5716 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
5717 ecleaz (yi
); /* it was zero */
5719 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
5723 /* Convert target computer signed 64-bit integer to e-type. */
5727 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
5728 unsigned EMUSHORT
*e
;
5730 unsigned EMULONG acc
;
5731 unsigned EMUSHORT yi
[NI
];
5732 unsigned EMUSHORT carry
;
5736 #if WORDS_BIG_ENDIAN
5737 for (k
= M
; k
< M
+ 4; k
++)
5740 for (k
= M
+ 3; k
>= M
; k
--)
5743 /* Take absolute value */
5749 for (k
= M
+ 3; k
>= M
; k
--)
5751 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
5758 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
5759 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
5760 ecleaz (yi
); /* it was zero */
5762 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
5769 /* Convert e-type to unsigned 64-bit int. */
5773 unsigned EMUSHORT
*x
;
5774 unsigned EMUSHORT
*i
;
5776 unsigned EMUSHORT xi
[NI
];
5785 k
= (int) xi
[E
] - (EXONE
- 1);
5788 for (j
= 0; j
< 4; j
++)
5794 for (j
= 0; j
< 4; j
++)
5797 warning ("overflow on truncation to integer");
5802 /* Shift more than 16 bits: first shift up k-16 mod 16,
5803 then shift up by 16's. */
5804 j
= k
- ((k
>> 4) << 4);
5808 #if WORDS_BIG_ENDIAN
5818 #if WORDS_BIG_ENDIAN
5824 while ((k
-= 16) > 0);
5828 /* shift not more than 16 bits */
5833 #if WORDS_BIG_ENDIAN
5849 /* Convert e-type to signed 64-bit int. */
5853 unsigned EMUSHORT
*x
;
5854 unsigned EMUSHORT
*i
;
5856 unsigned EMULONG acc
;
5857 unsigned EMUSHORT xi
[NI
];
5858 unsigned EMUSHORT carry
;
5859 unsigned EMUSHORT
*isave
;
5863 k
= (int) xi
[E
] - (EXONE
- 1);
5866 for (j
= 0; j
< 4; j
++)
5872 for (j
= 0; j
< 4; j
++)
5875 warning ("overflow on truncation to integer");
5881 /* Shift more than 16 bits: first shift up k-16 mod 16,
5882 then shift up by 16's. */
5883 j
= k
- ((k
>> 4) << 4);
5887 #if WORDS_BIG_ENDIAN
5897 #if WORDS_BIG_ENDIAN
5903 while ((k
-= 16) > 0);
5907 /* shift not more than 16 bits */
5910 #if WORDS_BIG_ENDIAN
5923 /* Negate if negative */
5927 #if WORDS_BIG_ENDIAN
5930 for (k
= 0; k
< 4; k
++)
5932 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
5933 #if WORDS_BIG_ENDIAN
5946 /* Longhand square root routine. */
5949 static int esqinited
= 0;
5950 static unsigned short sqrndbit
[NI
];
5954 unsigned EMUSHORT
*x
, *y
;
5956 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
5958 int i
, j
, k
, n
, nlups
;
5963 sqrndbit
[NI
- 2] = 1;
5966 /* Check for arg <= 0 */
5967 i
= ecmp (x
, ezero
);
5972 mtherr ("esqrt", DOMAIN
);
5988 /* Bring in the arg and renormalize if it is denormal. */
5990 m
= (EMULONG
) xx
[1]; /* local long word exponent */
5994 /* Divide exponent by 2 */
5996 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
5998 /* Adjust if exponent odd */
6008 n
= 8; /* get 8 bits of result per inner loop */
6014 /* bring in next word of arg */
6016 num
[NI
- 1] = xx
[j
+ 3];
6017 /* Do additional bit on last outer loop, for roundoff. */
6020 for (i
= 0; i
< n
; i
++)
6022 /* Next 2 bits of arg */
6025 /* Shift up answer */
6027 /* Make trial divisor */
6028 for (k
= 0; k
< NI
; k
++)
6031 eaddm (sqrndbit
, temp
);
6032 /* Subtract and insert answer bit if it goes in */
6033 if (ecmpm (temp
, num
) <= 0)
6043 /* Adjust for extra, roundoff loop done. */
6044 exp
+= (NBITS
- 1) - rndprc
;
6046 /* Sticky bit = 1 if the remainder is nonzero. */
6048 for (i
= 3; i
< NI
; i
++)
6051 /* Renormalize and round off. */
6052 emdnorm (sq
, k
, 0, exp
, 64);
6056 #endif /* EMU_NON_COMPILE not defined */
This page took 0.290252 seconds and 5 git commands to generate.