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 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 following converts gcc macros into the ones used by this file. */
99 /* REAL_ARITHMETIC defined means that macros in real.h are
100 defined to call emulator functions. */
101 #ifdef REAL_ARITHMETIC
103 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
104 /* PDP-11, Pro350, VAX: */
106 #else /* it's not VAX */
107 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
108 /* IBM System/370 style */
110 #else /* it's also not an IBM */
111 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
113 /* Motorola IEEE, high order words come first (Sun workstation): */
115 #else /* not big-endian */
116 /* Intel IEEE, low order words come first:
119 #endif /* big-endian */
120 #else /* it's not IEEE either */
121 /* UNKnown arithmetic. We don't support this and can't go on. */
122 unknown arithmetic type
124 #endif /* not IEEE */
129 /* REAL_ARITHMETIC not defined means that the *host's* data
130 structure will be used. It may differ by endian-ness from the
131 target machine's structure and will get its ends swapped
132 accordingly (but not here). Probably only the decimal <-> binary
133 functions in this file will actually be used in this case. */
134 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
136 #else /* it's not VAX */
137 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
138 /* IBM System/370 style */
140 #else /* it's also not an IBM */
141 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
142 #ifdef HOST_WORDS_BIG_ENDIAN
144 #else /* not big-endian */
146 #endif /* big-endian */
147 #else /* it's not IEEE either */
148 unknown arithmetic type
150 #endif /* not IEEE */
154 #endif /* REAL_ARITHMETIC not defined */
156 /* Define INFINITY for support of infinity.
157 Define NANS for support of Not-a-Number's (NaN's). */
158 #if !defined(DEC) && !defined(IBM)
163 /* Support of NaNs requires support of infinity. */
170 /* Find a host integer type that is at least 16 bits wide,
171 and another type at least twice whatever that size is. */
173 #if HOST_BITS_PER_CHAR >= 16
174 #define EMUSHORT char
175 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
176 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
178 #if HOST_BITS_PER_SHORT >= 16
179 #define EMUSHORT short
180 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
181 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
183 #if HOST_BITS_PER_INT >= 16
185 #define EMUSHORT_SIZE HOST_BITS_PER_INT
186 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
188 #if HOST_BITS_PER_LONG >= 16
189 #define EMUSHORT long
190 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
191 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
193 /* You will have to modify this program to have a smaller unit size. */
194 #define EMU_NON_COMPILE
200 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
201 #define EMULONG short
203 #if HOST_BITS_PER_INT >= EMULONG_SIZE
206 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
209 #if HOST_BITS_PER_LONG_LONG >= EMULONG_SIZE
210 #define EMULONG long long int
212 /* You will have to modify this program to have a smaller unit size. */
213 #define EMU_NON_COMPILE
220 /* The host interface doesn't work if no 16-bit size exists. */
221 #if EMUSHORT_SIZE != 16
222 #define EMU_NON_COMPILE
225 /* OK to continue compilation. */
226 #ifndef EMU_NON_COMPILE
228 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
229 In GET_REAL and PUT_REAL, r and e are pointers.
230 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
231 in memory, with no holes. */
233 #if LONG_DOUBLE_TYPE_SIZE == 96
234 /* Number of 16 bit words in external e type format */
236 #define MAXDECEXP 4932
237 #define MINDECEXP -4956
238 #define GET_REAL(r,e) bcopy (r, e, 2*NE)
239 #define PUT_REAL(e,r) bcopy (e, r, 2*NE)
240 #else /* no XFmode */
241 #if LONG_DOUBLE_TYPE_SIZE == 128
243 #define MAXDECEXP 4932
244 #define MINDECEXP -4977
245 #define GET_REAL(r,e) bcopy (r, e, 2*NE)
246 #define PUT_REAL(e,r) bcopy (e, r, 2*NE)
249 #define MAXDECEXP 4932
250 #define MINDECEXP -4956
251 #ifdef REAL_ARITHMETIC
252 /* Emulator uses target format internally
253 but host stores it in host endian-ness. */
255 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
256 #define GET_REAL(r,e) e53toe ((r), (e))
257 #define PUT_REAL(e,r) etoe53 ((e), (r))
259 #else /* endian-ness differs */
260 /* emulator uses target endian-ness internally */
261 #define GET_REAL(r,e) \
262 do { EMUSHORT w[4]; \
263 w[3] = ((EMUSHORT *) r)[0]; \
264 w[2] = ((EMUSHORT *) r)[1]; \
265 w[1] = ((EMUSHORT *) r)[2]; \
266 w[0] = ((EMUSHORT *) r)[3]; \
267 e53toe (w, (e)); } while (0)
269 #define PUT_REAL(e,r) \
270 do { EMUSHORT w[4]; \
272 *((EMUSHORT *) r) = w[3]; \
273 *((EMUSHORT *) r + 1) = w[2]; \
274 *((EMUSHORT *) r + 2) = w[1]; \
275 *((EMUSHORT *) r + 3) = w[0]; } while (0)
277 #endif /* endian-ness differs */
279 #else /* not REAL_ARITHMETIC */
281 /* emulator uses host format */
282 #define GET_REAL(r,e) e53toe ((r), (e))
283 #define PUT_REAL(e,r) etoe53 ((e), (r))
285 #endif /* not REAL_ARITHMETIC */
286 #endif /* not TFmode */
287 #endif /* no XFmode */
290 /* Number of 16 bit words in internal format */
293 /* Array offset to exponent */
296 /* Array offset to high guard word */
299 /* Number of bits of precision */
300 #define NBITS ((NI-4)*16)
302 /* Maximum number of decimal digits in ASCII conversion
305 #define NDEC (NBITS*8/27)
307 /* The exponent of 1.0 */
308 #define EXONE (0x3fff)
311 extern int extra_warnings;
312 int ecmp (), enormlz (), eshift ();
313 int eisneg (), eisinf (), eisnan (), eiisinf (), eiisnan ();
314 void eadd (), esub (), emul (), ediv ();
315 void eshup1 (), eshup8 (), eshup6 (), eshdn1 (), eshdn8 (), eshdn6 ();
316 void eabs (), eneg (), emov (), eclear (), einfin (), efloor ();
317 void eldexp (), efrexp (), eifrac (), euifrac (), ltoe (), ultoe ();
318 void ereal_to_decimal (), eiinfin (), einan ();
319 void esqrt (), elog (), eexp (), etanh (), epow ();
320 void asctoe (), asctoe24 (), asctoe53 (), asctoe64 (), asctoe113 ();
321 void etoasc (), e24toasc (), e53toasc (), e64toasc (), e113toasc ();
322 void etoe64 (), etoe53 (), etoe24 (), e64toe (), e53toe (), e24toe ();
323 void etoe113 (), e113toe ();
324 void mtherr (), make_nan ();
326 extern unsigned EMUSHORT ezero[], ehalf[], eone[], etwo[];
327 extern unsigned EMUSHORT elog2[], esqrt2[];
329 /* Pack output array with 32-bit numbers obtained from
330 array containing 16-bit numbers, swapping ends if required. */
333 unsigned EMUSHORT e[];
335 enum machine_mode mode;
344 /* Swap halfwords in the fourth long. */
345 th = (unsigned long) e[6] & 0xffff;
346 t = (unsigned long) e[7] & 0xffff;
352 /* Swap halfwords in the third long. */
353 th = (unsigned long) e[4] & 0xffff;
354 t = (unsigned long) e[5] & 0xffff;
357 /* fall into the double case */
361 /* swap halfwords in the second word */
362 th = (unsigned long) e[2] & 0xffff;
363 t = (unsigned long) e[3] & 0xffff;
366 /* fall into the float case */
370 /* swap halfwords in the first word */
371 th = (unsigned long) e[0] & 0xffff;
372 t = (unsigned long) e[1] & 0xffff;
383 /* Pack the output array without swapping. */
390 /* Pack the fourth long. */
391 th = (unsigned long) e[7] & 0xffff;
392 t = (unsigned long) e[6] & 0xffff;
398 /* Pack the third long.
399 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
401 th = (unsigned long) e[5] & 0xffff;
402 t = (unsigned long) e[4] & 0xffff;
405 /* fall into the double case */
409 /* pack the second long */
410 th = (unsigned long) e[3] & 0xffff;
411 t = (unsigned long) e[2] & 0xffff;
414 /* fall into the float case */
418 /* pack the first long */
419 th = (unsigned long) e[1] & 0xffff;
420 t = (unsigned long) e[0] & 0xffff;
433 /* This is the implementation of the REAL_ARITHMETIC macro.
436 earith (value, icode, r1, r2)
437 REAL_VALUE_TYPE *value;
442 unsigned EMUSHORT d1[NE], d2[NE], v[NE];
448 /* Return NaN input back to the caller. */
451 PUT_REAL (d1, value);
456 PUT_REAL (d2, value);
460 code = (enum tree_code) icode;
468 esub (d2, d1, v); /* d1 - d2 */
476 #ifndef REAL_INFINITY
477 if (ecmp (d2, ezero) == 0)
487 ediv (d2, d1, v); /* d1/d2 */
490 case MIN_EXPR: /* min (d1,d2) */
491 if (ecmp (d1, d2) < 0)
497 case MAX_EXPR: /* max (d1,d2) */
498 if (ecmp (d1, d2) > 0)
511 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT
512 * implements REAL_VALUE_RNDZINT (x) (etrunci (x))
518 unsigned EMUSHORT f[NE], g[NE];
534 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT
535 * implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x))
541 unsigned EMUSHORT f[NE], g[NE];
557 /* This is the REAL_VALUE_ATOF function.
558 * It converts a decimal string to binary, rounding off
559 * as indicated by the machine_mode argument. Then it
560 * promotes the rounded value to REAL_VALUE_TYPE.
567 unsigned EMUSHORT tem[NE], e[NE];
596 /* Expansion of REAL_NEGATE.
602 unsigned EMUSHORT e[NE];
616 /* Round real toward zero to HOST_WIDE_INT
617 * implements REAL_VALUE_FIX (x).
623 unsigned EMUSHORT f[NE], g[NE];
630 warning ("conversion from NaN to int");
638 /* Round real toward zero to unsigned HOST_WIDE_INT
639 * implements REAL_VALUE_UNSIGNED_FIX (x).
640 * Negative input returns zero.
646 unsigned EMUSHORT f[NE], g[NE];
653 warning ("conversion from NaN to unsigned int");
662 /* REAL_VALUE_FROM_INT macro.
665 ereal_from_int (d, i, j)
669 unsigned EMUSHORT df[NE], dg[NE];
678 /* complement and add 1 */
685 eldexp (eone, HOST_BITS_PER_LONG, df);
696 /* REAL_VALUE_FROM_UNSIGNED_INT macro.
699 ereal_from_uint (d, i, j)
703 unsigned EMUSHORT df[NE], dg[NE];
704 unsigned long low, high;
708 eldexp (eone, HOST_BITS_PER_LONG, df);
717 /* REAL_VALUE_TO_INT macro
720 ereal_to_int (low, high, rr)
724 unsigned EMUSHORT d[NE], df[NE], dg[NE], dh[NE];
731 warning ("conversion from NaN to int");
737 /* convert positive value */
744 eldexp (eone, HOST_BITS_PER_LONG, df);
745 ediv (df, d, dg); /* dg = d / 2^32 is the high word */
746 euifrac (dg, high, dh);
747 emul (df, dh, dg); /* fractional part is the low word */
748 euifrac (dg, low, dh);
751 /* complement and add 1 */
761 /* REAL_VALUE_LDEXP macro.
768 unsigned EMUSHORT e[NE], y[NE];
781 /* These routines are conditionally compiled because functions
782 * of the same names may be defined in fold-const.c. */
783 #ifdef REAL_ARITHMETIC
785 /* Check for infinity in a REAL_VALUE_TYPE. */
790 unsigned EMUSHORT e[NE];
801 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
807 unsigned EMUSHORT e[NE];
818 /* Check for a negative REAL_VALUE_TYPE number.
819 * this means strictly less than zero, not -0.
826 unsigned EMUSHORT e[NE];
829 if (ecmp (e, ezero) == -1)
834 /* Expansion of REAL_VALUE_TRUNCATE.
835 * The result is in floating point, rounded to nearest or even.
838 real_value_truncate (mode, arg)
839 enum machine_mode mode;
842 unsigned EMUSHORT e[NE], t[NE];
884 #endif /* REAL_ARITHMETIC defined */
886 /* Used for debugging--print the value of R in human-readable format
895 REAL_VALUE_TO_DECIMAL (r, "%.20g", dstr);
896 fprintf (stderr, "%s", dstr);
900 /* Target values are arrays of host longs. A long is guaranteed
901 to be at least 32 bits wide. */
903 /* 128-bit long double */
909 unsigned EMUSHORT e[NE];
913 endian (e, l, TFmode);
916 /* 80-bit long double */
922 unsigned EMUSHORT e[NE];
926 endian (e, l, XFmode);
934 unsigned EMUSHORT e[NE];
938 endian (e, l, DFmode);
945 unsigned EMUSHORT e[NE];
950 endian (e, &l, SFmode);
955 ereal_to_decimal (x, s)
959 unsigned EMUSHORT e[NE];
967 REAL_VALUE_TYPE x, y;
969 unsigned EMUSHORT ex[NE], ey[NE];
973 return (ecmp (ex, ey));
980 unsigned EMUSHORT ex[NE];
983 return (eisneg (ex));
986 /* End of REAL_ARITHMETIC interface */
990 * Extended precision IEEE binary floating point arithmetic routines
992 * Numbers are stored in C language as arrays of 16-bit unsigned
993 * short integers. The arguments of the routines are pointers to
997 * External e type data structure, simulates Intel 8087 chip
998 * temporary real format but possibly with a larger significand:
1000 * NE-1 significand words (least significant word first,
1001 * most significant bit is normally set)
1002 * exponent (value = EXONE for 1.0,
1003 * top bit is the sign)
1006 * Internal data structure of a number (a "word" is 16 bits):
1008 * ei[0] sign word (0 for positive, 0xffff for negative)
1009 * ei[1] biased exponent (value = EXONE for the number 1.0)
1010 * ei[2] high guard word (always zero after normalization)
1012 * to ei[NI-2] significand (NI-4 significand words,
1013 * most significant word first,
1014 * most significant bit is set)
1015 * ei[NI-1] low guard word (0x8000 bit is rounding place)
1019 * Routines for external format numbers
1021 * asctoe (string, e) ASCII string to extended double e type
1022 * asctoe64 (string, &d) ASCII string to long double
1023 * asctoe53 (string, &d) ASCII string to double
1024 * asctoe24 (string, &f) ASCII string to single
1025 * asctoeg (string, e, prec) ASCII string to specified precision
1026 * e24toe (&f, e) IEEE single precision to e type
1027 * e53toe (&d, e) IEEE double precision to e type
1028 * e64toe (&d, e) IEEE long double precision to e type
1029 * e113toe (&d, e) 128-bit long double precision to e type
1030 * eabs (e) absolute value
1031 * eadd (a, b, c) c = b + a
1033 * ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1034 * -1 if a < b, -2 if either a or b is a NaN.
1035 * ediv (a, b, c) c = b / a
1036 * efloor (a, b) truncate to integer, toward -infinity
1037 * efrexp (a, exp, s) extract exponent and significand
1038 * eifrac (e, &l, frac) e to long integer and e type fraction
1039 * euifrac (e, &l, frac) e to unsigned long integer and e type fraction
1040 * einfin (e) set e to infinity, leaving its sign alone
1041 * eldexp (a, n, b) multiply by 2**n
1043 * emul (a, b, c) c = b * a
1045 * eround (a, b) b = nearest integer value to a
1046 * esub (a, b, c) c = b - a
1047 * e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1048 * e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1049 * e64toasc (&d, str, n) 80-bit long double to ASCII string
1050 * e113toasc (&d, str, n) 128-bit long double to ASCII string
1051 * etoasc (e, str, n) e to ASCII string, n digits after decimal
1052 * etoe24 (e, &f) convert e type to IEEE single precision
1053 * etoe53 (e, &d) convert e type to IEEE double precision
1054 * etoe64 (e, &d) convert e type to IEEE long double precision
1055 * ltoe (&l, e) long (32 bit) integer to e type
1056 * ultoe (&l, e) unsigned long (32 bit) integer to e type
1057 * eisneg (e) 1 if sign bit of e != 0, else 0
1058 * eisinf (e) 1 if e has maximum exponent (non-IEEE)
1059 * or is infinite (IEEE)
1060 * eisnan (e) 1 if e is a NaN
1063 * Routines for internal format numbers
1065 * eaddm (ai, bi) add significands, bi = bi + ai
1066 * ecleaz (ei) ei = 0
1067 * ecleazs (ei) set ei = 0 but leave its sign alone
1068 * ecmpm (ai, bi) compare significands, return 1, 0, or -1
1069 * edivm (ai, bi) divide significands, bi = bi / ai
1070 * emdnorm (ai,l,s,exp) normalize and round off
1071 * emovi (a, ai) convert external a to internal ai
1072 * emovo (ai, a) convert internal ai to external a
1073 * emovz (ai, bi) bi = ai, low guard word of bi = 0
1074 * emulm (ai, bi) multiply significands, bi = bi * ai
1075 * enormlz (ei) left-justify the significand
1076 * eshdn1 (ai) shift significand and guards down 1 bit
1077 * eshdn8 (ai) shift down 8 bits
1078 * eshdn6 (ai) shift down 16 bits
1079 * eshift (ai, n) shift ai n bits up (or down if n < 0)
1080 * eshup1 (ai) shift significand and guards up 1 bit
1081 * eshup8 (ai) shift up 8 bits
1082 * eshup6 (ai) shift up 16 bits
1083 * esubm (ai, bi) subtract significands, bi = bi - ai
1084 * eiisinf (ai) 1 if infinite
1085 * eiisnan (ai) 1 if a NaN
1086 * einan (ai) set ai = NaN
1087 * eiinfin (ai) set ai = infinity
1090 * The result is always normalized and rounded to NI-4 word precision
1091 * after each arithmetic operation.
1093 * Exception flags are NOT fully supported.
1095 * Signaling NaN's are NOT supported; they are treated the same
1098 * Define INFINITY for support of infinity; otherwise a
1099 * saturation arithmetic is implemented.
1101 * Define NANS for support of Not-a-Number items; otherwise the
1102 * arithmetic will never produce a NaN output, and might be confused
1104 * If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1105 * either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1106 * may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1109 * Denormals are always supported here where appropriate (e.g., not
1110 * for conversion to DEC numbers).
1117 * Common include file for math routines
1123 * #include "mconf.h"
1129 * This file contains definitions for error codes that are
1130 * passed to the common error handling routine mtherr
1133 * The file also includes a conditional assembly definition
1134 * for the type of computer arithmetic (Intel IEEE, DEC, Motorola
1135 * IEEE, or UNKnown).
1137 * For Digital Equipment PDP-11 and VAX computers, certain
1138 * IBM systems, and others that use numbers with a 56-bit
1139 * significand, the symbol DEC should be defined. In this
1140 * mode, most floating point constants are given as arrays
1141 * of octal integers to eliminate decimal to binary conversion
1142 * errors that might be introduced by the compiler.
1144 * For computers, such as IBM PC, that follow the IEEE
1145 * Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1146 * Std 754-1985), the symbol IBMPC or MIEEE should be defined.
1147 * These numbers have 53-bit significands. In this mode, constants
1148 * are provided as arrays of hexadecimal 16 bit integers.
1150 * To accommodate other types of computer arithmetic, all
1151 * constants are also provided in a normal decimal radix
1152 * which one can hope are correctly converted to a suitable
1153 * format by the available C language compiler. To invoke
1154 * this mode, the symbol UNK is defined.
1156 * An important difference among these modes is a predefined
1157 * set of machine arithmetic constants for each. The numbers
1158 * MACHEP (the machine roundoff error), MAXNUM (largest number
1159 * represented), and several other parameters are preset by
1160 * the configuration symbol. Check the file const.c to
1161 * ensure that these values are correct for your computer.
1163 * For ANSI C compatibility, define ANSIC equal to 1. Currently
1164 * this affects only the atan2 function and others that use it.
1167 /* Constant definitions for math error conditions. */
1169 #define DOMAIN 1 /* argument domain error */
1170 #define SING 2 /* argument singularity */
1171 #define OVERFLOW 3 /* overflow range error */
1172 #define UNDERFLOW 4 /* underflow range error */
1173 #define TLOSS 5 /* total loss of precision */
1174 #define PLOSS 6 /* partial loss of precision */
1175 #define INVALID 7 /* NaN-producing operation */
1177 /* e type constants used by high precision check routines */
1179 #if LONG_DOUBLE_TYPE_SIZE == 128
1181 unsigned EMUSHORT ezero[NE] =
1182 {0x0000, 0x0000, 0x0000, 0x0000,
1183 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1184 extern unsigned EMUSHORT ezero[];
1187 unsigned EMUSHORT ehalf[NE] =
1188 {0x0000, 0x0000, 0x0000, 0x0000,
1189 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1190 extern unsigned EMUSHORT ehalf[];
1193 unsigned EMUSHORT eone[NE] =
1194 {0x0000, 0x0000, 0x0000, 0x0000,
1195 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1196 extern unsigned EMUSHORT eone[];
1199 unsigned EMUSHORT etwo[NE] =
1200 {0x0000, 0x0000, 0x0000, 0x0000,
1201 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1202 extern unsigned EMUSHORT etwo[];
1205 unsigned EMUSHORT e32[NE] =
1206 {0x0000, 0x0000, 0x0000, 0x0000,
1207 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1208 extern unsigned EMUSHORT e32[];
1210 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1211 unsigned EMUSHORT elog2[NE] =
1212 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1213 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1214 extern unsigned EMUSHORT elog2[];
1216 /* 1.41421356237309504880168872420969807856967187537695E0 */
1217 unsigned EMUSHORT esqrt2[NE] =
1218 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1219 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1220 extern unsigned EMUSHORT esqrt2[];
1222 /* 3.14159265358979323846264338327950288419716939937511E0 */
1223 unsigned EMUSHORT epi[NE] =
1224 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1225 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1226 extern unsigned EMUSHORT epi[];
1229 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1230 unsigned EMUSHORT ezero[NE] =
1231 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1232 unsigned EMUSHORT ehalf[NE] =
1233 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1234 unsigned EMUSHORT eone[NE] =
1235 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1236 unsigned EMUSHORT etwo[NE] =
1237 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1238 unsigned EMUSHORT e32[NE] =
1239 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1240 unsigned EMUSHORT elog2[NE] =
1241 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1242 unsigned EMUSHORT esqrt2[NE] =
1243 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1244 unsigned EMUSHORT epi[NE] =
1245 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1250 /* Control register for rounding precision.
1251 * This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits.
1256 void eaddm (), esubm (), emdnorm (), asctoeg ();
1257 static void toe24 (), toe53 (), toe64 (), toe113 ();
1258 void eremain (), einit (), eiremain ();
1259 int ecmpm (), edivm (), emulm ();
1260 void emovi (), emovo (), emovz (), ecleaz (), ecleazs (), eadd1 ();
1262 void etodec (), todec (), dectoe ();
1265 void etoibm (), toibm (), ibmtoe ();
1275 ; Clear out entire external format number.
1277 ; unsigned EMUSHORT x[];
1283 register unsigned EMUSHORT *x;
1287 for (i = 0; i < NE; i++)
1293 /* Move external format number from a to b.
1300 register unsigned EMUSHORT *a, *b;
1304 for (i = 0; i < NE; i++)
1310 ; Absolute value of external format number
1318 unsigned EMUSHORT x[]; /* x is the memory address of a short */
1321 x[NE - 1] &= 0x7fff; /* sign is top bit of last word of external format */
1328 ; Negate external format number
1330 ; unsigned EMUSHORT x[NE];
1336 unsigned EMUSHORT x[];
1343 x[NE - 1] ^= 0x8000; /* Toggle the sign bit */
1348 /* Return 1 if external format number is negative,
1349 * else return zero, including when it is a NaN.
1353 unsigned EMUSHORT x[];
1360 if (x[NE - 1] & 0x8000)
1367 /* Return 1 if external format number is infinity.
1372 unsigned EMUSHORT x[];
1379 if ((x[NE - 1] & 0x7fff) == 0x7fff)
1386 /* Check if e-type number is not a number.
1387 The bit pattern is one that we defined, so we know for sure how to
1392 unsigned EMUSHORT x[];
1397 /* NaN has maximum exponent */
1398 if ((x[NE - 1] & 0x7fff) != 0x7fff)
1400 /* ... and non-zero significand field. */
1401 for (i = 0; i < NE - 1; i++)
1410 /* Fill external format number with infinity pattern (IEEE)
1411 or largest possible number (non-IEEE). */
1415 register unsigned EMUSHORT *x;
1420 for (i = 0; i < NE - 1; i++)
1424 for (i = 0; i < NE - 1; i++)
1453 /* Output an e-type NaN.
1454 This generates Intel's quiet NaN pattern for extended real.
1455 The exponent is 7fff, the leading mantissa word is c000. */
1459 register unsigned EMUSHORT *x;
1463 for (i = 0; i < NE - 2; i++)
1470 /* Move in external format number,
1471 * converting it to internal format.
1475 unsigned EMUSHORT *a, *b;
1477 register unsigned EMUSHORT *p, *q;
1481 p = a + (NE - 1); /* point to last word of external number */
1482 /* get the sign bit */
1487 /* get the exponent */
1489 *q++ &= 0x7fff; /* delete the sign bit */
1491 if ((*(q - 1) & 0x7fff) == 0x7fff)
1497 for (i = 3; i < NI; i++)
1502 for (i = 2; i < NI; i++)
1507 /* clear high guard word */
1509 /* move in the significand */
1510 for (i = 0; i < NE - 1; i++)
1512 /* clear low guard word */
1517 /* Move internal format number out,
1518 * converting it to external format.
1522 unsigned EMUSHORT *a, *b;
1524 register unsigned EMUSHORT *p, *q;
1525 unsigned EMUSHORT i;
1528 q = b + (NE - 1); /* point to output exponent */
1529 /* combine sign and exponent */
1532 *q-- = *p++ | 0x8000;
1536 if (*(p - 1) == 0x7fff)
1549 /* skip over guard word */
1551 /* move the significand */
1552 for (i = 0; i < NE - 1; i++)
1559 /* Clear out internal format number.
1564 register unsigned EMUSHORT *xi;
1568 for (i = 0; i < NI; i++)
1573 /* same, but don't touch the sign. */
1577 register unsigned EMUSHORT *xi;
1582 for (i = 0; i < NI - 1; i++)
1588 /* Move internal format number from a to b.
1592 register unsigned EMUSHORT *a, *b;
1596 for (i = 0; i < NI - 1; i++)
1598 /* clear low guard word */
1602 /* Generate internal format NaN.
1603 The explicit pattern for this is maximum exponent and
1604 top two significand bits set. */
1608 unsigned EMUSHORT x[];
1616 /* Return nonzero if internal format number is a NaN. */
1620 unsigned EMUSHORT x[];
1624 if ((x[E] & 0x7fff) == 0x7fff)
1626 for (i = M + 1; i < NI; i++)
1635 /* Fill internal format number with infinity pattern.
1636 This has maximum exponent and significand all zeros. */
1640 unsigned EMUSHORT x[];
1647 /* Return nonzero if internal format number is infinite. */
1651 unsigned EMUSHORT x[];
1658 if ((x[E] & 0x7fff) == 0x7fff)
1665 ; Compare significands of numbers in internal format.
1666 ; Guard words are included in the comparison.
1668 ; unsigned EMUSHORT a[NI], b[NI];
1671 ; for the significands:
1672 ; returns +1 if a > b
1678 register unsigned EMUSHORT *a, *b;
1682 a += M; /* skip up to significand area */
1684 for (i = M; i < NI; i++)
1692 if (*(--a) > *(--b))
1700 ; Shift significand down by 1 bit
1705 register unsigned EMUSHORT *x;
1707 register unsigned EMUSHORT bits;
1710 x += M; /* point to significand area */
1713 for (i = M; i < NI; i++)
1728 ; Shift significand up by 1 bit
1733 register unsigned EMUSHORT *x;
1735 register unsigned EMUSHORT bits;
1741 for (i = M; i < NI; i++)
1756 ; Shift significand down by 8 bits
1761 register unsigned EMUSHORT *x;
1763 register unsigned EMUSHORT newbyt, oldbyt;
1768 for (i = M; i < NI; i++)
1779 ; Shift significand up by 8 bits
1784 register unsigned EMUSHORT *x;
1787 register unsigned EMUSHORT newbyt, oldbyt;
1792 for (i = M; i < NI; i++)
1803 ; Shift significand up by 16 bits
1808 register unsigned EMUSHORT *x;
1811 register unsigned EMUSHORT *p;
1816 for (i = M; i < NI - 1; i++)
1823 ; Shift significand down by 16 bits
1828 register unsigned EMUSHORT *x;
1831 register unsigned EMUSHORT *p;
1836 for (i = M; i < NI - 1; i++)
1849 unsigned EMUSHORT *x, *y;
1851 register unsigned EMULONG a;
1858 for (i = M; i < NI; i++)
1860 a = (unsigned EMULONG) (*x) + (unsigned EMULONG) (*y) + carry;
1865 *y = (unsigned EMUSHORT) a;
1872 ; Subtract significands
1878 unsigned EMUSHORT *x, *y;
1887 for (i = M; i < NI; i++)
1889 a = (unsigned EMULONG) (*y) - (unsigned EMULONG) (*x) - carry;
1894 *y = (unsigned EMUSHORT) a;
1901 static unsigned EMUSHORT equot[NI];
1905 /* Radix 2 shift-and-add versions of multiply and divide */
1908 /* Divide significands */
1912 unsigned EMUSHORT den[], num[];
1915 register unsigned EMUSHORT *p, *q;
1916 unsigned EMUSHORT j;
1922 for (i = M; i < NI; i++)
1927 /* Use faster compare and subtraction if denominator
1928 * has only 15 bits of significance.
1933 for (i = M + 3; i < NI; i++)
1938 if ((den[M + 1] & 1) != 0)
1946 for (i = 0; i < NBITS + 2; i++)
1964 /* The number of quotient bits to calculate is
1965 * NBITS + 1 scaling guard bit + 1 roundoff bit.
1970 for (i = 0; i < NBITS + 2; i++)
1972 if (ecmpm (den, num) <= 0)
1975 j = 1; /* quotient bit = 1 */
1989 /* test for nonzero remainder after roundoff bit */
1992 for (i = M; i < NI; i++)
2000 for (i = 0; i < NI; i++)
2006 /* Multiply significands */
2009 unsigned EMUSHORT a[], b[];
2011 unsigned EMUSHORT *p, *q;
2016 for (i = M; i < NI; i++)
2021 while (*p == 0) /* significand is not supposed to be all zero */
2026 if ((*p & 0xff) == 0)
2034 for (i = 0; i < k; i++)
2038 /* remember if there were any nonzero bits shifted out */
2045 for (i = 0; i < NI; i++)
2048 /* return flag for lost nonzero bits */
2054 /* Radix 65536 versions of multiply and divide */
2057 /* Multiply significand of e-type number b
2058 by 16-bit quantity a, e-type result to c. */
2063 unsigned short b[], c[];
2065 register unsigned short *pp;
2066 register unsigned long carry;
2068 unsigned short p[NI];
2069 unsigned long aa, m;
2078 for (i=M+1; i<NI; i++)
2088 m = (unsigned long) aa * *ps--;
2089 carry = (m & 0xffff) + *pp;
2090 *pp-- = (unsigned short)carry;
2091 carry = (carry >> 16) + (m >> 16) + *pp;
2092 *pp = (unsigned short)carry;
2093 *(pp-1) = carry >> 16;
2096 for (i=M; i<NI; i++)
2101 /* Divide significands. Neither the numerator nor the denominator
2102 is permitted to have its high guard word nonzero. */
2106 unsigned short den[], num[];
2109 register unsigned short *p;
2111 unsigned short j, tdenm, tquot;
2112 unsigned short tprod[NI+1];
2118 for (i=M; i<NI; i++)
2124 for (i=M; i<NI; i++)
2126 /* Find trial quotient digit (the radix is 65536). */
2127 tnum = (((unsigned long) num[M]) << 16) + num[M+1];
2129 /* Do not execute the divide instruction if it will overflow. */
2130 if ((tdenm * 0xffffL) < tnum)
2133 tquot = tnum / tdenm;
2134 /* Multiply denominator by trial quotient digit. */
2135 m16m (tquot, den, tprod);
2136 /* The quotient digit may have been overestimated. */
2137 if (ecmpm (tprod, num) > 0)
2141 if (ecmpm (tprod, num) > 0)
2151 /* test for nonzero remainder after roundoff bit */
2154 for (i=M; i<NI; i++)
2161 for (i=0; i<NI; i++)
2169 /* Multiply significands */
2172 unsigned short a[], b[];
2174 unsigned short *p, *q;
2175 unsigned short pprod[NI];
2181 for (i=M; i<NI; i++)
2187 for (i=M+1; i<NI; i++)
2195 m16m (*p--, b, pprod);
2196 eaddm(pprod, equot);
2202 for (i=0; i<NI; i++)
2205 /* return flag for lost nonzero bits */
2212 * Normalize and round off.
2214 * The internal format number to be rounded is "s".
2215 * Input "lost" indicates whether or not the number is exact.
2216 * This is the so-called sticky bit.
2218 * Input "subflg" indicates whether the number was obtained
2219 * by a subtraction operation. In that case if lost is nonzero
2220 * then the number is slightly smaller than indicated.
2222 * Input "exp" is the biased exponent, which may be negative.
2223 * the exponent field of "s" is ignored but is replaced by
2224 * "exp" as adjusted by normalization and rounding.
2226 * Input "rcntrl" is the rounding control.
2229 /* For future reference: In order for emdnorm to round off denormal
2230 significands at the right point, the input exponent must be
2231 adjusted to be the actual value it would have after conversion to
2232 the final floating point type. This adjustment has been
2233 implemented for all type conversions (etoe53, etc.) and decimal
2234 conversions, but not for the arithmetic functions (eadd, etc.).
2235 Data types having standard 15-bit exponents are not affected by
2236 this, but SFmode and DFmode are affected. For example, ediv with
2237 rndprc = 24 will not round correctly to 24-bit precision if the
2238 result is denormal. */
2240 static int rlast = -1;
2242 static unsigned EMUSHORT rmsk = 0;
2243 static unsigned EMUSHORT rmbit = 0;
2244 static unsigned EMUSHORT rebit = 0;
2246 static unsigned EMUSHORT rbit[NI];
2249 emdnorm (s, lost, subflg, exp, rcntrl)
2250 unsigned EMUSHORT s[];
2257 unsigned EMUSHORT r;
2262 /* a blank significand could mean either zero or infinity. */
2275 if ((j > NBITS) && (exp < 32767))
2283 if (exp > (EMULONG) (-NBITS - 1))
2296 /* Round off, unless told not to by rcntrl. */
2299 /* Set up rounding parameters if the control register changed. */
2300 if (rndprc != rlast)
2307 rw = NI - 1; /* low guard word */
2327 /* For DEC or IBM arithmetic */
2354 /* Shift down 1 temporarily if the data structure has an implied
2355 most significant bit and the number is denormal. */
2356 if ((exp <= 0) && (rndprc != 64) && (rndprc != NBITS))
2358 lost |= s[NI - 1] & 1;
2361 /* Clear out all bits below the rounding bit,
2362 remembering in r if any were nonzero. */
2376 if ((r & rmbit) != 0)
2381 { /* round to even */
2382 if ((s[re] & rebit) == 0)
2394 if ((exp <= 0) && (rndprc != 64) && (rndprc != NBITS))
2399 { /* overflow on roundoff */
2412 for (i = 2; i < NI - 1; i++)
2415 warning ("floating point overflow");
2419 for (i = M + 1; i < NI - 1; i++)
2422 if ((rndprc < 64) || (rndprc == 113))
2437 s[1] = (unsigned EMUSHORT) exp;
2443 ; Subtract external format numbers.
2445 ; unsigned EMUSHORT a[NE], b[NE], c[NE];
2446 ; esub (a, b, c); c = b - a
2449 static int subflg = 0;
2453 unsigned EMUSHORT *a, *b, *c;
2467 /* Infinity minus infinity is a NaN.
2468 Test for subtracting infinities of the same sign. */
2469 if (eisinf (a) && eisinf (b)
2470 && ((eisneg (a) ^ eisneg (b)) == 0))
2472 mtherr ("esub", INVALID);
2485 ; unsigned EMUSHORT a[NE], b[NE], c[NE];
2486 ; eadd (a, b, c); c = b + a
2490 unsigned EMUSHORT *a, *b, *c;
2494 /* NaN plus anything is a NaN. */
2505 /* Infinity minus infinity is a NaN.
2506 Test for adding infinities of opposite signs. */
2507 if (eisinf (a) && eisinf (b)
2508 && ((eisneg (a) ^ eisneg (b)) != 0))
2510 mtherr ("esub", INVALID);
2521 unsigned EMUSHORT *a, *b, *c;
2523 unsigned EMUSHORT ai[NI], bi[NI], ci[NI];
2525 EMULONG lt, lta, ltb;
2546 /* compare exponents */
2551 { /* put the larger number in bi */
2561 if (lt < (EMULONG) (-NBITS - 1))
2562 goto done; /* answer same as larger addend */
2564 lost = eshift (ai, k); /* shift the smaller number down */
2568 /* exponents were the same, so must compare significands */
2571 { /* the numbers are identical in magnitude */
2572 /* if different signs, result is zero */
2578 /* if same sign, result is double */
2579 /* double denomalized tiny number */
2580 if ((bi[E] == 0) && ((bi[3] & 0x8000) == 0))
2585 /* add 1 to exponent unless both are zero! */
2586 for (j = 1; j < NI - 1; j++)
2590 /* This could overflow, but let emovo take care of that. */
2595 bi[E] = (unsigned EMUSHORT) ltb;
2599 { /* put the larger number in bi */
2615 emdnorm (bi, lost, subflg, ltb, 64);
2626 ; unsigned EMUSHORT a[NE], b[NE], c[NE];
2627 ; ediv (a, b, c); c = b / a
2631 unsigned EMUSHORT *a, *b, *c;
2633 unsigned EMUSHORT ai[NI], bi[NI];
2635 EMULONG lt, lta, ltb;
2638 /* Return any NaN input. */
2649 /* Zero over zero, or infinity over infinity, is a NaN. */
2650 if (((ecmp (a, ezero) == 0) && (ecmp (b, ezero) == 0))
2651 || (eisinf (a) && eisinf (b)))
2653 mtherr ("ediv", INVALID);
2658 /* Infinity over anything else is infinity. */
2662 if (eisneg (a) ^ eisneg (b))
2663 *(c + (NE - 1)) = 0x8000;
2665 *(c + (NE - 1)) = 0;
2669 /* Anything else over infinity is zero. */
2681 { /* See if numerator is zero. */
2682 for (i = 1; i < NI - 1; i++)
2686 ltb -= enormlz (bi);
2696 { /* possible divide by zero */
2697 for (i = 1; i < NI - 1; i++)
2701 lta -= enormlz (ai);
2706 *(c + (NE - 1)) = 0;
2708 *(c + (NE - 1)) = 0x8000;
2709 /* Divide by zero is not an invalid operation.
2710 It is a divide-by-zero operation! */
2712 mtherr ("ediv", SING);
2718 /* calculate exponent */
2719 lt = ltb - lta + EXONE;
2720 emdnorm (bi, i, 0, lt, 64);
2734 ; unsigned EMUSHORT a[NE], b[NE], c[NE];
2735 ; emul (a, b, c); c = b * a
2739 unsigned EMUSHORT *a, *b, *c;
2741 unsigned EMUSHORT ai[NI], bi[NI];
2743 EMULONG lt, lta, ltb;
2746 /* NaN times anything is the same NaN. */
2757 /* Zero times infinity is a NaN. */
2758 if ((eisinf (a) && (ecmp (b, ezero) == 0))
2759 || (eisinf (b) && (ecmp (a, ezero) == 0)))
2761 mtherr ("emul", INVALID);
2766 /* Infinity times anything else is infinity. */
2768 if (eisinf (a) || eisinf (b))
2770 if (eisneg (a) ^ eisneg (b))
2771 *(c + (NE - 1)) = 0x8000;
2773 *(c + (NE - 1)) = 0;
2784 for (i = 1; i < NI - 1; i++)
2788 lta -= enormlz (ai);
2799 for (i = 1; i < NI - 1; i++)
2803 ltb -= enormlz (bi);
2812 /* Multiply significands */
2814 /* calculate exponent */
2815 lt = lta + ltb - (EXONE - 1);
2816 emdnorm (bi, j, 0, lt, 64);
2817 /* calculate sign of product */
2829 ; Convert IEEE double precision to e type
2831 ; unsigned EMUSHORT x[N+2];
2836 unsigned EMUSHORT *pe, *y;
2840 dectoe (pe, y); /* see etodec.c */
2845 ibmtoe (pe, y, DFmode);
2848 register unsigned EMUSHORT r;
2849 register unsigned EMUSHORT *e, *p;
2850 unsigned EMUSHORT yy[NI];
2854 denorm = 0; /* flag if denormalized number */
2863 yy[M] = (r & 0x0f) | 0x10;
2864 r &= ~0x800f; /* strip sign and 4 significand bits */
2870 if (((pe[3] & 0xf) != 0) || (pe[2] != 0)
2871 || (pe[1] != 0) || (pe[0] != 0))
2877 if (((pe[0] & 0xf) != 0) || (pe[1] != 0)
2878 || (pe[2] != 0) || (pe[3] != 0))
2891 #endif /* INFINITY */
2893 /* If zero exponent, then the significand is denormalized.
2894 * So, take back the understood high significand bit. */
2916 { /* if zero exponent, then normalize the significand */
2917 if ((k = enormlz (yy)) > NBITS)
2920 yy[E] -= (unsigned EMUSHORT) (k - 1);
2923 #endif /* not IBM */
2924 #endif /* not DEC */
2929 unsigned EMUSHORT *pe, *y;
2931 unsigned EMUSHORT yy[NI];
2932 unsigned EMUSHORT *e, *p, *q;
2937 for (i = 0; i < NE - 5; i++)
2940 for (i = 0; i < 5; i++)
2943 /* This precision is not ordinarily supported on DEC or IBM. */
2945 for (i = 0; i < 5; i++)
2949 p = &yy[0] + (NE - 1);
2952 for (i = 0; i < 5; i++)
2956 p = &yy[0] + (NE - 1);
2959 for (i = 0; i < 4; i++)
2969 for (i = 0; i < 4; i++)
2978 for (i = 1; i <= 4; i++)
2994 #endif /* INFINITY */
2995 for (i = 0; i < NE; i++)
3002 unsigned EMUSHORT *pe, *y;
3004 register unsigned EMUSHORT r;
3005 unsigned EMUSHORT *e, *p;
3006 unsigned EMUSHORT yy[NI];
3025 for (i = 0; i < 7; i++)
3034 for (i = 1; i < 8; i++)
3050 #endif /* INFINITY */
3054 for (i = 0; i < 7; i++)
3059 for (i = 0; i < 7; i++)
3062 /* If denormal, remove the implied bit; else shift down 1. */
3077 ; Convert IEEE single precision to e type
3079 ; unsigned EMUSHORT x[N+2];
3084 unsigned EMUSHORT *pe, *y;
3088 ibmtoe (pe, y, SFmode);
3091 register unsigned EMUSHORT r;
3092 register unsigned EMUSHORT *e, *p;
3093 unsigned EMUSHORT yy[NI];
3097 denorm = 0; /* flag if denormalized number */
3109 yy[M] = (r & 0x7f) | 0200;
3110 r &= ~0x807f; /* strip sign and 7 significand bits */
3116 if (((pe[0] & 0x7f) != 0) || (pe[1] != 0))
3122 if (((pe[1] & 0x7f) != 0) || (pe[0] != 0))
3135 #endif /* INFINITY */
3137 /* If zero exponent, then the significand is denormalized.
3138 * So, take back the understood high significand bit. */
3159 { /* if zero exponent, then normalize the significand */
3160 if ((k = enormlz (yy)) > NBITS)
3163 yy[E] -= (unsigned EMUSHORT) (k - 1);
3166 #endif /* not IBM */
3172 unsigned EMUSHORT *x, *e;
3174 unsigned EMUSHORT xi[NI];
3181 make_nan (e, TFmode);
3186 exp = (EMULONG) xi[E];
3191 /* round off to nearest or even */
3194 emdnorm (xi, 0, 0, exp, 64);
3200 /* move out internal format to ieee long double */
3203 unsigned EMUSHORT *a, *b;
3205 register unsigned EMUSHORT *p, *q;
3206 unsigned EMUSHORT i;
3211 make_nan (b, TFmode);
3219 q = b + 7; /* point to output exponent */
3222 /* If not denormal, delete the implied bit. */
3227 /* combine sign and exponent */
3231 *q++ = *p++ | 0x8000;
3236 *q-- = *p++ | 0x8000;
3240 /* skip over guard word */
3242 /* move the significand */
3244 for (i = 0; i < 7; i++)
3247 for (i = 0; i < 7; i++)
3254 unsigned EMUSHORT *x, *e;
3256 unsigned EMUSHORT xi[NI];
3263 make_nan (e, XFmode);
3268 /* adjust exponent for offset */
3269 exp = (EMULONG) xi[E];
3274 /* round off to nearest or even */
3277 emdnorm (xi, 0, 0, exp, 64);
3283 /* move out internal format to ieee long double */
3286 unsigned EMUSHORT *a, *b;
3288 register unsigned EMUSHORT *p, *q;
3289 unsigned EMUSHORT i;
3294 make_nan (b, XFmode);
3299 #if defined(MIEEE) || defined(IBM)
3302 q = b + 4; /* point to output exponent */
3303 #if LONG_DOUBLE_TYPE_SIZE == 96
3304 /* Clear the last two bytes of 12-byte Intel format */
3309 /* combine sign and exponent */
3311 #if defined(MIEEE) || defined(IBM)
3313 *q++ = *p++ | 0x8000;
3319 *q-- = *p++ | 0x8000;
3323 /* skip over guard word */
3325 /* move the significand */
3326 #if defined(MIEEE) || defined(IBM)
3327 for (i = 0; i < 4; i++)
3330 for (i = 0; i < 4; i++)
3337 ; e type to IEEE double precision
3339 ; unsigned EMUSHORT x[NE];
3347 unsigned EMUSHORT *x, *e;
3349 etodec (x, e); /* see etodec.c */
3354 unsigned EMUSHORT *x, *y;
3364 unsigned EMUSHORT *x, *e;
3366 etoibm (x, e, DFmode);
3371 unsigned EMUSHORT *x, *y;
3373 toibm (x, y, DFmode);
3376 #else /* it's neither DEC nor IBM */
3380 unsigned EMUSHORT *x, *e;
3382 unsigned EMUSHORT xi[NI];
3389 make_nan (e, DFmode);
3394 /* adjust exponent for offsets */
3395 exp = (EMULONG) xi[E] - (EXONE - 0x3ff);
3400 /* round off to nearest or even */
3403 emdnorm (xi, 0, 0, exp, 64);
3412 unsigned EMUSHORT *x, *y;
3414 unsigned EMUSHORT i;
3415 unsigned EMUSHORT *p;
3420 make_nan (y, DFmode);
3428 *y = 0; /* output high order */
3430 *y = 0x8000; /* output sign bit */
3433 if (i >= (unsigned int) 2047)
3434 { /* Saturate at largest number less than infinity. */
3449 *y |= (unsigned EMUSHORT) 0x7fef;
3473 i |= *p++ & (unsigned EMUSHORT) 0x0f; /* *p = xi[M] */
3474 *y |= (unsigned EMUSHORT) i; /* high order output already has sign bit set */
3488 #endif /* not IBM */
3489 #endif /* not DEC */
3494 ; e type to IEEE single precision
3496 ; unsigned EMUSHORT x[N+2];
3503 unsigned EMUSHORT *x, *e;
3505 etoibm (x, e, SFmode);
3510 unsigned EMUSHORT *x, *y;
3512 toibm (x, y, SFmode);
3519 unsigned EMUSHORT *x, *e;
3522 unsigned EMUSHORT xi[NI];
3528 make_nan (e, SFmode);
3533 /* adjust exponent for offsets */
3534 exp = (EMULONG) xi[E] - (EXONE - 0177);
3539 /* round off to nearest or even */
3542 emdnorm (xi, 0, 0, exp, 64);
3550 unsigned EMUSHORT *x, *y;
3552 unsigned EMUSHORT i;
3553 unsigned EMUSHORT *p;
3558 make_nan (y, SFmode);
3569 *y = 0; /* output high order */
3571 *y = 0x8000; /* output sign bit */
3574 /* Handle overflow cases. */
3578 *y |= (unsigned EMUSHORT) 0x7f80;
3589 #else /* no INFINITY */
3590 *y |= (unsigned EMUSHORT) 0x7f7f;
3604 #endif /* no INFINITY */
3616 i |= *p++ & (unsigned EMUSHORT) 0x7f; /* *p = xi[M] */
3617 *y |= i; /* high order output already has sign bit set */
3629 #endif /* not IBM */
3631 /* Compare two e type numbers.
3633 * unsigned EMUSHORT a[NE], b[NE];
3636 * returns +1 if a > b
3639 * -2 if either a or b is a NaN.
3643 unsigned EMUSHORT *a, *b;
3645 unsigned EMUSHORT ai[NI], bi[NI];
3646 register unsigned EMUSHORT *p, *q;
3651 if (eisnan (a) || eisnan (b))
3660 { /* the signs are different */
3662 for (i = 1; i < NI - 1; i++)
3676 /* both are the same sign */
3691 return (0); /* equality */
3697 if (*(--p) > *(--q))
3698 return (msign); /* p is bigger */
3700 return (-msign); /* p is littler */
3706 /* Find nearest integer to x = floor (x + 0.5)
3708 * unsigned EMUSHORT x[NE], y[NE]
3713 unsigned EMUSHORT *x, *y;
3723 ; convert long integer to e type
3726 ; unsigned EMUSHORT x[NE];
3728 ; note &l is the memory address of l
3732 long *lp; /* lp is the memory address of a long integer */
3733 unsigned EMUSHORT *y; /* y is the address of a short */
3735 unsigned EMUSHORT yi[NI];
3742 /* make it positive */
3743 ll = (unsigned long) (-(*lp));
3744 yi[0] = 0xffff; /* put correct sign in the e type number */
3748 ll = (unsigned long) (*lp);
3750 /* move the long integer to yi significand area */
3751 #if HOST_BITS_PER_LONG == 64
3752 yi[M] = (unsigned EMUSHORT) (ll >> 48);
3753 yi[M + 1] = (unsigned EMUSHORT) (ll >> 32);
3754 yi[M + 2] = (unsigned EMUSHORT) (ll >> 16);
3755 yi[M + 3] = (unsigned EMUSHORT) ll;
3756 yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
3758 yi[M] = (unsigned EMUSHORT) (ll >> 16);
3759 yi[M + 1] = (unsigned EMUSHORT) ll;
3760 yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */
3763 if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
3764 ecleaz (yi); /* it was zero */
3766 yi[E] -= (unsigned EMUSHORT) k;/* subtract shift count from exponent */
3767 emovo (yi, y); /* output the answer */
3771 ; convert unsigned long integer to e type
3774 ; unsigned EMUSHORT x[NE];
3776 ; note &l is the memory address of l
3780 unsigned long *lp; /* lp is the memory address of a long integer */
3781 unsigned EMUSHORT *y; /* y is the address of a short */
3783 unsigned EMUSHORT yi[NI];
3790 /* move the long integer to ayi significand area */
3791 #if HOST_BITS_PER_LONG == 64
3792 yi[M] = (unsigned EMUSHORT) (ll >> 48);
3793 yi[M + 1] = (unsigned EMUSHORT) (ll >> 32);
3794 yi[M + 2] = (unsigned EMUSHORT) (ll >> 16);
3795 yi[M + 3] = (unsigned EMUSHORT) ll;
3796 yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
3798 yi[M] = (unsigned EMUSHORT) (ll >> 16);
3799 yi[M + 1] = (unsigned EMUSHORT) ll;
3800 yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */
3803 if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
3804 ecleaz (yi); /* it was zero */
3806 yi[E] -= (unsigned EMUSHORT) k; /* subtract shift count from exponent */
3807 emovo (yi, y); /* output the answer */
3812 ; Find long integer and fractional parts
3815 ; unsigned EMUSHORT x[NE], frac[NE];
3816 ; xifrac (x, &i, frac);
3818 The integer output has the sign of the input. The fraction is
3819 the positive fractional part of abs (x).
3823 unsigned EMUSHORT *x;
3825 unsigned EMUSHORT *frac;
3827 unsigned EMUSHORT xi[NI];
3832 k = (int) xi[E] - (EXONE - 1);
3835 /* if exponent <= 0, integer = 0 and real output is fraction */
3840 if (k > (HOST_BITS_PER_LONG - 1))
3842 /* long integer overflow: output large integer
3843 and correct fraction */
3845 *i = ((unsigned long) 1) << (HOST_BITS_PER_LONG - 1);
3847 *i = (((unsigned long) 1) << (HOST_BITS_PER_LONG - 1)) - 1;
3850 warning ("overflow on truncation to integer");
3854 /* Shift more than 16 bits: first shift up k-16 mod 16,
3855 then shift up by 16's. */
3856 j = k - ((k >> 4) << 4);
3863 ll = (ll << 16) | xi[M];
3865 while ((k -= 16) > 0);
3872 /* shift not more than 16 bits */
3874 *i = (long) xi[M] & 0xffff;
3881 if ((k = enormlz (xi)) > NBITS)
3884 xi[E] -= (unsigned EMUSHORT) k;
3890 /* Find unsigned long integer and fractional parts.
3891 A negative e type input yields integer output = 0
3892 but correct fraction. */
3895 euifrac (x, i, frac)
3896 unsigned EMUSHORT *x;
3898 unsigned EMUSHORT *frac;
3901 unsigned EMUSHORT xi[NI];
3905 k = (int) xi[E] - (EXONE - 1);
3908 /* if exponent <= 0, integer = 0 and argument is fraction */
3913 if (k > HOST_BITS_PER_LONG)
3915 /* Long integer overflow: output large integer
3916 and correct fraction.
3917 Note, the BSD microvax compiler says that ~(0UL)
3918 is a syntax error. */
3922 warning ("overflow on truncation to unsigned integer");
3926 /* Shift more than 16 bits: first shift up k-16 mod 16,
3927 then shift up by 16's. */
3928 j = k - ((k >> 4) << 4);
3935 ll = (ll << 16) | xi[M];
3937 while ((k -= 16) > 0);
3942 /* shift not more than 16 bits */
3944 *i = (long) xi[M] & 0xffff;
3947 if (xi[0]) /* A negative value yields unsigned integer 0. */
3953 if ((k = enormlz (xi)) > NBITS)
3956 xi[E] -= (unsigned EMUSHORT) k;
3966 ; Shifts significand area up or down by the number of bits
3967 ; given by the variable sc.
3971 unsigned EMUSHORT *x;
3974 unsigned EMUSHORT lost;
3975 unsigned EMUSHORT *p;
3988 lost |= *p; /* remember lost bits */
4029 return ((int) lost);
4037 ; Shift normalizes the significand area pointed to by argument
4038 ; shift count (up = positive) is returned.
4042 unsigned EMUSHORT x[];
4044 register unsigned EMUSHORT *p;
4053 return (0); /* already normalized */
4058 /* With guard word, there are NBITS+16 bits available.
4059 * return true if all are zero.
4064 /* see if high byte is zero */
4065 while ((*p & 0xff00) == 0)
4070 /* now shift 1 bit at a time */
4071 while ((*p & 0x8000) == 0)
4077 mtherr ("enormlz", UNDERFLOW);
4083 /* Normalize by shifting down out of the high guard word
4084 of the significand */
4099 mtherr ("enormlz", OVERFLOW);
4109 /* Convert e type number to decimal format ASCII string.
4110 * The constants are for 64 bit precision.
4116 #if LONG_DOUBLE_TYPE_SIZE == 128
4117 static unsigned EMUSHORT etens[NTEN + 1][NE] =
4119 {0x6576, 0x4a92, 0x804a, 0x153f,
4120 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4121 {0x6a32, 0xce52, 0x329a, 0x28ce,
4122 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4123 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4124 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4125 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4126 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4127 {0x851e, 0xeab7, 0x98fe, 0x901b,
4128 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4129 {0x0235, 0x0137, 0x36b1, 0x336c,
4130 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4131 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4132 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4133 {0x0000, 0x0000, 0x0000, 0x0000,
4134 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4135 {0x0000, 0x0000, 0x0000, 0x0000,
4136 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4137 {0x0000, 0x0000, 0x0000, 0x0000,
4138 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4139 {0x0000, 0x0000, 0x0000, 0x0000,
4140 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4141 {0x0000, 0x0000, 0x0000, 0x0000,
4142 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4143 {0x0000, 0x0000, 0x0000, 0x0000,
4144 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4147 static unsigned EMUSHORT emtens[NTEN + 1][NE] =
4149 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4150 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4151 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4152 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4153 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4154 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4155 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4156 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4157 {0xa23e, 0x5308, 0xfefb, 0x1155,
4158 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4159 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4160 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4161 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4162 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4163 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4164 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4165 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4166 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4167 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4168 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4169 {0xc155, 0xa4a8, 0x404e, 0x6113,
4170 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4171 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4172 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4173 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4174 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4177 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4178 static unsigned EMUSHORT etens[NTEN + 1][NE] =
4180 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4181 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4182 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4183 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4184 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4185 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4186 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4187 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4188 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4189 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4190 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4191 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4192 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4195 static unsigned EMUSHORT emtens[NTEN + 1][NE] =
4197 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4198 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4199 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4200 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4201 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4202 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4203 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4204 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4205 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4206 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4207 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4208 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4209 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4214 e24toasc (x, string, ndigs)
4215 unsigned EMUSHORT x[];
4219 unsigned EMUSHORT w[NI];
4222 etoasc (w, string, ndigs);
4227 e53toasc (x, string, ndigs)
4228 unsigned EMUSHORT x[];
4232 unsigned EMUSHORT w[NI];
4235 etoasc (w, string, ndigs);
4240 e64toasc (x, string, ndigs)
4241 unsigned EMUSHORT x[];
4245 unsigned EMUSHORT w[NI];
4248 etoasc (w, string, ndigs);
4252 e113toasc (x, string, ndigs)
4253 unsigned EMUSHORT x[];
4257 unsigned EMUSHORT w[NI];
4260 etoasc (w, string, ndigs);
4264 static char wstring[80]; /* working storage for ASCII output */
4267 etoasc (x, string, ndigs)
4268 unsigned EMUSHORT x[];
4273 unsigned EMUSHORT y[NI], t[NI], u[NI], w[NI];
4274 unsigned EMUSHORT *p, *r, *ten;
4275 unsigned EMUSHORT sign;
4276 int i, j, k, expon, rndsav;
4278 unsigned EMUSHORT m;
4289 sprintf (wstring, " NaN ");
4293 rndprc = NBITS; /* set to full precision */
4294 emov (x, y); /* retain external format */
4295 if (y[NE - 1] & 0x8000)
4298 y[NE - 1] &= 0x7fff;
4305 ten = &etens[NTEN][0];
4307 /* Test for zero exponent */
4310 for (k = 0; k < NE - 1; k++)
4313 goto tnzro; /* denormalized number */
4315 goto isone; /* legal all zeros */
4319 /* Test for infinity. */
4320 if (y[NE - 1] == 0x7fff)
4323 sprintf (wstring, " -Infinity ");
4325 sprintf (wstring, " Infinity ");
4329 /* Test for exponent nonzero but significand denormalized.
4330 * This is an error condition.
4332 if ((y[NE - 1] != 0) && ((y[NE - 2] & 0x8000) == 0))
4334 mtherr ("etoasc", DOMAIN);
4335 sprintf (wstring, "NaN");
4339 /* Compare to 1.0 */
4348 { /* Number is greater than 1 */
4349 /* Convert significand to an integer and strip trailing decimal zeros. */
4351 u[NE - 1] = EXONE + NBITS - 1;
4353 p = &etens[NTEN - 4][0];
4359 for (j = 0; j < NE - 1; j++)
4372 /* Rescale from integer significand */
4373 u[NE - 1] += y[NE - 1] - (unsigned int) (EXONE + NBITS - 1);
4375 /* Find power of 10 */
4379 /* An unordered compare result shouldn't happen here. */
4380 while (ecmp (ten, u) <= 0)
4382 if (ecmp (p, u) <= 0)
4395 { /* Number is less than 1.0 */
4396 /* Pad significand with trailing decimal zeros. */
4399 while ((y[NE - 2] & 0x8000) == 0)
4408 for (i = 0; i < NDEC + 1; i++)
4410 if ((w[NI - 1] & 0x7) != 0)
4412 /* multiply by 10 */
4425 if (eone[NE - 1] <= u[1])
4437 while (ecmp (eone, w) > 0)
4439 if (ecmp (p, w) >= 0)
4454 /* Find the first (leading) digit. */
4460 digit = equot[NI - 1];
4461 while ((digit == 0) && (ecmp (y, ezero) != 0))
4469 digit = equot[NI - 1];
4477 /* Examine number of digits requested by caller. */
4495 *s++ = (char)digit + '0';
4498 /* Generate digits after the decimal point. */
4499 for (k = 0; k <= ndigs; k++)
4501 /* multiply current number by 10, without normalizing */
4508 *s++ = (char) equot[NI - 1] + '0';
4510 digit = equot[NI - 1];
4513 /* round off the ASCII string */
4516 /* Test for critical rounding case in ASCII output. */
4520 if (ecmp (t, ezero) != 0)
4521 goto roun; /* round to nearest */
4522 if ((*(s - 1) & 1) == 0)
4523 goto doexp; /* round to even */
4525 /* Round up and propagate carry-outs */
4529 /* Carry out to most significant digit? */
4536 /* Most significant digit carries to 10? */
4544 /* Round up and carry out from less significant digits */
4556 sprintf (ss, "e+%d", expon);
4558 sprintf (ss, "e%d", expon);
4560 sprintf (ss, "e%d", expon);
4563 /* copy out the working string */
4566 while (*ss == ' ') /* strip possible leading space */
4568 while ((*s++ = *ss++) != '\0')
4577 ; ASCTOQ.MAC LATEST REV: 11 JAN 84
4580 ; Convert ASCII string to quadruple precision floating point
4582 ; Numeric input is free field decimal number
4583 ; with max of 15 digits with or without
4584 ; decimal point entered as ASCII from teletype.
4585 ; Entering E after the number followed by a second
4586 ; number causes the second number to be interpreted
4587 ; as a power of 10 to be multiplied by the first number
4588 ; (i.e., "scientific" notation).
4591 ; asctoq (string, q);
4594 /* ASCII to single */
4598 unsigned EMUSHORT *y;
4604 /* ASCII to double */
4608 unsigned EMUSHORT *y;
4610 #if defined(DEC) || defined(IBM)
4618 /* ASCII to long double */
4622 unsigned EMUSHORT *y;
4627 /* ASCII to 128-bit long double */
4631 unsigned EMUSHORT *y;
4633 asctoeg (s, y, 113);
4636 /* ASCII to super double */
4640 unsigned EMUSHORT *y;
4642 asctoeg (s, y, NBITS);
4646 /* ASCII to e type, with specified rounding precision = oprec. */
4648 asctoeg (ss, y, oprec)
4650 unsigned EMUSHORT *y;
4653 unsigned EMUSHORT yy[NI], xt[NI], tt[NI];
4654 int esign, decflg, sgnflg, nexp, exp, prec, lost;
4655 int k, trail, c, rndsav;
4657 unsigned EMUSHORT nsign, *p;
4658 char *sp, *s, *lstr;
4660 /* Copy the input string. */
4661 lstr = (char *) alloca (strlen (ss) + 1);
4663 while (*s == ' ') /* skip leading spaces */
4666 while ((*sp++ = *s++) != '\0')
4671 rndprc = NBITS; /* Set to full precision */
4684 if ((k >= 0) && (k <= 9))
4686 /* Ignore leading zeros */
4687 if ((prec == 0) && (decflg == 0) && (k == 0))
4689 /* Identify and strip trailing zeros after the decimal point. */
4690 if ((trail == 0) && (decflg != 0))
4693 while ((*sp >= '0') && (*sp <= '9'))
4695 /* Check for syntax error */
4697 if ((c != 'e') && (c != 'E') && (c != '\0')
4698 && (c != '\n') && (c != '\r') && (c != ' ')
4708 /* If enough digits were given to more than fill up the yy register,
4709 * continuing until overflow into the high guard word yy[2]
4710 * guarantees that there will be a roundoff bit at the top
4711 * of the low guard word after normalization.
4716 nexp += 1; /* count digits after decimal point */
4717 eshup1 (yy); /* multiply current number by 10 */
4723 xt[NI - 2] = (unsigned EMUSHORT) k;
4728 /* Mark any lost non-zero digit. */
4730 /* Count lost digits before the decimal point. */
4745 case '.': /* decimal point */
4775 mtherr ("asctoe", DOMAIN);
4784 /* Exponent interpretation */
4790 /* check for + or - */
4798 while ((*s >= '0') && (*s <= '9'))
4802 if (exp > -(MINDECEXP))
4812 if (exp > MAXDECEXP)
4816 yy[E] = 0x7fff; /* infinity */
4819 if (exp < MINDECEXP)
4828 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
4829 while ((nexp > 0) && (yy[2] == 0))
4841 if ((k = enormlz (yy)) > NBITS)
4846 lexp = (EXONE - 1 + NBITS) - k;
4847 emdnorm (yy, lost, 0, lexp, 64);
4848 /* convert to external format */
4851 /* Multiply by 10**nexp. If precision is 64 bits,
4852 * the maximum relative error incurred in forming 10**n
4853 * for 0 <= n <= 324 is 8.2e-20, at 10**180.
4854 * For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
4855 * For 0 >= n >= -999, it is -1.55e-19 at 10**-435.
4869 { /* Punt. Can't handle this without 2 divides. */
4870 emovi (etens[0], tt);
4877 p = &etens[NTEN][0];
4887 while (exp <= MAXP);
4905 /* Round and convert directly to the destination type */
4907 lexp -= EXONE - 0x3ff;
4909 else if (oprec == 24 || oprec == 56)
4910 lexp -= EXONE - (0x41 << 2);
4912 else if (oprec == 24)
4913 lexp -= EXONE - 0177;
4916 else if (oprec == 56)
4917 lexp -= EXONE - 0201;
4920 emdnorm (yy, k, 0, lexp, 64);
4930 todec (yy, y); /* see etodec.c */
4935 toibm (yy, y, DFmode);
4958 /* y = largest integer not greater than x
4959 * (truncated toward minus infinity)
4961 * unsigned EMUSHORT x[NE], y[NE]
4965 static unsigned EMUSHORT bmask[] =
4988 unsigned EMUSHORT x[], y[];
4990 register unsigned EMUSHORT *p;
4992 unsigned EMUSHORT f[NE];
4994 emov (x, f); /* leave in external format */
4995 expon = (int) f[NE - 1];
4996 e = (expon & 0x7fff) - (EXONE - 1);
5002 /* number of bits to clear out */
5014 /* clear the remaining bits */
5016 /* truncate negatives toward minus infinity */
5019 if ((unsigned EMUSHORT) expon & (unsigned EMUSHORT) 0x8000)
5021 for (i = 0; i < NE - 1; i++)
5033 /* unsigned EMUSHORT x[], s[];
5036 * efrexp (x, exp, s);
5038 * Returns s and exp such that s * 2**exp = x and .5 <= s < 1.
5039 * For example, 1.1 = 0.55 * 2**1
5040 * Handles denormalized numbers properly using long integer exp.
5044 unsigned EMUSHORT x[];
5046 unsigned EMUSHORT s[];
5048 unsigned EMUSHORT xi[NI];
5052 li = (EMULONG) ((EMUSHORT) xi[1]);
5060 *exp = (int) (li - 0x3ffe);
5065 /* unsigned EMUSHORT x[], y[];
5068 * eldexp (x, pwr2, y);
5070 * Returns y = x * 2**pwr2.
5074 unsigned EMUSHORT x[];
5076 unsigned EMUSHORT y[];
5078 unsigned EMUSHORT xi[NI];
5086 emdnorm (xi, i, i, li, 64);
5091 /* c = remainder after dividing b by a
5092 * Least significant integer quotient bits left in equot[].
5096 unsigned EMUSHORT a[], b[], c[];
5098 unsigned EMUSHORT den[NI], num[NI];
5102 || (ecmp (a, ezero) == 0)
5110 if (ecmp (a, ezero) == 0)
5112 mtherr ("eremain", SING);
5118 eiremain (den, num);
5119 /* Sign of remainder = sign of quotient */
5129 unsigned EMUSHORT den[], num[];
5132 unsigned EMUSHORT j;
5135 ld -= enormlz (den);
5137 ln -= enormlz (num);
5141 if (ecmpm (den, num) <= 0)
5155 emdnorm (num, 0, 0, ln, 0);
5160 * Library common error handling routine
5170 * mtherr (fctnam, code);
5176 * This routine may be called to report one of the following
5177 * error conditions (in the include file mconf.h).
5179 * Mnemonic Value Significance
5181 * DOMAIN 1 argument domain error
5182 * SING 2 function singularity
5183 * OVERFLOW 3 overflow range error
5184 * UNDERFLOW 4 underflow range error
5185 * TLOSS 5 total loss of precision
5186 * PLOSS 6 partial loss of precision
5187 * INVALID 7 NaN - producing operation
5188 * EDOM 33 Unix domain error code
5189 * ERANGE 34 Unix range error code
5191 * The default version of the file prints the function name,
5192 * passed to it by the pointer fctnam, followed by the
5193 * error condition. The display is directed to the standard
5194 * output device. The routine then returns to the calling
5195 * program. Users may wish to modify the program to abort by
5196 * calling exit under severe error conditions such as domain
5199 * Since all error conditions pass control to this function,
5200 * the display may be easily changed, eliminated, or directed
5201 * to an error logging device.
5210 Cephes Math Library Release 2.0: April, 1987
5211 Copyright 1984, 1987 by Stephen L. Moshier
5212 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
5215 /* include "mconf.h" */
5217 /* Notice: the order of appearance of the following
5218 * messages is bound to the error codes defined
5222 static char *ermsg[NMSGS] =
5224 "unknown", /* error code 0 */
5225 "domain", /* error code 1 */
5226 "singularity", /* et seq. */
5229 "total loss of precision",
5230 "partial loss of precision",
5244 /* Display string passed by calling program,
5245 * which is supposed to be the name of the
5246 * function in which the error occurred.
5249 /* Display error message defined
5250 * by the code argument.
5252 if ((code <= 0) || (code >= NMSGS))
5254 sprintf (errstr, " %s %s error", name, ermsg[code]);
5257 /* Set global error message word */
5260 /* Return to calling
5266 /* Here is etodec.c .
5271 ; convert DEC double precision to e type
5278 unsigned EMUSHORT *d;
5279 unsigned EMUSHORT *e;
5281 unsigned EMUSHORT y[NI];
5282 register unsigned EMUSHORT r, *p;
5284 ecleaz (y); /* start with a zero */
5285 p = y; /* point to our number */
5286 r = *d; /* get DEC exponent word */
5287 if (*d & (unsigned int) 0x8000)
5288 *p = 0xffff; /* fill in our sign */
5289 ++p; /* bump pointer to our exponent word */
5290 r &= 0x7fff; /* strip the sign bit */
5291 if (r == 0) /* answer = 0 if high order DEC word = 0 */
5295 r >>= 7; /* shift exponent word down 7 bits */
5296 r += EXONE - 0201; /* subtract DEC exponent offset */
5297 /* add our e type exponent offset */
5298 *p++ = r; /* to form our exponent */
5300 r = *d++; /* now do the high order mantissa */
5301 r &= 0177; /* strip off the DEC exponent and sign bits */
5302 r |= 0200; /* the DEC understood high order mantissa bit */
5303 *p++ = r; /* put result in our high guard word */
5305 *p++ = *d++; /* fill in the rest of our mantissa */
5309 eshdn8 (y); /* shift our mantissa down 8 bits */
5317 ; convert e type to DEC double precision
5325 unsigned EMUSHORT *x, *d;
5327 unsigned EMUSHORT xi[NI];
5332 exp = (EMULONG) xi[E] - (EXONE - 0201); /* adjust exponent for offsets */
5333 /* round off to nearest or even */
5336 emdnorm (xi, 0, 0, exp, 64);
5343 unsigned EMUSHORT *x, *y;
5345 unsigned EMUSHORT i;
5346 unsigned EMUSHORT *p;
5390 ; convert IBM single/double precision to e type
5393 ; enum machine_mode mode; SFmode/DFmode
5394 ; ibmtoe (&d, e, mode);
5398 unsigned EMUSHORT *d;
5399 unsigned EMUSHORT *e;
5400 enum machine_mode mode;
5402 unsigned EMUSHORT y[NI];
5403 register unsigned EMUSHORT r, *p;
5406 ecleaz (y); /* start with a zero */
5407 p = y; /* point to our number */
5408 r = *d; /* get IBM exponent word */
5409 if (*d & (unsigned int) 0x8000)
5410 *p = 0xffff; /* fill in our sign */
5411 ++p; /* bump pointer to our exponent word */
5412 r &= 0x7f00; /* strip the sign bit */
5413 r >>= 6; /* shift exponent word down 6 bits */
5414 /* in fact shift by 8 right and 2 left */
5415 r += EXONE - (0x41 << 2); /* subtract IBM exponent offset */
5416 /* add our e type exponent offset */
5417 *p++ = r; /* to form our exponent */
5419 *p++ = *d++ & 0xff; /* now do the high order mantissa */
5420 /* strip off the IBM exponent and sign bits */
5421 if (mode != SFmode) /* there are only 2 words in SFmode */
5423 *p++ = *d++; /* fill in the rest of our mantissa */
5428 if (y[M] == 0 && y[M+1] == 0 && y[M+2] == 0 && y[M+3] == 0)
5431 y[E] -= 5 + enormlz (y); /* now normalise the mantissa */
5432 /* handle change in RADIX */
5439 ; convert e type to IBM single/double precision
5442 ; enum machine_mode mode; SFmode/DFmode
5443 ; etoibm (e, &d, mode);
5448 unsigned EMUSHORT *x, *d;
5449 enum machine_mode mode;
5451 unsigned EMUSHORT xi[NI];
5456 exp = (EMULONG) xi[E] - (EXONE - (0x41 << 2)); /* adjust exponent for offsets */
5457 /* round off to nearest or even */
5460 emdnorm (xi, 0, 0, exp, 64);
5462 toibm (xi, d, mode);
5467 unsigned EMUSHORT *x, *y;
5468 enum machine_mode mode;
5470 unsigned EMUSHORT i;
5471 unsigned EMUSHORT *p;
5519 /* Output a binary NaN bit pattern in the target machine's format. */
5521 /* If special NaN bit patterns are required, define them in tm.h
5522 as arrays of unsigned 16-bit shorts. Otherwise, use the default
5528 unsigned EMUSHORT TFnan[8] =
5529 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5532 unsigned EMUSHORT TFnan[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
5540 unsigned EMUSHORT XFnan[6] = {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5543 unsigned EMUSHORT XFnan[6] = {0, 0, 0, 0xc000, 0xffff, 0};
5551 unsigned EMUSHORT DFnan[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
5554 unsigned EMUSHORT DFnan[4] = {0, 0, 0, 0xfff8};
5562 unsigned EMUSHORT SFnan[2] = {0x7fff, 0xffff};
5565 unsigned EMUSHORT SFnan[2] = {0, 0xffc0};
5571 make_nan (nan, mode)
5572 unsigned EMUSHORT *nan;
5573 enum machine_mode mode;
5576 unsigned EMUSHORT *p;
5581 /* Possibly the `reserved operand' patterns on a VAX can be
5582 used like NaN's, but probably not in the same way as IEEE. */
5583 #if !defined(DEC) && !defined(IBM)
5604 for (i=0; i < n; i++)
5608 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
5609 This is the inverse of the function `etarsingle' invoked by
5610 REAL_VALUE_TO_TARGET_SINGLE. */
5613 ereal_from_float (f)
5617 unsigned EMUSHORT s[2];
5618 unsigned EMUSHORT e[NE];
5620 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
5621 This is the inverse operation to what the function `endian' does. */
5622 #if WORDS_BIG_ENDIAN
5623 s[0] = (unsigned EMUSHORT) (f >> 16);
5624 s[1] = (unsigned EMUSHORT) f;
5626 s[0] = (unsigned EMUSHORT) f;
5627 s[1] = (unsigned EMUSHORT) (f >> 16);
5629 /* Convert and promote the target float to E-type. */
5631 /* Output E-type to REAL_VALUE_TYPE. */
5637 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
5638 This is the inverse of the function `etardouble' invoked by
5639 REAL_VALUE_TO_TARGET_DOUBLE.
5641 The DFmode is stored as an array of longs (i.e., HOST_WIDE_INTs)
5642 with 32 bits of the value per each long. The first element
5643 of the input array holds the bits that would come first in the
5644 target computer's memory. */
5647 ereal_from_double (d)
5651 unsigned EMUSHORT s[4];
5652 unsigned EMUSHORT e[NE];
5654 /* Convert array of 32 bit pieces to equivalent array of 16 bit pieces.
5655 This is the inverse of `endian'. */
5656 #if WORDS_BIG_ENDIAN
5657 s[0] = (unsigned EMUSHORT) (d[0] >> 16);
5658 s[1] = (unsigned EMUSHORT) d[0];
5659 s[2] = (unsigned EMUSHORT) (d[1] >> 16);
5660 s[3] = (unsigned EMUSHORT) d[1];
5662 s[0] = (unsigned EMUSHORT) d[0];
5663 s[1] = (unsigned EMUSHORT) (d[0] >> 16);
5664 s[2] = (unsigned EMUSHORT) d[1];
5665 s[3] = (unsigned EMUSHORT) (d[1] >> 16);
5667 /* Convert target double to E-type. */
5669 /* Output E-type to REAL_VALUE_TYPE. */
5675 /* Convert target computer unsigned 64-bit integer to e-type. */
5679 unsigned EMUSHORT *di; /* Address of the 64-bit int. */
5680 unsigned EMUSHORT *e;
5682 unsigned EMUSHORT yi[NI];
5686 #if WORDS_BIG_ENDIAN
5687 for (k = M; k < M + 4; k++)
5690 for (k = M + 3; k >= M; k--)
5693 yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
5694 if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
5695 ecleaz (yi); /* it was zero */
5697 yi[E] -= (unsigned EMUSHORT) k;/* subtract shift count from exponent */
5701 /* Convert target computer signed 64-bit integer to e-type. */
5705 unsigned EMUSHORT *di; /* Address of the 64-bit int. */
5706 unsigned EMUSHORT *e;
5708 unsigned EMULONG acc;
5709 unsigned EMUSHORT yi[NI];
5710 unsigned EMUSHORT carry;
5714 #if WORDS_BIG_ENDIAN
5715 for (k = M; k < M + 4; k++)
5718 for (k = M + 3; k >= M; k--)
5721 /* Take absolute value */
5727 for (k = M + 3; k >= M; k--)
5729 acc = (unsigned EMULONG) (~yi[k] & 0xffff) + carry;
5736 yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
5737 if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
5738 ecleaz (yi); /* it was zero */
5740 yi[E] -= (unsigned EMUSHORT) k;/* subtract shift count from exponent */
5747 /* Convert e-type to unsigned 64-bit int. */
5751 unsigned EMUSHORT *x;
5752 unsigned EMUSHORT *i;
5754 unsigned EMUSHORT xi[NI];
5763 k = (int) xi[E] - (EXONE - 1);
5766 for (j = 0; j < 4; j++)
5772 for (j = 0; j < 4; j++)
5775 warning ("overflow on truncation to integer");
5780 /* Shift more than 16 bits: first shift up k-16 mod 16,
5781 then shift up by 16's. */
5782 j = k - ((k >> 4) << 4);
5786 #if WORDS_BIG_ENDIAN
5796 #if WORDS_BIG_ENDIAN
5802 while ((k -= 16) > 0);
5806 /* shift not more than 16 bits */
5811 #if WORDS_BIG_ENDIAN
5827 /* Convert e-type to signed 64-bit int. */
5831 unsigned EMUSHORT *x;
5832 unsigned EMUSHORT *i;
5834 unsigned EMULONG acc;
5835 unsigned EMUSHORT xi[NI];
5836 unsigned EMUSHORT carry;
5837 unsigned EMUSHORT *isave;
5841 k = (int) xi[E] - (EXONE - 1);
5844 for (j = 0; j < 4; j++)
5850 for (j = 0; j < 4; j++)
5853 warning ("overflow on truncation to integer");
5859 /* Shift more than 16 bits: first shift up k-16 mod 16,
5860 then shift up by 16's. */
5861 j = k - ((k >> 4) << 4);
5865 #if WORDS_BIG_ENDIAN
5875 #if WORDS_BIG_ENDIAN
5881 while ((k -= 16) > 0);
5885 /* shift not more than 16 bits */
5888 #if WORDS_BIG_ENDIAN
5901 /* Negate if negative */
5905 #if WORDS_BIG_ENDIAN
5908 for (k = 0; k < 4; k++)
5910 acc = (unsigned EMULONG) (~(*isave) & 0xffff) + carry;
5911 #if WORDS_BIG_ENDIAN
5924 /* Longhand square root routine. */
5927 static int esqinited = 0;
5928 static unsigned short sqrndbit[NI];
5932 unsigned EMUSHORT *x, *y;
5934 unsigned EMUSHORT temp[NI], num[NI], sq[NI], xx[NI];
5936 int i, j, k, n, nlups;
5941 sqrndbit[NI - 2] = 1;
5944 /* Check for arg <= 0 */
5945 i = ecmp (x, ezero);
5957 mtherr ("esqrt", DOMAIN);
5969 /* Bring in the arg and renormalize if it is denormal. */
5971 m = (EMULONG) xx[1]; /* local long word exponent */
5975 /* Divide exponent by 2 */
5977 exp = (unsigned short) ((m / 2) + 0x3ffe);
5979 /* Adjust if exponent odd */
5989 n = 8; /* get 8 bits of result per inner loop */
5995 /* bring in next word of arg */
5997 num[NI - 1] = xx[j + 3];
5998 /* Do additional bit on last outer loop, for roundoff. */
6001 for (i = 0; i < n; i++)
6003 /* Next 2 bits of arg */
6006 /* Shift up answer */
6008 /* Make trial divisor */
6009 for (k = 0; k < NI; k++)
6012 eaddm (sqrndbit, temp);
6013 /* Subtract and insert answer bit if it goes in */
6014 if (ecmpm (temp, num) <= 0)
6024 /* Adjust for extra, roundoff loop done. */
6025 exp += (NBITS - 1) - rndprc;
6027 /* Sticky bit = 1 if the remainder is nonzero. */
6029 for (i = 3; i < NI; i++)
6032 /* Renormalize and round off. */
6033 emdnorm (sq, k, 0, exp, 64);
6037 #endif /* EMU_NON_COMPILE not defined */