1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2002 Free Software Foundation, Inc.
5 Contributed by Stephen L. Moshier (moshier@world.std.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 /* To enable support of XFmode extended real floating point, define
31 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
33 Machine files (tm.h etc) must not contain any code
34 that tries to use host floating point arithmetic to convert
35 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
36 etc. In cross-compile situations a REAL_VALUE_TYPE may not
37 be intelligible to the host computer's native arithmetic.
39 The first part of this file interfaces gcc to a floating point
40 arithmetic suite that was not written with gcc in mind. Avoid
41 changing the low-level arithmetic routines unless you have suitable
42 test programs available. A special version of the PARANOIA floating
43 point arithmetic tester, modified for this purpose, can be found on
44 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
45 XFmode and TFmode transcendental functions, can be obtained by ftp from
46 netlib.att.com: netlib/cephes. */
48 /* Type of computer arithmetic.
49 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
51 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
52 to big-endian IEEE floating-point data structure. This definition
53 should work in SFmode `float' type and DFmode `double' type on
54 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
55 has been defined to be 96, then IEEE also invokes the particular
56 XFmode (`long double' type) data structure used by the Motorola
57 680x0 series processors.
59 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
60 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
61 has been defined to be 96, then IEEE also invokes the particular
62 XFmode `long double' data structure used by the Intel 80x86 series
65 `DEC' refers specifically to the Digital Equipment Corp PDP-11
66 and VAX floating point data structure. This model currently
67 supports no type wider than DFmode.
69 `IBM' refers specifically to the IBM System/370 and compatible
70 floating point data structure. This model currently supports
71 no type wider than DFmode. The IBM conversions were contributed by
72 frank@atom.ansto.gov.au (Frank Crawford).
74 `C4X' refers specifically to the floating point format used on
75 Texas Instruments TMS320C3x and TMS320C4x digital signal
76 processors. This supports QFmode (32-bit float, double) and HFmode
77 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
78 floats, C4x floats are not rounded to be even. The C4x conversions
79 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
80 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
82 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
83 then `long double' and `double' are both implemented, but they
86 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
87 and may deactivate XFmode since `long double' is used to refer
88 to both modes. Defining INTEL_EXTENDED_IEEE_FORMAT to non-zero
89 at the same time enables 80387-style 80-bit floats in a 128-bit
90 padded image, as seen on IA-64.
92 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
93 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
94 separate the floating point unit's endian-ness from that of
95 the integer addressing. This permits one to define a big-endian
96 FPU on a little-endian machine (e.g., ARM). An extension to
97 BYTES_BIG_ENDIAN may be required for some machines in the future.
98 These optional macros may be defined in tm.h. In real.h, they
99 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
100 them for any normal host or target machine on which the floats
101 and the integers have the same endian-ness. */
104 /* The following converts gcc macros into the ones used by this file. */
106 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
107 /* PDP-11, Pro350, VAX: */
109 #else /* it's not VAX */
110 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
111 /* IBM System/370 style */
113 #else /* it's also not an IBM */
114 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
115 /* TMS320C3x/C4x style */
117 #else /* it's also not a C4X */
118 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
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 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
131 /* Define INFINITY for support of infinity.
132 Define NANS for support of Not-a-Number's (NaN's). */
133 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
138 /* Support of NaNs requires support of infinity. */
145 /* Find a host integer type that is at least 16 bits wide,
146 and another type at least twice whatever that size is. */
148 #if HOST_BITS_PER_CHAR >= 16
149 #define EMUSHORT char
150 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
151 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
153 #if HOST_BITS_PER_SHORT >= 16
154 #define EMUSHORT short
155 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
156 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
158 #if HOST_BITS_PER_INT >= 16
160 #define EMUSHORT_SIZE HOST_BITS_PER_INT
161 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
163 #if HOST_BITS_PER_LONG >= 16
164 #define EMUSHORT long
165 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
166 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
168 #error "You will have to modify this program to have a smaller unit size."
174 /* If no 16-bit type has been found and the compiler is GCC, try HImode. */
175 #if defined(__GNUC__) && EMUSHORT_SIZE != 16
176 typedef int HItype
__attribute__ ((mode (HI
)));
177 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
181 #define EMUSHORT HItype
182 #define UEMUSHORT UHItype
183 #define EMUSHORT_SIZE 16
184 #define EMULONG_SIZE 32
186 #define UEMUSHORT unsigned EMUSHORT
189 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
190 #define EMULONG short
192 #if HOST_BITS_PER_INT >= EMULONG_SIZE
195 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
198 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
199 #define EMULONG long long int
201 #error "You will have to modify this program to have a smaller unit size."
207 #if EMUSHORT_SIZE != 16
208 #error "The host interface doesn't work if no 16-bit size exists."
211 /* Calculate the size of the generic "e" type. This always has
212 identical in-memory size to REAL_VALUE_TYPE.
213 There are only two supported sizes: ten and six 16-bit words (160
216 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !INTEL_EXTENDED_IEEE_FORMAT
219 # define MAXDECEXP 4932
220 # define MINDECEXP -4977
223 # define MAXDECEXP 4932
224 # define MINDECEXP -4956
227 /* Fail compilation if 2*NE is not the appropriate size.
228 If HOST_BITS_PER_WIDE_INT is 64, we're going to have padding
229 at the end of the array, because neither 96 nor 160 is
230 evenly divisible by 64. */
231 struct compile_test_dummy
{
232 char twice_NE_must_equal_sizeof_REAL_VALUE_TYPE
233 [(sizeof (REAL_VALUE_TYPE
) >= 2*NE
) ? 1 : -1];
236 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
237 In GET_REAL and PUT_REAL, r and e are pointers.
238 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
239 in memory, with no holes. */
240 #define GET_REAL(r, e) memcpy ((e), (r), 2*NE)
241 #define PUT_REAL(e, r) \
243 memcpy (r, e, 2*NE); \
244 if (2*NE < sizeof (*r)) \
245 memset ((char *) (r) + 2*NE, 0, sizeof (*r) - 2*NE); \
248 /* Number of 16 bit words in internal format */
251 /* Array offset to exponent */
254 /* Array offset to high guard word */
257 /* Number of bits of precision */
258 #define NBITS ((NI-4)*16)
260 /* Maximum number of decimal digits in ASCII conversion
263 #define NDEC (NBITS*8/27)
265 /* The exponent of 1.0 */
266 #define EXONE (0x3fff)
268 #if defined(HOST_EBCDIC)
269 /* bit 8 is significant in EBCDIC */
270 #define CHARMASK 0xff
272 #define CHARMASK 0x7f
275 extern int extra_warnings
;
276 extern const UEMUSHORT ezero
[NE
], ehalf
[NE
], eone
[NE
], etwo
[NE
];
277 extern const UEMUSHORT elog2
[NE
], esqrt2
[NE
];
279 static void endian
PARAMS ((const UEMUSHORT
*, long *,
281 static void eclear
PARAMS ((UEMUSHORT
*));
282 static void emov
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
284 static void eabs
PARAMS ((UEMUSHORT
*));
286 static void eneg
PARAMS ((UEMUSHORT
*));
287 static int eisneg
PARAMS ((const UEMUSHORT
*));
288 static int eisinf
PARAMS ((const UEMUSHORT
*));
289 static int eisnan
PARAMS ((const UEMUSHORT
*));
290 static void einfin
PARAMS ((UEMUSHORT
*));
292 static void enan
PARAMS ((UEMUSHORT
*, int));
293 static void einan
PARAMS ((UEMUSHORT
*));
294 static int eiisnan
PARAMS ((const UEMUSHORT
*));
295 static void make_nan
PARAMS ((UEMUSHORT
*, int, enum machine_mode
));
297 static int eiisneg
PARAMS ((const UEMUSHORT
*));
298 static void saturate
PARAMS ((UEMUSHORT
*, int, int, int));
299 static void emovi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
300 static void emovo
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
301 static void ecleaz
PARAMS ((UEMUSHORT
*));
302 static void ecleazs
PARAMS ((UEMUSHORT
*));
303 static void emovz
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
305 static void eiinfin
PARAMS ((UEMUSHORT
*));
308 static int eiisinf
PARAMS ((const UEMUSHORT
*));
310 static int ecmpm
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
311 static void eshdn1
PARAMS ((UEMUSHORT
*));
312 static void eshup1
PARAMS ((UEMUSHORT
*));
313 static void eshdn8
PARAMS ((UEMUSHORT
*));
314 static void eshup8
PARAMS ((UEMUSHORT
*));
315 static void eshup6
PARAMS ((UEMUSHORT
*));
316 static void eshdn6
PARAMS ((UEMUSHORT
*));
317 static void eaddm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));\f
318 static void esubm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
319 static void m16m
PARAMS ((unsigned int, const UEMUSHORT
*, UEMUSHORT
*));
320 static int edivm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
321 static int emulm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
322 static void emdnorm
PARAMS ((UEMUSHORT
*, int, int, EMULONG
, int));
323 static void esub
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
325 static void eadd
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
327 static void eadd1
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
329 static void ediv
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
331 static void emul
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
333 static void e53toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
334 static void e64toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
335 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
336 static void e113toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
338 static void e24toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
339 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
340 static void etoe113
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
341 static void toe113
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
343 static void etoe64
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
344 static void toe64
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
345 static void etoe53
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
346 static void toe53
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
347 static void etoe24
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
348 static void toe24
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
349 static int ecmp
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
351 static void eround
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
353 static void ltoe
PARAMS ((const HOST_WIDE_INT
*, UEMUSHORT
*));
354 static void ultoe
PARAMS ((const unsigned HOST_WIDE_INT
*, UEMUSHORT
*));
355 static void eifrac
PARAMS ((const UEMUSHORT
*, HOST_WIDE_INT
*,
357 static void euifrac
PARAMS ((const UEMUSHORT
*, unsigned HOST_WIDE_INT
*,
359 static int eshift
PARAMS ((UEMUSHORT
*, int));
360 static int enormlz
PARAMS ((UEMUSHORT
*));
362 static void e24toasc
PARAMS ((const UEMUSHORT
*, char *, int));
363 static void e53toasc
PARAMS ((const UEMUSHORT
*, char *, int));
364 static void e64toasc
PARAMS ((const UEMUSHORT
*, char *, int));
365 static void e113toasc
PARAMS ((const UEMUSHORT
*, char *, int));
367 static void etoasc
PARAMS ((const UEMUSHORT
*, char *, int));
368 static void asctoe24
PARAMS ((const char *, UEMUSHORT
*));
369 static void asctoe53
PARAMS ((const char *, UEMUSHORT
*));
370 static void asctoe64
PARAMS ((const char *, UEMUSHORT
*));
371 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
372 static void asctoe113
PARAMS ((const char *, UEMUSHORT
*));
374 static void asctoe
PARAMS ((const char *, UEMUSHORT
*));
375 static void asctoeg
PARAMS ((const char *, UEMUSHORT
*, int));
376 static void efloor
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
378 static void efrexp
PARAMS ((const UEMUSHORT
*, int *,
381 static void eldexp
PARAMS ((const UEMUSHORT
*, int, UEMUSHORT
*));
383 static void eremain
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
386 static void eiremain
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
387 static void mtherr
PARAMS ((const char *, int));
389 static void dectoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
390 static void etodec
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
391 static void todec
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
394 static void ibmtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
396 static void etoibm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
398 static void toibm
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
402 static void c4xtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
404 static void etoc4x
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
406 static void toc4x
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
410 static void uditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
411 static void ditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
412 static void etoudi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
413 static void etodi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
414 static void esqrt
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
417 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
418 swapping ends if required, into output array of longs. The
419 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
425 enum machine_mode mode
;
429 if (REAL_WORDS_BIG_ENDIAN
)
434 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
435 /* Swap halfwords in the fourth long. */
436 th
= (unsigned long) e
[6] & 0xffff;
437 t
= (unsigned long) e
[7] & 0xffff;
446 /* Swap halfwords in the third long. */
447 th
= (unsigned long) e
[4] & 0xffff;
448 t
= (unsigned long) e
[5] & 0xffff;
454 /* Swap halfwords in the second word. */
455 th
= (unsigned long) e
[2] & 0xffff;
456 t
= (unsigned long) e
[3] & 0xffff;
463 /* Swap halfwords in the first word. */
464 th
= (unsigned long) e
[0] & 0xffff;
465 t
= (unsigned long) e
[1] & 0xffff;
476 /* Pack the output array without swapping. */
481 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
482 /* Pack the fourth long. */
483 th
= (unsigned long) e
[7] & 0xffff;
484 t
= (unsigned long) e
[6] & 0xffff;
493 /* Pack the third long.
494 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
496 th
= (unsigned long) e
[5] & 0xffff;
497 t
= (unsigned long) e
[4] & 0xffff;
503 /* Pack the second long */
504 th
= (unsigned long) e
[3] & 0xffff;
505 t
= (unsigned long) e
[2] & 0xffff;
512 /* Pack the first long */
513 th
= (unsigned long) e
[1] & 0xffff;
514 t
= (unsigned long) e
[0] & 0xffff;
526 /* This is the implementation of the REAL_ARITHMETIC macro. */
529 earith (value
, icode
, r1
, r2
)
530 REAL_VALUE_TYPE
*value
;
535 UEMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
541 /* Return NaN input back to the caller. */
544 PUT_REAL (d1
, value
);
549 PUT_REAL (d2
, value
);
553 code
= (enum tree_code
) icode
;
561 esub (d2
, d1
, v
); /* d1 - d2 */
570 if (ecmp (d2
, ezero
) == 0)
573 ediv (d2
, d1
, v
); /* d1/d2 */
576 case MIN_EXPR
: /* min (d1,d2) */
577 if (ecmp (d1
, d2
) < 0)
583 case MAX_EXPR
: /* max (d1,d2) */
584 if (ecmp (d1
, d2
) > 0)
597 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
598 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
604 UEMUSHORT f
[NE
], g
[NE
];
620 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
621 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
627 UEMUSHORT f
[NE
], g
[NE
];
629 unsigned HOST_WIDE_INT l
;
643 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
644 string to binary, rounding off as indicated by the machine_mode argument.
645 Then it promotes the rounded value to REAL_VALUE_TYPE. */
652 UEMUSHORT tem
[NE
], e
[NE
];
678 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
698 /* Expansion of REAL_NEGATE. */
714 /* Round real toward zero to HOST_WIDE_INT;
715 implements REAL_VALUE_FIX (x). */
721 UEMUSHORT f
[NE
], g
[NE
];
728 warning ("conversion from NaN to int");
736 /* Round real toward zero to unsigned HOST_WIDE_INT
737 implements REAL_VALUE_UNSIGNED_FIX (x).
738 Negative input returns zero. */
740 unsigned HOST_WIDE_INT
744 UEMUSHORT f
[NE
], g
[NE
];
745 unsigned HOST_WIDE_INT l
;
751 warning ("conversion from NaN to unsigned int");
760 /* REAL_VALUE_FROM_INT macro. */
763 ereal_from_int (d
, i
, j
, mode
)
766 enum machine_mode mode
;
768 UEMUSHORT df
[NE
], dg
[NE
];
769 HOST_WIDE_INT low
, high
;
772 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
779 /* complement and add 1 */
786 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
787 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
789 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
794 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
795 Avoid double-rounding errors later by rounding off now from the
796 extra-wide internal format to the requested precision. */
797 switch (GET_MODE_BITSIZE (mode
))
815 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
832 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
835 ereal_from_uint (d
, i
, j
, mode
)
837 unsigned HOST_WIDE_INT i
, j
;
838 enum machine_mode mode
;
840 UEMUSHORT df
[NE
], dg
[NE
];
841 unsigned HOST_WIDE_INT low
, high
;
843 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
847 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
853 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
854 Avoid double-rounding errors later by rounding off now from the
855 extra-wide internal format to the requested precision. */
856 switch (GET_MODE_BITSIZE (mode
))
874 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
891 /* REAL_VALUE_TO_INT macro. */
894 ereal_to_int (low
, high
, rr
)
895 HOST_WIDE_INT
*low
, *high
;
898 UEMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
905 warning ("conversion from NaN to int");
911 /* convert positive value */
918 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
919 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
920 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
921 emul (df
, dh
, dg
); /* fractional part is the low word */
922 euifrac (dg
, (unsigned HOST_WIDE_INT
*) low
, dh
);
925 /* complement and add 1 */
935 /* REAL_VALUE_LDEXP macro. */
942 UEMUSHORT e
[NE
], y
[NE
];
955 /* Check for infinity in a REAL_VALUE_TYPE. */
959 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
971 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
975 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
988 /* Check for a negative REAL_VALUE_TYPE number.
989 This just checks the sign bit, so that -0 counts as negative. */
995 return ereal_isneg (x
);
998 /* Expansion of REAL_VALUE_TRUNCATE.
999 The result is in floating point, rounded to nearest or even. */
1002 real_value_truncate (mode
, arg
)
1003 enum machine_mode mode
;
1004 REAL_VALUE_TYPE arg
;
1006 UEMUSHORT e
[NE
], t
[NE
];
1018 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
1055 /* If an unsupported type was requested, presume that
1056 the machine files know something useful to do with
1057 the unmodified value. */
1066 /* Try to change R into its exact multiplicative inverse in machine mode
1067 MODE. Return nonzero function value if successful. */
1070 exact_real_inverse (mode
, r
)
1071 enum machine_mode mode
;
1074 UEMUSHORT e
[NE
], einv
[NE
];
1075 REAL_VALUE_TYPE rinv
;
1080 /* Test for input in range. Don't transform IEEE special values. */
1081 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1084 /* Test for a power of 2: all significand bits zero except the MSB.
1085 We are assuming the target has binary (or hex) arithmetic. */
1086 if (e
[NE
- 2] != 0x8000)
1089 for (i
= 0; i
< NE
- 2; i
++)
1095 /* Compute the inverse and truncate it to the required mode. */
1096 ediv (e
, eone
, einv
);
1097 PUT_REAL (einv
, &rinv
);
1098 rinv
= real_value_truncate (mode
, rinv
);
1100 #ifdef CHECK_FLOAT_VALUE
1101 /* This check is not redundant. It may, for example, flush
1102 a supposedly IEEE denormal value to zero. */
1104 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1107 GET_REAL (&rinv
, einv
);
1109 /* Check the bits again, because the truncation might have
1110 generated an arbitrary saturation value on overflow. */
1111 if (einv
[NE
- 2] != 0x8000)
1114 for (i
= 0; i
< NE
- 2; i
++)
1120 /* Fail if the computed inverse is out of range. */
1121 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1124 /* Output the reciprocal and return success flag. */
1129 /* Used for debugging--print the value of R in human-readable format
1138 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1139 fprintf (stderr
, "%s", dstr
);
1143 /* The following routines convert REAL_VALUE_TYPE to the various floating
1144 point formats that are meaningful to supported computers.
1146 The results are returned in 32-bit pieces, each piece stored in a `long'.
1147 This is so they can be printed by statements like
1149 fprintf (file, "%lx, %lx", L[0], L[1]);
1151 that will work on both narrow- and wide-word host computers. */
1153 /* Convert R to a 128-bit long double precision value. The output array L
1154 contains four 32-bit pieces of the result, in the order they would appear
1165 #if INTEL_EXTENDED_IEEE_FORMAT == 0
1170 endian (e
, l
, TFmode
);
1173 /* Convert R to a double extended precision value. The output array L
1174 contains three 32-bit pieces of the result, in the order they would
1175 appear in memory. */
1186 endian (e
, l
, XFmode
);
1189 /* Convert R to a double precision value. The output array L contains two
1190 32-bit pieces of the result, in the order they would appear in memory. */
1201 endian (e
, l
, DFmode
);
1204 /* Convert R to a single precision float value stored in the least-significant
1205 bits of a `long'. */
1216 endian (e
, &l
, SFmode
);
1220 /* Convert X to a decimal ASCII string S for output to an assembly
1221 language file. Note, there is no standard way to spell infinity or
1222 a NaN, so these values may require special treatment in the tm.h
1226 ereal_to_decimal (x
, s
)
1236 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1237 or -2 if either is a NaN. */
1241 REAL_VALUE_TYPE x
, y
;
1243 UEMUSHORT ex
[NE
], ey
[NE
];
1247 return (ecmp (ex
, ey
));
1250 /* Return 1 if the sign bit of X is set, else return 0. */
1259 return (eisneg (ex
));
1264 Extended precision IEEE binary floating point arithmetic routines
1266 Numbers are stored in C language as arrays of 16-bit unsigned
1267 short integers. The arguments of the routines are pointers to
1270 External e type data structure, similar to Intel 8087 chip
1271 temporary real format but possibly with a larger significand:
1273 NE-1 significand words (least significant word first,
1274 most significant bit is normally set)
1275 exponent (value = EXONE for 1.0,
1276 top bit is the sign)
1279 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1281 ei[0] sign word (0 for positive, 0xffff for negative)
1282 ei[1] biased exponent (value = EXONE for the number 1.0)
1283 ei[2] high guard word (always zero after normalization)
1285 to ei[NI-2] significand (NI-4 significand words,
1286 most significant word first,
1287 most significant bit is set)
1288 ei[NI-1] low guard word (0x8000 bit is rounding place)
1292 Routines for external format e-type numbers
1294 asctoe (string, e) ASCII string to extended double e type
1295 asctoe64 (string, &d) ASCII string to long double
1296 asctoe53 (string, &d) ASCII string to double
1297 asctoe24 (string, &f) ASCII string to single
1298 asctoeg (string, e, prec) ASCII string to specified precision
1299 e24toe (&f, e) IEEE single precision to e type
1300 e53toe (&d, e) IEEE double precision to e type
1301 e64toe (&d, e) IEEE long double precision to e type
1302 e113toe (&d, e) 128-bit long double precision to e type
1304 eabs (e) absolute value
1306 eadd (a, b, c) c = b + a
1308 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1309 -1 if a < b, -2 if either a or b is a NaN.
1310 ediv (a, b, c) c = b / a
1311 efloor (a, b) truncate to integer, toward -infinity
1312 efrexp (a, exp, s) extract exponent and significand
1313 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1314 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1315 einfin (e) set e to infinity, leaving its sign alone
1316 eldexp (a, n, b) multiply by 2**n
1318 emul (a, b, c) c = b * a
1321 eround (a, b) b = nearest integer value to a
1323 esub (a, b, c) c = b - a
1325 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1326 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1327 e64toasc (&d, str, n) 80-bit long double to ASCII string
1328 e113toasc (&d, str, n) 128-bit long double to ASCII string
1330 etoasc (e, str, n) e to ASCII string, n digits after decimal
1331 etoe24 (e, &f) convert e type to IEEE single precision
1332 etoe53 (e, &d) convert e type to IEEE double precision
1333 etoe64 (e, &d) convert e type to IEEE long double precision
1334 ltoe (&l, e) HOST_WIDE_INT to e type
1335 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1336 eisneg (e) 1 if sign bit of e != 0, else 0
1337 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1338 or is infinite (IEEE)
1339 eisnan (e) 1 if e is a NaN
1342 Routines for internal format exploded e-type numbers
1344 eaddm (ai, bi) add significands, bi = bi + ai
1346 ecleazs (ei) set ei = 0 but leave its sign alone
1347 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1348 edivm (ai, bi) divide significands, bi = bi / ai
1349 emdnorm (ai,l,s,exp) normalize and round off
1350 emovi (a, ai) convert external a to internal ai
1351 emovo (ai, a) convert internal ai to external a
1352 emovz (ai, bi) bi = ai, low guard word of bi = 0
1353 emulm (ai, bi) multiply significands, bi = bi * ai
1354 enormlz (ei) left-justify the significand
1355 eshdn1 (ai) shift significand and guards down 1 bit
1356 eshdn8 (ai) shift down 8 bits
1357 eshdn6 (ai) shift down 16 bits
1358 eshift (ai, n) shift ai n bits up (or down if n < 0)
1359 eshup1 (ai) shift significand and guards up 1 bit
1360 eshup8 (ai) shift up 8 bits
1361 eshup6 (ai) shift up 16 bits
1362 esubm (ai, bi) subtract significands, bi = bi - ai
1363 eiisinf (ai) 1 if infinite
1364 eiisnan (ai) 1 if a NaN
1365 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1366 einan (ai) set ai = NaN
1368 eiinfin (ai) set ai = infinity
1371 The result is always normalized and rounded to NI-4 word precision
1372 after each arithmetic operation.
1374 Exception flags are NOT fully supported.
1376 Signaling NaN's are NOT supported; they are treated the same
1379 Define INFINITY for support of infinity; otherwise a
1380 saturation arithmetic is implemented.
1382 Define NANS for support of Not-a-Number items; otherwise the
1383 arithmetic will never produce a NaN output, and might be confused
1385 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1386 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1387 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1390 Denormals are always supported here where appropriate (e.g., not
1391 for conversion to DEC numbers). */
1393 /* Definitions for error codes that are passed to the common error handling
1396 For Digital Equipment PDP-11 and VAX computers, certain
1397 IBM systems, and others that use numbers with a 56-bit
1398 significand, the symbol DEC should be defined. In this
1399 mode, most floating point constants are given as arrays
1400 of octal integers to eliminate decimal to binary conversion
1401 errors that might be introduced by the compiler.
1403 For computers, such as IBM PC, that follow the IEEE
1404 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1405 Std 754-1985), the symbol IEEE should be defined.
1406 These numbers have 53-bit significands. In this mode, constants
1407 are provided as arrays of hexadecimal 16 bit integers.
1408 The endian-ness of generated values is controlled by
1409 REAL_WORDS_BIG_ENDIAN.
1411 To accommodate other types of computer arithmetic, all
1412 constants are also provided in a normal decimal radix
1413 which one can hope are correctly converted to a suitable
1414 format by the available C language compiler. To invoke
1415 this mode, the symbol UNK is defined.
1417 An important difference among these modes is a predefined
1418 set of machine arithmetic constants for each. The numbers
1419 MACHEP (the machine roundoff error), MAXNUM (largest number
1420 represented), and several other parameters are preset by
1421 the configuration symbol. Check the file const.c to
1422 ensure that these values are correct for your computer.
1424 For ANSI C compatibility, define ANSIC equal to 1. Currently
1425 this affects only the atan2 function and others that use it. */
1427 /* Constant definitions for math error conditions. */
1429 #define DOMAIN 1 /* argument domain error */
1430 #define SING 2 /* argument singularity */
1431 #define OVERFLOW 3 /* overflow range error */
1432 #define UNDERFLOW 4 /* underflow range error */
1433 #define TLOSS 5 /* total loss of precision */
1434 #define PLOSS 6 /* partial loss of precision */
1435 #define INVALID 7 /* NaN-producing operation */
1437 /* e type constants used by high precision check routines */
1439 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
1441 const UEMUSHORT ezero
[NE
] =
1442 {0x0000, 0x0000, 0x0000, 0x0000,
1443 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1446 const UEMUSHORT ehalf
[NE
] =
1447 {0x0000, 0x0000, 0x0000, 0x0000,
1448 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1451 const UEMUSHORT eone
[NE
] =
1452 {0x0000, 0x0000, 0x0000, 0x0000,
1453 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1456 const UEMUSHORT etwo
[NE
] =
1457 {0x0000, 0x0000, 0x0000, 0x0000,
1458 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1461 const UEMUSHORT e32
[NE
] =
1462 {0x0000, 0x0000, 0x0000, 0x0000,
1463 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1465 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1466 const UEMUSHORT elog2
[NE
] =
1467 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1468 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1470 /* 1.41421356237309504880168872420969807856967187537695E0 */
1471 const UEMUSHORT esqrt2
[NE
] =
1472 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1473 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1475 /* 3.14159265358979323846264338327950288419716939937511E0 */
1476 const UEMUSHORT epi
[NE
] =
1477 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1478 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1481 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1482 const UEMUSHORT ezero
[NE
] =
1483 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1484 const UEMUSHORT ehalf
[NE
] =
1485 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1486 const UEMUSHORT eone
[NE
] =
1487 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1488 const UEMUSHORT etwo
[NE
] =
1489 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1490 const UEMUSHORT e32
[NE
] =
1491 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1492 const UEMUSHORT elog2
[NE
] =
1493 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1494 const UEMUSHORT esqrt2
[NE
] =
1495 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1496 const UEMUSHORT epi
[NE
] =
1497 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1500 /* Control register for rounding precision.
1501 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1506 /* Clear out entire e-type number X. */
1514 for (i
= 0; i
< NE
; i
++)
1518 /* Move e-type number from A to B. */
1527 for (i
= 0; i
< NE
; i
++)
1533 /* Absolute value of e-type X. */
1539 /* sign is top bit of last word of external format */
1540 x
[NE
- 1] &= 0x7fff;
1544 /* Negate the e-type number X. */
1551 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1554 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1558 const UEMUSHORT x
[];
1561 if (x
[NE
- 1] & 0x8000)
1567 /* Return 1 if e-type number X is infinity, else return zero. */
1571 const UEMUSHORT x
[];
1578 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1584 /* Check if e-type number is not a number. The bit pattern is one that we
1585 defined, so we know for sure how to detect it. */
1589 const UEMUSHORT x
[] ATTRIBUTE_UNUSED
;
1594 /* NaN has maximum exponent */
1595 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1597 /* ... and non-zero significand field. */
1598 for (i
= 0; i
< NE
- 1; i
++)
1608 /* Fill e-type number X with infinity pattern (IEEE)
1609 or largest possible number (non-IEEE). */
1618 for (i
= 0; i
< NE
- 1; i
++)
1622 for (i
= 0; i
< NE
- 1; i
++)
1650 /* Output an e-type NaN.
1651 This generates Intel's quiet NaN pattern for extended real.
1652 The exponent is 7fff, the leading mantissa word is c000. */
1662 for (i
= 0; i
< NE
- 2; i
++)
1665 *x
= (sign
<< 15) | 0x7fff;
1669 /* Move in an e-type number A, converting it to exploded e-type B. */
1681 p
= a
+ (NE
- 1); /* point to last word of external number */
1682 /* get the sign bit */
1687 /* get the exponent */
1689 *q
++ &= 0x7fff; /* delete the sign bit */
1691 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1697 for (i
= 3; i
< NI
; i
++)
1703 for (i
= 2; i
< NI
; i
++)
1709 /* clear high guard word */
1711 /* move in the significand */
1712 for (i
= 0; i
< NE
- 1; i
++)
1714 /* clear low guard word */
1718 /* Move out exploded e-type number A, converting it to e type B. */
1731 q
= b
+ (NE
- 1); /* point to output exponent */
1732 /* combine sign and exponent */
1735 *q
-- = *p
++ | 0x8000;
1739 if (*(p
- 1) == 0x7fff)
1744 enan (b
, eiisneg (a
));
1752 /* skip over guard word */
1754 /* move the significand */
1755 for (j
= 0; j
< NE
- 1; j
++)
1759 /* Clear out exploded e-type number XI. */
1767 for (i
= 0; i
< NI
; i
++)
1771 /* Clear out exploded e-type XI, but don't touch the sign. */
1780 for (i
= 0; i
< NI
- 1; i
++)
1784 /* Move exploded e-type number from A to B. */
1793 for (i
= 0; i
< NI
- 1; i
++)
1795 /* clear low guard word */
1799 /* Generate exploded e-type NaN.
1800 The explicit pattern for this is maximum exponent and
1801 top two significant bits set. */
1815 /* Return nonzero if exploded e-type X is a NaN. */
1820 const UEMUSHORT x
[];
1824 if ((x
[E
] & 0x7fff) == 0x7fff)
1826 for (i
= M
+ 1; i
< NI
; i
++)
1836 /* Return nonzero if sign of exploded e-type X is nonzero. */
1840 const UEMUSHORT x
[];
1847 /* Fill exploded e-type X with infinity pattern.
1848 This has maximum exponent and significand all zeros. */
1860 /* Return nonzero if exploded e-type X is infinite. */
1865 const UEMUSHORT x
[];
1872 if ((x
[E
] & 0x7fff) == 0x7fff)
1876 #endif /* INFINITY */
1878 /* Compare significands of numbers in internal exploded e-type format.
1879 Guard words are included in the comparison.
1887 const UEMUSHORT
*a
, *b
;
1891 a
+= M
; /* skip up to significand area */
1893 for (i
= M
; i
< NI
; i
++)
1901 if (*(--a
) > *(--b
))
1907 /* Shift significand of exploded e-type X down by 1 bit. */
1916 x
+= M
; /* point to significand area */
1919 for (i
= M
; i
< NI
; i
++)
1931 /* Shift significand of exploded e-type X up by 1 bit. */
1943 for (i
= M
; i
< NI
; i
++)
1956 /* Shift significand of exploded e-type X down by 8 bits. */
1962 UEMUSHORT newbyt
, oldbyt
;
1967 for (i
= M
; i
< NI
; i
++)
1977 /* Shift significand of exploded e-type X up by 8 bits. */
1984 UEMUSHORT newbyt
, oldbyt
;
1989 for (i
= M
; i
< NI
; i
++)
1999 /* Shift significand of exploded e-type X up by 16 bits. */
2011 for (i
= M
; i
< NI
- 1; i
++)
2017 /* Shift significand of exploded e-type X down by 16 bits. */
2029 for (i
= M
; i
< NI
- 1; i
++)
2035 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2049 for (i
= M
; i
< NI
; i
++)
2051 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2062 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2076 for (i
= M
; i
< NI
; i
++)
2078 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2090 static UEMUSHORT equot
[NI
];
2094 /* Radix 2 shift-and-add versions of multiply and divide */
2097 /* Divide significands */
2101 UEMUSHORT den
[], num
[];
2111 for (i
= M
; i
< NI
; i
++)
2116 /* Use faster compare and subtraction if denominator has only 15 bits of
2122 for (i
= M
+ 3; i
< NI
; i
++)
2127 if ((den
[M
+ 1] & 1) != 0)
2135 for (i
= 0; i
< NBITS
+ 2; i
++)
2153 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2154 bit + 1 roundoff bit. */
2159 for (i
= 0; i
< NBITS
+ 2; i
++)
2161 if (ecmpm (den
, num
) <= 0)
2164 j
= 1; /* quotient bit = 1 */
2178 /* test for nonzero remainder after roundoff bit */
2181 for (i
= M
; i
< NI
; i
++)
2189 for (i
= 0; i
< NI
; i
++)
2195 /* Multiply significands */
2206 for (i
= M
; i
< NI
; i
++)
2211 while (*p
== 0) /* significand is not supposed to be zero */
2216 if ((*p
& 0xff) == 0)
2224 for (i
= 0; i
< k
; i
++)
2228 /* remember if there were any nonzero bits shifted out */
2235 for (i
= 0; i
< NI
; i
++)
2238 /* return flag for lost nonzero bits */
2244 /* Radix 65536 versions of multiply and divide. */
2246 /* Multiply significand of e-type number B
2247 by 16-bit quantity A, return e-type result to C. */
2252 const UEMUSHORT b
[];
2256 unsigned EMULONG carry
;
2257 const UEMUSHORT
*ps
;
2259 unsigned EMULONG aa
, m
;
2268 for (i
=M
+1; i
<NI
; i
++)
2278 m
= (unsigned EMULONG
) aa
* *ps
--;
2279 carry
= (m
& 0xffff) + *pp
;
2280 *pp
-- = (UEMUSHORT
) carry
;
2281 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2282 *pp
= (UEMUSHORT
) carry
;
2283 *(pp
-1) = carry
>> 16;
2286 for (i
=M
; i
<NI
; i
++)
2290 /* Divide significands of exploded e-types NUM / DEN. Neither the
2291 numerator NUM nor the denominator DEN is permitted to have its high guard
2296 const UEMUSHORT den
[];
2301 unsigned EMULONG tnum
;
2302 UEMUSHORT j
, tdenm
, tquot
;
2303 UEMUSHORT tprod
[NI
+1];
2309 for (i
=M
; i
<NI
; i
++)
2315 for (i
=M
; i
<NI
; i
++)
2317 /* Find trial quotient digit (the radix is 65536). */
2318 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2320 /* Do not execute the divide instruction if it will overflow. */
2321 if ((tdenm
* (unsigned long) 0xffff) < tnum
)
2324 tquot
= tnum
/ tdenm
;
2325 /* Multiply denominator by trial quotient digit. */
2326 m16m ((unsigned int) tquot
, den
, tprod
);
2327 /* The quotient digit may have been overestimated. */
2328 if (ecmpm (tprod
, num
) > 0)
2332 if (ecmpm (tprod
, num
) > 0)
2342 /* test for nonzero remainder after roundoff bit */
2345 for (i
=M
; i
<NI
; i
++)
2352 for (i
=0; i
<NI
; i
++)
2358 /* Multiply significands of exploded e-type A and B, result in B. */
2362 const UEMUSHORT a
[];
2367 UEMUSHORT pprod
[NI
];
2373 for (i
=M
; i
<NI
; i
++)
2379 for (i
=M
+1; i
<NI
; i
++)
2387 m16m ((unsigned int) *p
--, b
, pprod
);
2388 eaddm (pprod
, equot
);
2394 for (i
=0; i
<NI
; i
++)
2397 /* return flag for lost nonzero bits */
2403 /* Normalize and round off.
2405 The internal format number to be rounded is S.
2406 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2408 Input SUBFLG indicates whether the number was obtained
2409 by a subtraction operation. In that case if LOST is nonzero
2410 then the number is slightly smaller than indicated.
2412 Input EXP is the biased exponent, which may be negative.
2413 the exponent field of S is ignored but is replaced by
2414 EXP as adjusted by normalization and rounding.
2416 Input RCNTRL is the rounding control. If it is nonzero, the
2417 returned value will be rounded to RNDPRC bits.
2419 For future reference: In order for emdnorm to round off denormal
2420 significands at the right point, the input exponent must be
2421 adjusted to be the actual value it would have after conversion to
2422 the final floating point type. This adjustment has been
2423 implemented for all type conversions (etoe53, etc.) and decimal
2424 conversions, but not for the arithmetic functions (eadd, etc.).
2425 Data types having standard 15-bit exponents are not affected by
2426 this, but SFmode and DFmode are affected. For example, ediv with
2427 rndprc = 24 will not round correctly to 24-bit precision if the
2428 result is denormal. */
2430 static int rlast
= -1;
2432 static UEMUSHORT rmsk
= 0;
2433 static UEMUSHORT rmbit
= 0;
2434 static UEMUSHORT rebit
= 0;
2436 static UEMUSHORT rbit
[NI
];
2439 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2452 /* a blank significand could mean either zero or infinity. */
2465 if ((j
> NBITS
) && (exp
< 32767))
2473 if (exp
> (EMULONG
) (-NBITS
- 1))
2486 /* Round off, unless told not to by rcntrl. */
2489 /* Set up rounding parameters if the control register changed. */
2490 if (rndprc
!= rlast
)
2497 rw
= NI
- 1; /* low guard word */
2520 /* For DEC or IBM arithmetic */
2537 /* For C4x arithmetic */
2558 /* Shift down 1 temporarily if the data structure has an implied
2559 most significant bit and the number is denormal.
2560 Intel long double denormals also lose one bit of precision. */
2561 if ((exp
<= 0) && (rndprc
!= NBITS
)
2562 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2564 lost
|= s
[NI
- 1] & 1;
2567 /* Clear out all bits below the rounding bit,
2568 remembering in r if any were nonzero. */
2582 if ((r
& rmbit
) != 0)
2588 { /* round to even */
2589 if ((s
[re
] & rebit
) == 0)
2602 /* Undo the temporary shift for denormal values. */
2603 if ((exp
<= 0) && (rndprc
!= NBITS
)
2604 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2609 { /* overflow on roundoff */
2622 for (i
= 2; i
< NI
- 1; i
++)
2625 warning ("floating point overflow");
2629 for (i
= M
+ 1; i
< NI
- 1; i
++)
2632 if ((rndprc
< 64) || (rndprc
== 113))
2647 s
[1] = (UEMUSHORT
) exp
;
2650 /* Subtract. C = B - A, all e type numbers. */
2652 static int subflg
= 0;
2656 const UEMUSHORT
*a
, *b
;
2671 /* Infinity minus infinity is a NaN.
2672 Test for subtracting infinities of the same sign. */
2673 if (eisinf (a
) && eisinf (b
)
2674 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2676 mtherr ("esub", INVALID
);
2685 /* Add. C = A + B, all e type. */
2689 const UEMUSHORT
*a
, *b
;
2694 /* NaN plus anything is a NaN. */
2705 /* Infinity minus infinity is a NaN.
2706 Test for adding infinities of opposite signs. */
2707 if (eisinf (a
) && eisinf (b
)
2708 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2710 mtherr ("esub", INVALID
);
2719 /* Arithmetic common to both addition and subtraction. */
2723 const UEMUSHORT
*a
, *b
;
2726 UEMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2728 EMULONG lt
, lta
, ltb
;
2749 /* compare exponents */
2754 { /* put the larger number in bi */
2764 if (lt
< (EMULONG
) (-NBITS
- 1))
2765 goto done
; /* answer same as larger addend */
2767 lost
= eshift (ai
, k
); /* shift the smaller number down */
2771 /* exponents were the same, so must compare significands */
2774 { /* the numbers are identical in magnitude */
2775 /* if different signs, result is zero */
2781 /* if same sign, result is double */
2782 /* double denormalized tiny number */
2783 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2788 /* add 1 to exponent unless both are zero! */
2789 for (j
= 1; j
< NI
- 1; j
++)
2805 bi
[E
] = (UEMUSHORT
) ltb
;
2809 { /* put the larger number in bi */
2825 emdnorm (bi
, lost
, subflg
, ltb
, !ROUND_TOWARDS_ZERO
);
2831 /* Divide: C = B/A, all e type. */
2835 const UEMUSHORT
*a
, *b
;
2838 UEMUSHORT ai
[NI
], bi
[NI
];
2840 EMULONG lt
, lta
, ltb
;
2842 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2843 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2844 sign
= eisneg (a
) ^ eisneg (b
);
2847 /* Return any NaN input. */
2858 /* Zero over zero, or infinity over infinity, is a NaN. */
2859 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2860 || (eisinf (a
) && eisinf (b
)))
2862 mtherr ("ediv", INVALID
);
2867 /* Infinity over anything else is infinity. */
2874 /* Anything else over infinity is zero. */
2886 { /* See if numerator is zero. */
2887 for (i
= 1; i
< NI
- 1; i
++)
2891 ltb
-= enormlz (bi
);
2901 { /* possible divide by zero */
2902 for (i
= 1; i
< NI
- 1; i
++)
2906 lta
-= enormlz (ai
);
2910 /* Divide by zero is not an invalid operation.
2911 It is a divide-by-zero operation! */
2913 mtherr ("ediv", SING
);
2919 /* calculate exponent */
2920 lt
= ltb
- lta
+ EXONE
;
2921 emdnorm (bi
, i
, 0, lt
, !ROUND_TOWARDS_ZERO
);
2928 && (ecmp (c
, ezero
) != 0)
2931 *(c
+(NE
-1)) |= 0x8000;
2933 *(c
+(NE
-1)) &= ~0x8000;
2936 /* Multiply e-types A and B, return e-type product C. */
2940 const UEMUSHORT
*a
, *b
;
2943 UEMUSHORT ai
[NI
], bi
[NI
];
2945 EMULONG lt
, lta
, ltb
;
2947 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2948 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2949 sign
= eisneg (a
) ^ eisneg (b
);
2952 /* NaN times anything is the same NaN. */
2963 /* Zero times infinity is a NaN. */
2964 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2965 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2967 mtherr ("emul", INVALID
);
2972 /* Infinity times anything else is infinity. */
2974 if (eisinf (a
) || eisinf (b
))
2986 for (i
= 1; i
< NI
- 1; i
++)
2990 lta
-= enormlz (ai
);
3001 for (i
= 1; i
< NI
- 1; i
++)
3005 ltb
-= enormlz (bi
);
3014 /* Multiply significands */
3016 /* calculate exponent */
3017 lt
= lta
+ ltb
- (EXONE
- 1);
3018 emdnorm (bi
, j
, 0, lt
, !ROUND_TOWARDS_ZERO
);
3025 && (ecmp (c
, ezero
) != 0)
3028 *(c
+(NE
-1)) |= 0x8000;
3030 *(c
+(NE
-1)) &= ~0x8000;
3033 /* Convert double precision PE to e-type Y. */
3037 const UEMUSHORT
*pe
;
3047 ibmtoe (pe
, y
, DFmode
);
3052 c4xtoe (pe
, y
, HFmode
);
3062 denorm
= 0; /* flag if denormalized number */
3064 if (! REAL_WORDS_BIG_ENDIAN
)
3070 yy
[M
] = (r
& 0x0f) | 0x10;
3071 r
&= ~0x800f; /* strip sign and 4 significand bits */
3076 if (! REAL_WORDS_BIG_ENDIAN
)
3078 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3079 || (pe
[1] != 0) || (pe
[0] != 0))
3081 enan (y
, yy
[0] != 0);
3087 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3088 || (pe
[2] != 0) || (pe
[3] != 0))
3090 enan (y
, yy
[0] != 0);
3101 #endif /* INFINITY */
3103 /* If zero exponent, then the significand is denormalized.
3104 So take back the understood high significand bit. */
3115 if (! REAL_WORDS_BIG_ENDIAN
)
3132 /* If zero exponent, then normalize the significand. */
3133 if ((k
= enormlz (yy
)) > NBITS
)
3136 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3139 #endif /* not C4X */
3140 #endif /* not IBM */
3141 #endif /* not DEC */
3144 /* Convert double extended precision float PE to e type Y. */
3148 const UEMUSHORT
*pe
;
3158 for (i
= 0; i
< NE
- 5; i
++)
3160 /* This precision is not ordinarily supported on DEC or IBM. */
3162 for (i
= 0; i
< 5; i
++)
3166 p
= &yy
[0] + (NE
- 1);
3169 for (i
= 0; i
< 5; i
++)
3173 if (! REAL_WORDS_BIG_ENDIAN
)
3175 for (i
= 0; i
< 5; i
++)
3178 /* For denormal long double Intel format, shift significand up one
3179 -- but only if the top significand bit is zero. A top bit of 1
3180 is "pseudodenormal" when the exponent is zero. */
3181 if ((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3193 p
= &yy
[0] + (NE
- 1);
3194 #ifdef ARM_EXTENDED_IEEE_FORMAT
3195 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3196 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3202 for (i
= 0; i
< 4; i
++)
3207 /* Point to the exponent field and check max exponent cases. */
3209 if ((*p
& 0x7fff) == 0x7fff)
3212 if (! REAL_WORDS_BIG_ENDIAN
)
3214 for (i
= 0; i
< 4; i
++)
3216 if ((i
!= 3 && pe
[i
] != 0)
3217 /* Anything but 0x8000 here, including 0, is a NaN. */
3218 || (i
== 3 && pe
[i
] != 0x8000))
3220 enan (y
, (*p
& 0x8000) != 0);
3227 #ifdef ARM_EXTENDED_IEEE_FORMAT
3228 for (i
= 2; i
<= 5; i
++)
3232 enan (y
, (*p
& 0x8000) != 0);
3237 /* In Motorola extended precision format, the most significant
3238 bit of an infinity mantissa could be either 1 or 0. It is
3239 the lower order bits that tell whether the value is a NaN. */
3240 if ((pe
[2] & 0x7fff) != 0)
3243 for (i
= 3; i
<= 5; i
++)
3248 enan (y
, (*p
& 0x8000) != 0);
3252 #endif /* not ARM */
3261 #endif /* INFINITY */
3264 for (i
= 0; i
< NE
; i
++)
3268 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3269 /* Convert 128-bit long double precision float PE to e type Y. */
3273 const UEMUSHORT
*pe
;
3286 if (! REAL_WORDS_BIG_ENDIAN
)
3298 if (! REAL_WORDS_BIG_ENDIAN
)
3300 for (i
= 0; i
< 7; i
++)
3304 enan (y
, yy
[0] != 0);
3311 for (i
= 1; i
< 8; i
++)
3315 enan (y
, yy
[0] != 0);
3327 #endif /* INFINITY */
3331 if (! REAL_WORDS_BIG_ENDIAN
)
3333 for (i
= 0; i
< 7; i
++)
3339 for (i
= 0; i
< 7; i
++)
3343 /* If denormal, remove the implied bit; else shift down 1. */
3357 /* Convert single precision float PE to e type Y. */
3361 const UEMUSHORT
*pe
;
3366 ibmtoe (pe
, y
, SFmode
);
3372 c4xtoe (pe
, y
, QFmode
);
3383 denorm
= 0; /* flag if denormalized number */
3386 if (! REAL_WORDS_BIG_ENDIAN
)
3396 yy
[M
] = (r
& 0x7f) | 0200;
3397 r
&= ~0x807f; /* strip sign and 7 significand bits */
3399 if (!LARGEST_EXPONENT_IS_NORMAL (32) && r
== 0x7f80)
3402 if (REAL_WORDS_BIG_ENDIAN
)
3404 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3406 enan (y
, yy
[0] != 0);
3412 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3414 enan (y
, yy
[0] != 0);
3425 #endif /* INFINITY */
3427 /* If zero exponent, then the significand is denormalized.
3428 So take back the understood high significand bit. */
3441 if (! REAL_WORDS_BIG_ENDIAN
)
3451 { /* if zero exponent, then normalize the significand */
3452 if ((k
= enormlz (yy
)) > NBITS
)
3455 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3458 #endif /* not C4X */
3459 #endif /* not IBM */
3462 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3463 /* Convert e-type X to IEEE 128-bit long double format E. */
3477 make_nan (e
, eisneg (x
), TFmode
);
3482 exp
= (EMULONG
) xi
[E
];
3487 /* round off to nearest or even */
3490 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3498 /* Convert exploded e-type X, that has already been rounded to
3499 113-bit precision, to IEEE 128-bit long double format Y. */
3511 make_nan (b
, eiisneg (a
), TFmode
);
3516 if (REAL_WORDS_BIG_ENDIAN
)
3519 q
= b
+ 7; /* point to output exponent */
3521 /* If not denormal, delete the implied bit. */
3526 /* combine sign and exponent */
3528 if (REAL_WORDS_BIG_ENDIAN
)
3531 *q
++ = *p
++ | 0x8000;
3538 *q
-- = *p
++ | 0x8000;
3542 /* skip over guard word */
3544 /* move the significand */
3545 if (REAL_WORDS_BIG_ENDIAN
)
3547 for (i
= 0; i
< 7; i
++)
3552 for (i
= 0; i
< 7; i
++)
3558 /* Convert e-type X to IEEE double extended format E. */
3572 make_nan (e
, eisneg (x
), XFmode
);
3577 /* adjust exponent for offset */
3578 exp
= (EMULONG
) xi
[E
];
3583 /* round off to nearest or even */
3586 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3594 /* Convert exploded e-type X, that has already been rounded to
3595 64-bit precision, to IEEE double extended format Y. */
3607 make_nan (b
, eiisneg (a
), XFmode
);
3611 /* Shift denormal long double Intel format significand down one bit. */
3612 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3622 if (REAL_WORDS_BIG_ENDIAN
)
3626 q
= b
+ 4; /* point to output exponent */
3627 /* Clear the last two bytes of 12-byte Intel format. q is pointing
3628 into an array of size 6 (e.g. x[NE]), so the last two bytes are
3629 always there, and there are never more bytes, even when we are using
3630 INTEL_EXTENDED_IEEE_FORMAT. */
3635 /* combine sign and exponent */
3639 *q
++ = *p
++ | 0x8000;
3646 *q
-- = *p
++ | 0x8000;
3651 if (REAL_WORDS_BIG_ENDIAN
)
3653 #ifdef ARM_EXTENDED_IEEE_FORMAT
3654 /* The exponent is in the lowest 15 bits of the first word. */
3655 *q
++ = i
? 0x8000 : 0;
3659 *q
++ = *p
++ | 0x8000;
3668 *q
-- = *p
++ | 0x8000;
3673 /* skip over guard word */
3675 /* move the significand */
3677 for (i
= 0; i
< 4; i
++)
3681 for (i
= 0; i
< 4; i
++)
3685 if (REAL_WORDS_BIG_ENDIAN
)
3687 for (i
= 0; i
< 4; i
++)
3695 /* Intel long double infinity significand. */
3703 for (i
= 0; i
< 4; i
++)
3709 /* e type to double precision. */
3712 /* Convert e-type X to DEC-format double E. */
3719 etodec (x
, e
); /* see etodec.c */
3722 /* Convert exploded e-type X, that has already been rounded to
3723 56-bit double precision, to DEC double Y. */
3734 /* Convert e-type X to IBM 370-format double E. */
3741 etoibm (x
, e
, DFmode
);
3744 /* Convert exploded e-type X, that has already been rounded to
3745 56-bit precision, to IBM 370 double Y. */
3751 toibm (x
, y
, DFmode
);
3754 #else /* it's neither DEC nor IBM */
3756 /* Convert e-type X to C4X-format long double E. */
3763 etoc4x (x
, e
, HFmode
);
3766 /* Convert exploded e-type X, that has already been rounded to
3767 56-bit precision, to IBM 370 double Y. */
3773 toc4x (x
, y
, HFmode
);
3776 #else /* it's neither DEC nor IBM nor C4X */
3778 /* Convert e-type X to IEEE double E. */
3792 make_nan (e
, eisneg (x
), DFmode
);
3797 /* adjust exponent for offsets */
3798 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3803 /* round off to nearest or even */
3806 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3814 /* Convert exploded e-type X, that has already been rounded to
3815 53-bit precision, to IEEE double Y. */
3827 make_nan (y
, eiisneg (x
), DFmode
);
3831 if (LARGEST_EXPONENT_IS_NORMAL (64) && x
[1] > 2047)
3833 saturate (y
, eiisneg (x
), 64, 1);
3838 if (! REAL_WORDS_BIG_ENDIAN
)
3841 *y
= 0; /* output high order */
3843 *y
= 0x8000; /* output sign bit */
3846 if (i
>= (unsigned int) 2047)
3848 /* Saturate at largest number less than infinity. */
3851 if (! REAL_WORDS_BIG_ENDIAN
)
3865 *y
|= (UEMUSHORT
) 0x7fef;
3866 if (! REAL_WORDS_BIG_ENDIAN
)
3891 i
|= *p
++ & (UEMUSHORT
) 0x0f; /* *p = xi[M] */
3892 *y
|= (UEMUSHORT
) i
; /* high order output already has sign bit set */
3893 if (! REAL_WORDS_BIG_ENDIAN
)
3908 #endif /* not C4X */
3909 #endif /* not IBM */
3910 #endif /* not DEC */
3914 /* e type to single precision. */
3917 /* Convert e-type X to IBM 370 float E. */
3924 etoibm (x
, e
, SFmode
);
3927 /* Convert exploded e-type X, that has already been rounded to
3928 float precision, to IBM 370 float Y. */
3934 toibm (x
, y
, SFmode
);
3940 /* Convert e-type X to C4X float E. */
3947 etoc4x (x
, e
, QFmode
);
3950 /* Convert exploded e-type X, that has already been rounded to
3951 float precision, to IBM 370 float Y. */
3957 toc4x (x
, y
, QFmode
);
3962 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3976 make_nan (e
, eisneg (x
), SFmode
);
3981 /* adjust exponent for offsets */
3982 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3987 /* round off to nearest or even */
3990 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3998 /* Convert exploded e-type X, that has already been rounded to
3999 float precision, to IEEE float Y. */
4011 make_nan (y
, eiisneg (x
), SFmode
);
4015 if (LARGEST_EXPONENT_IS_NORMAL (32) && x
[1] > 255)
4017 saturate (y
, eiisneg (x
), 32, 1);
4022 if (! REAL_WORDS_BIG_ENDIAN
)
4028 *y
= 0; /* output high order */
4030 *y
= 0x8000; /* output sign bit */
4033 /* Handle overflow cases. */
4034 if (!LARGEST_EXPONENT_IS_NORMAL (32) && i
>= 255)
4037 *y
|= (UEMUSHORT
) 0x7f80;
4042 if (! REAL_WORDS_BIG_ENDIAN
)
4050 #else /* no INFINITY */
4051 *y
|= (UEMUSHORT
) 0x7f7f;
4056 if (! REAL_WORDS_BIG_ENDIAN
)
4067 #endif /* no INFINITY */
4079 i
|= *p
++ & (UEMUSHORT
) 0x7f; /* *p = xi[M] */
4080 /* High order output already has sign bit set. */
4086 if (! REAL_WORDS_BIG_ENDIAN
)
4095 #endif /* not C4X */
4096 #endif /* not IBM */
4098 /* Compare two e type numbers.
4102 -2 if either a or b is a NaN. */
4106 const UEMUSHORT
*a
, *b
;
4108 UEMUSHORT ai
[NI
], bi
[NI
];
4114 if (eisnan (a
) || eisnan (b
))
4123 { /* the signs are different */
4125 for (i
= 1; i
< NI
- 1; i
++)
4139 /* both are the same sign */
4154 return (0); /* equality */
4158 if (*(--p
) > *(--q
))
4159 return (msign
); /* p is bigger */
4161 return (-msign
); /* p is littler */
4165 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4177 /* Convert HOST_WIDE_INT LP to e type Y. */
4181 const HOST_WIDE_INT
*lp
;
4185 unsigned HOST_WIDE_INT ll
;
4191 /* make it positive */
4192 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4193 yi
[0] = 0xffff; /* put correct sign in the e type number */
4197 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4199 /* move the long integer to yi significand area */
4200 #if HOST_BITS_PER_WIDE_INT == 64
4201 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4202 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4203 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4204 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4205 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4207 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4208 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4209 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4212 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4213 ecleaz (yi
); /* it was zero */
4215 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
4216 emovo (yi
, y
); /* output the answer */
4219 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4223 const unsigned HOST_WIDE_INT
*lp
;
4227 unsigned HOST_WIDE_INT ll
;
4233 /* move the long integer to ayi significand area */
4234 #if HOST_BITS_PER_WIDE_INT == 64
4235 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4236 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4237 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4238 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4239 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4241 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4242 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4243 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4246 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4247 ecleaz (yi
); /* it was zero */
4249 yi
[E
] -= (UEMUSHORT
) k
; /* subtract shift count from exponent */
4250 emovo (yi
, y
); /* output the answer */
4254 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4255 part FRAC of e-type (packed internal format) floating point input X.
4256 The integer output I has the sign of the input, except that
4257 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4258 The output e-type fraction FRAC is the positive fractional
4269 unsigned HOST_WIDE_INT ll
;
4272 k
= (int) xi
[E
] - (EXONE
- 1);
4275 /* if exponent <= 0, integer = 0 and real output is fraction */
4280 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4282 /* long integer overflow: output large integer
4283 and correct fraction */
4285 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4288 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4289 /* In this case, let it overflow and convert as if unsigned. */
4290 euifrac (x
, &ll
, frac
);
4291 *i
= (HOST_WIDE_INT
) ll
;
4294 /* In other cases, return the largest positive integer. */
4295 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4300 warning ("overflow on truncation to integer");
4304 /* Shift more than 16 bits: first shift up k-16 mod 16,
4305 then shift up by 16's. */
4306 j
= k
- ((k
>> 4) << 4);
4313 ll
= (ll
<< 16) | xi
[M
];
4315 while ((k
-= 16) > 0);
4322 /* shift not more than 16 bits */
4324 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4331 if ((k
= enormlz (xi
)) > NBITS
)
4334 xi
[E
] -= (UEMUSHORT
) k
;
4340 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4341 FRAC of e-type X. A negative input yields integer output = 0 but
4342 correct fraction. */
4345 euifrac (x
, i
, frac
)
4347 unsigned HOST_WIDE_INT
*i
;
4350 unsigned HOST_WIDE_INT ll
;
4355 k
= (int) xi
[E
] - (EXONE
- 1);
4358 /* if exponent <= 0, integer = 0 and argument is fraction */
4363 if (k
> HOST_BITS_PER_WIDE_INT
)
4365 /* Long integer overflow: output large integer
4366 and correct fraction.
4367 Note, the BSD MicroVAX compiler says that ~(0UL)
4368 is a syntax error. */
4372 warning ("overflow on truncation to unsigned integer");
4376 /* Shift more than 16 bits: first shift up k-16 mod 16,
4377 then shift up by 16's. */
4378 j
= k
- ((k
>> 4) << 4);
4385 ll
= (ll
<< 16) | xi
[M
];
4387 while ((k
-= 16) > 0);
4392 /* shift not more than 16 bits */
4394 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4397 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4403 if ((k
= enormlz (xi
)) > NBITS
)
4406 xi
[E
] -= (UEMUSHORT
) k
;
4411 /* Shift the significand of exploded e-type X up or down by SC bits. */
4432 lost
|= *p
; /* remember lost bits */
4473 return ((int) lost
);
4476 /* Shift normalize the significand area of exploded e-type X.
4477 Return the shift count (up = positive). */
4492 return (0); /* already normalized */
4498 /* With guard word, there are NBITS+16 bits available.
4499 Return true if all are zero. */
4503 /* see if high byte is zero */
4504 while ((*p
& 0xff00) == 0)
4509 /* now shift 1 bit at a time */
4510 while ((*p
& 0x8000) == 0)
4516 mtherr ("enormlz", UNDERFLOW
);
4522 /* Normalize by shifting down out of the high guard word
4523 of the significand */
4538 mtherr ("enormlz", OVERFLOW
);
4545 /* Powers of ten used in decimal <-> binary conversions. */
4550 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
4551 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4553 {0x6576, 0x4a92, 0x804a, 0x153f,
4554 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4555 {0x6a32, 0xce52, 0x329a, 0x28ce,
4556 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4557 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4558 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4559 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4560 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4561 {0x851e, 0xeab7, 0x98fe, 0x901b,
4562 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4563 {0x0235, 0x0137, 0x36b1, 0x336c,
4564 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4565 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4566 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4567 {0x0000, 0x0000, 0x0000, 0x0000,
4568 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4569 {0x0000, 0x0000, 0x0000, 0x0000,
4570 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4571 {0x0000, 0x0000, 0x0000, 0x0000,
4572 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4573 {0x0000, 0x0000, 0x0000, 0x0000,
4574 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4575 {0x0000, 0x0000, 0x0000, 0x0000,
4576 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4577 {0x0000, 0x0000, 0x0000, 0x0000,
4578 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4581 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4583 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4584 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4585 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4586 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4587 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4588 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4589 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4590 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4591 {0xa23e, 0x5308, 0xfefb, 0x1155,
4592 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4593 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4594 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4595 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4596 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4597 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4598 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4599 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4600 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4601 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4602 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4603 {0xc155, 0xa4a8, 0x404e, 0x6113,
4604 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4605 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4606 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4607 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4608 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4611 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4612 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4614 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4615 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4616 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4617 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4618 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4619 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4620 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4621 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4622 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4623 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4624 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4625 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4626 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4629 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4631 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4632 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4633 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4634 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4635 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4636 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4637 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4638 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4639 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4640 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4641 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4642 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4643 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4648 /* Convert float value X to ASCII string STRING with NDIG digits after
4649 the decimal point. */
4652 e24toasc (x
, string
, ndigs
)
4653 const UEMUSHORT x
[];
4660 etoasc (w
, string
, ndigs
);
4663 /* Convert double value X to ASCII string STRING with NDIG digits after
4664 the decimal point. */
4667 e53toasc (x
, string
, ndigs
)
4668 const UEMUSHORT x
[];
4675 etoasc (w
, string
, ndigs
);
4678 /* Convert double extended value X to ASCII string STRING with NDIG digits
4679 after the decimal point. */
4682 e64toasc (x
, string
, ndigs
)
4683 const UEMUSHORT x
[];
4690 etoasc (w
, string
, ndigs
);
4693 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4694 after the decimal point. */
4697 e113toasc (x
, string
, ndigs
)
4698 const UEMUSHORT x
[];
4705 etoasc (w
, string
, ndigs
);
4709 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4710 the decimal point. */
4712 static char wstring
[80]; /* working storage for ASCII output */
4715 etoasc (x
, string
, ndigs
)
4716 const UEMUSHORT x
[];
4721 UEMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4722 const UEMUSHORT
*p
, *r
, *ten
;
4724 int i
, j
, k
, expon
, rndsav
;
4737 sprintf (wstring
, " NaN ");
4741 rndprc
= NBITS
; /* set to full precision */
4742 emov (x
, y
); /* retain external format */
4743 if (y
[NE
- 1] & 0x8000)
4746 y
[NE
- 1] &= 0x7fff;
4753 ten
= &etens
[NTEN
][0];
4755 /* Test for zero exponent */
4758 for (k
= 0; k
< NE
- 1; k
++)
4761 goto tnzro
; /* denormalized number */
4763 goto isone
; /* valid all zeros */
4767 /* Test for infinity. */
4768 if (y
[NE
- 1] == 0x7fff)
4771 sprintf (wstring
, " -Infinity ");
4773 sprintf (wstring
, " Infinity ");
4777 /* Test for exponent nonzero but significand denormalized.
4778 * This is an error condition.
4780 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4782 mtherr ("etoasc", DOMAIN
);
4783 sprintf (wstring
, "NaN");
4787 /* Compare to 1.0 */
4796 { /* Number is greater than 1 */
4797 /* Convert significand to an integer and strip trailing decimal zeros. */
4799 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4801 p
= &etens
[NTEN
- 4][0];
4807 for (j
= 0; j
< NE
- 1; j
++)
4820 /* Rescale from integer significand */
4821 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4823 /* Find power of 10 */
4827 /* An unordered compare result shouldn't happen here. */
4828 while (ecmp (ten
, u
) <= 0)
4830 if (ecmp (p
, u
) <= 0)
4843 { /* Number is less than 1.0 */
4844 /* Pad significand with trailing decimal zeros. */
4847 while ((y
[NE
- 2] & 0x8000) == 0)
4856 for (i
= 0; i
< NDEC
+ 1; i
++)
4858 if ((w
[NI
- 1] & 0x7) != 0)
4860 /* multiply by 10 */
4873 if (eone
[NE
- 1] <= u
[1])
4885 while (ecmp (eone
, w
) > 0)
4887 if (ecmp (p
, w
) >= 0)
4902 /* Find the first (leading) digit. */
4908 digit
= equot
[NI
- 1];
4909 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4917 digit
= equot
[NI
- 1];
4925 /* Examine number of digits requested by caller. */
4943 *s
++ = (char) digit
+ '0';
4946 /* Generate digits after the decimal point. */
4947 for (k
= 0; k
<= ndigs
; k
++)
4949 /* multiply current number by 10, without normalizing */
4956 *s
++ = (char) equot
[NI
- 1] + '0';
4958 digit
= equot
[NI
- 1];
4961 /* round off the ASCII string */
4964 /* Test for critical rounding case in ASCII output. */
4968 if (ecmp (t
, ezero
) != 0)
4969 goto roun
; /* round to nearest */
4971 if ((*(s
- 1) & 1) == 0)
4972 goto doexp
; /* round to even */
4975 /* Round up and propagate carry-outs */
4979 /* Carry out to most significant digit? */
4986 /* Most significant digit carries to 10? */
4994 /* Round up and carry out from less significant digits */
5006 sprintf (ss, "e+%d", expon);
5008 sprintf (ss, "e%d", expon);
5010 sprintf (ss
, "e%d", expon
);
5013 /* copy out the working string */
5016 while (*ss
== ' ') /* strip possible leading space */
5018 while ((*s
++ = *ss
++) != '\0')
5023 /* Convert ASCII string to floating point.
5025 Numeric input is a free format decimal number of any length, with
5026 or without decimal point. Entering E after the number followed by an
5027 integer number causes the second number to be interpreted as a power of
5028 10 to be multiplied by the first number (i.e., "scientific" notation). */
5030 /* Convert ASCII string S to single precision float value Y. */
5041 /* Convert ASCII string S to double precision value Y. */
5048 #if defined(DEC) || defined(IBM)
5060 /* Convert ASCII string S to double extended value Y. */
5070 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5071 /* Convert ASCII string S to 128-bit long double Y. */
5078 asctoeg (s
, y
, 113);
5082 /* Convert ASCII string S to e type Y. */
5089 asctoeg (s
, y
, NBITS
);
5092 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5093 of OPREC bits. BASE is 16 for C99 hexadecimal floating constants. */
5096 asctoeg (ss
, y
, oprec
)
5101 UEMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5102 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5103 int i
, k
, trail
, c
, rndsav
;
5106 char *sp
, *s
, *lstr
;
5109 /* Copy the input string. */
5110 lstr
= (char *) alloca (strlen (ss
) + 1);
5112 while (*ss
== ' ') /* skip leading spaces */
5116 while ((*sp
++ = *ss
++) != '\0')
5120 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5127 rndprc
= NBITS
; /* Set to full precision */
5140 if ((k
>= 0) && (k
< base
))
5142 /* Ignore leading zeros */
5143 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5145 /* Identify and strip trailing zeros after the decimal point. */
5146 if ((trail
== 0) && (decflg
!= 0))
5149 while (ISDIGIT (*sp
) || (base
== 16 && ISXDIGIT (*sp
)))
5151 /* Check for syntax error */
5153 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5154 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5156 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5158 goto unexpected_char_error
;
5167 /* If enough digits were given to more than fill up the yy register,
5168 continuing until overflow into the high guard word yy[2]
5169 guarantees that there will be a roundoff bit at the top
5170 of the low guard word after normalization. */
5177 nexp
+= 4; /* count digits after decimal point */
5179 eshup1 (yy
); /* multiply current number by 16 */
5187 nexp
+= 1; /* count digits after decimal point */
5189 eshup1 (yy
); /* multiply current number by 10 */
5195 /* Insert the current digit. */
5197 xt
[NI
- 2] = (UEMUSHORT
) k
;
5202 /* Mark any lost non-zero digit. */
5204 /* Count lost digits before the decimal point. */
5226 case '.': /* decimal point */
5228 goto unexpected_char_error
;
5234 goto unexpected_char_error
;
5239 goto unexpected_char_error
;
5252 unexpected_char_error
:
5256 mtherr ("asctoe", DOMAIN
);
5265 /* Exponent interpretation */
5267 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5268 for (k
= 0; k
< NI
; k
++)
5279 /* check for + or - */
5287 while (ISDIGIT (*s
))
5296 if ((exp
> MAXDECEXP
) && (base
== 10))
5300 yy
[E
] = 0x7fff; /* infinity */
5303 if ((exp
< MINDECEXP
) && (base
== 10))
5313 /* Base 16 hexadecimal floating constant. */
5314 if ((k
= enormlz (yy
)) > NBITS
)
5319 /* Adjust the exponent. NEXP is the number of hex digits,
5320 EXP is a power of 2. */
5321 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5331 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5332 while ((nexp
> 0) && (yy
[2] == 0))
5344 if ((k
= enormlz (yy
)) > NBITS
)
5349 lexp
= (EXONE
- 1 + NBITS
) - k
;
5350 emdnorm (yy
, lost
, 0, lexp
, 64);
5353 /* Convert to external format:
5355 Multiply by 10**nexp. If precision is 64 bits,
5356 the maximum relative error incurred in forming 10**n
5357 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5358 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5359 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5374 /* Punt. Can't handle this without 2 divides. */
5375 emovi (etens
[0], tt
);
5388 emul (etens
[i
], xt
, xt
);
5392 while (exp
<= MAXP
);
5411 /* Round and convert directly to the destination type */
5413 lexp
-= EXONE
- 0x3ff;
5415 else if (oprec
== 24 || oprec
== 32)
5416 lexp
-= (EXONE
- 0x7f);
5419 else if (oprec
== 24 || oprec
== 56)
5420 lexp
-= EXONE
- (0x41 << 2);
5422 else if (oprec
== 24)
5423 lexp
-= EXONE
- 0177;
5427 else if (oprec
== 56)
5428 lexp
-= EXONE
- 0201;
5431 emdnorm (yy
, lost
, 0, lexp
, 64);
5441 todec (yy
, y
); /* see etodec.c */
5446 toibm (yy
, y
, DFmode
);
5451 toc4x (yy
, y
, HFmode
);
5464 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5477 /* Return Y = largest integer not greater than X (truncated toward minus
5480 static const UEMUSHORT bmask
[] =
5503 const UEMUSHORT x
[];
5510 emov (x
, f
); /* leave in external format */
5511 expon
= (int) f
[NE
- 1];
5512 e
= (expon
& 0x7fff) - (EXONE
- 1);
5518 /* number of bits to clear out */
5530 /* clear the remaining bits */
5532 /* truncate negatives toward minus infinity */
5535 if ((UEMUSHORT
) expon
& (UEMUSHORT
) 0x8000)
5537 for (i
= 0; i
< NE
- 1; i
++)
5550 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5551 For example, 1.1 = 0.55 * 2^1. */
5555 const UEMUSHORT x
[];
5563 /* Handle denormalized numbers properly using long integer exponent. */
5564 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5572 *exp
= (int) (li
- 0x3ffe);
5576 /* Return e type Y = X * 2^PWR2. */
5580 const UEMUSHORT x
[];
5592 emdnorm (xi
, i
, i
, li
, !ROUND_TOWARDS_ZERO
);
5598 /* C = remainder after dividing B by A, all e type values.
5599 Least significant integer quotient bits left in EQUOT. */
5603 const UEMUSHORT a
[], b
[];
5606 UEMUSHORT den
[NI
], num
[NI
];
5610 || (ecmp (a
, ezero
) == 0)
5618 if (ecmp (a
, ezero
) == 0)
5620 mtherr ("eremain", SING
);
5626 eiremain (den
, num
);
5627 /* Sign of remainder = sign of quotient */
5636 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5637 remainder in NUM. */
5641 UEMUSHORT den
[], num
[];
5647 ld
-= enormlz (den
);
5649 ln
-= enormlz (num
);
5653 if (ecmpm (den
, num
) <= 0)
5665 emdnorm (num
, 0, 0, ln
, 0);
5668 /* Report an error condition CODE encountered in function NAME.
5670 Mnemonic Value Significance
5672 DOMAIN 1 argument domain error
5673 SING 2 function singularity
5674 OVERFLOW 3 overflow range error
5675 UNDERFLOW 4 underflow range error
5676 TLOSS 5 total loss of precision
5677 PLOSS 6 partial loss of precision
5678 INVALID 7 NaN - producing operation
5679 EDOM 33 Unix domain error code
5680 ERANGE 34 Unix range error code
5682 The order of appearance of the following messages is bound to the
5683 error codes defined above. */
5693 /* The string passed by the calling program is supposed to be the
5694 name of the function in which the error occurred.
5695 The code argument selects which error message string will be printed. */
5697 if (strcmp (name
, "esub") == 0)
5698 name
= "subtraction";
5699 else if (strcmp (name
, "ediv") == 0)
5701 else if (strcmp (name
, "emul") == 0)
5702 name
= "multiplication";
5703 else if (strcmp (name
, "enormlz") == 0)
5704 name
= "normalization";
5705 else if (strcmp (name
, "etoasc") == 0)
5706 name
= "conversion to text";
5707 else if (strcmp (name
, "asctoe") == 0)
5709 else if (strcmp (name
, "eremain") == 0)
5711 else if (strcmp (name
, "esqrt") == 0)
5712 name
= "square root";
5717 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5718 case SING
: warning ("%s: function singularity" , name
); break;
5719 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5720 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5721 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5722 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5723 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5728 /* Set global error message word */
5733 /* Convert DEC double precision D to e type E. */
5743 ecleaz (y
); /* start with a zero */
5744 p
= y
; /* point to our number */
5745 r
= *d
; /* get DEC exponent word */
5746 if (*d
& (unsigned int) 0x8000)
5747 *p
= 0xffff; /* fill in our sign */
5748 ++p
; /* bump pointer to our exponent word */
5749 r
&= 0x7fff; /* strip the sign bit */
5750 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5754 r
>>= 7; /* shift exponent word down 7 bits */
5755 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5756 /* add our e type exponent offset */
5757 *p
++ = r
; /* to form our exponent */
5759 r
= *d
++; /* now do the high order mantissa */
5760 r
&= 0177; /* strip off the DEC exponent and sign bits */
5761 r
|= 0200; /* the DEC understood high order mantissa bit */
5762 *p
++ = r
; /* put result in our high guard word */
5764 *p
++ = *d
++; /* fill in the rest of our mantissa */
5768 eshdn8 (y
); /* shift our mantissa down 8 bits */
5773 /* Convert e type X to DEC double precision D. */
5785 /* Adjust exponent for offsets. */
5786 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5787 /* Round off to nearest or even. */
5790 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5795 /* Convert exploded e-type X, that has already been rounded to
5796 56-bit precision, to DEC format double Y. */
5842 /* Convert IBM single/double precision to e type. */
5848 enum machine_mode mode
;
5853 ecleaz (y
); /* start with a zero */
5854 p
= y
; /* point to our number */
5855 r
= *d
; /* get IBM exponent word */
5856 if (*d
& (unsigned int) 0x8000)
5857 *p
= 0xffff; /* fill in our sign */
5858 ++p
; /* bump pointer to our exponent word */
5859 r
&= 0x7f00; /* strip the sign bit */
5860 r
>>= 6; /* shift exponent word down 6 bits */
5861 /* in fact shift by 8 right and 2 left */
5862 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5863 /* add our e type exponent offset */
5864 *p
++ = r
; /* to form our exponent */
5866 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5867 /* strip off the IBM exponent and sign bits */
5868 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5870 *p
++ = *d
++; /* fill in the rest of our mantissa */
5875 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5878 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5879 /* handle change in RADIX */
5885 /* Convert e type to IBM single/double precision. */
5891 enum machine_mode mode
;
5898 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5899 /* round off to nearest or even */
5902 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5904 toibm (xi
, d
, mode
);
5910 enum machine_mode mode
;
5963 /* Convert C4X single/double precision to e type. */
5969 enum machine_mode mode
;
5987 /* Short-circuit the zero case. */
5988 if ((dn
[0] == 0x8000)
5989 && (dn
[1] == 0x0000)
5990 && ((mode
== QFmode
) || ((dn
[2] == 0x0000) && (dn
[3] == 0x0000))))
6001 ecleaz (y
); /* start with a zero */
6002 r
= dn
[0]; /* get sign/exponent part */
6003 if (r
& (unsigned int) 0x0080)
6005 y
[0] = 0xffff; /* fill in our sign */
6011 r
>>= 8; /* Shift exponent word down 8 bits. */
6012 if (r
& 0x80) /* Make the exponent negative if it is. */
6013 r
= r
| (~0 & ~0xff);
6017 /* Now do the high order mantissa. We don't "or" on the high bit
6018 because it is 2 (not 1) and is handled a little differently
6020 y
[M
] = dn
[0] & 0x7f;
6023 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6025 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
6033 /* Now do the two's complement on the data. */
6035 carry
= 1; /* Initially add 1 for the two's complement. */
6036 for (i
=size
+ M
; i
> M
; i
--)
6038 if (carry
&& (y
[i
] == 0x0000))
6039 /* We overflowed into the next word, carry is the same. */
6040 y
[i
] = carry
? 0x0000 : 0xffff;
6043 /* No overflow, just invert and add carry. */
6044 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6059 /* Add our e type exponent offset to form our exponent. */
6063 /* Now do the high order mantissa strip off the exponent and sign
6064 bits and add the high 1 bit. */
6065 y
[M
] = (dn
[0] & 0x7f) | 0x80;
6068 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6070 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
6080 /* Convert e type to C4X single/double precision. */
6086 enum machine_mode mode
;
6094 /* Adjust exponent for offsets. */
6095 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6097 /* Round off to nearest or even. */
6099 rndprc
= mode
== QFmode
? 24 : 32;
6100 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
6102 toc4x (xi
, d
, mode
);
6108 enum machine_mode mode
;
6114 /* Short-circuit the zero case */
6115 if ((x
[0] == 0) /* Zero exponent and sign */
6117 && (x
[M
] == 0) /* The rest is for zero mantissa */
6119 /* Only check for double if necessary */
6120 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6122 /* We have a zero. Put it into the output and return. */
6135 /* Negative number require a two's complement conversion of the
6141 i
= ((int) x
[1]) - 0x7f;
6143 /* Now add 1 to the inverted data to do the two's complement. */
6152 x
[v
] = carry
? 0x0000 : 0xffff;
6155 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6161 /* The following is a special case. The C4X negative float requires
6162 a zero in the high bit (because the format is (2 - x) x 2^m), so
6163 if a one is in that bit, we have to shift left one to get rid
6164 of it. This only occurs if the number is -1 x 2^m. */
6165 if (x
[M
+1] & 0x8000)
6167 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6168 high sign bit and shift the exponent. */
6174 i
= ((int) x
[1]) - 0x7f;
6176 if ((i
< -128) || (i
> 127))
6184 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6185 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6193 y
[0] |= ((i
& 0xff) << 8);
6197 y
[0] |= x
[M
] & 0x7f;
6203 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6204 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6209 /* Output a binary NaN bit pattern in the target machine's format. */
6211 /* If special NaN bit patterns are required, define them in tm.h
6212 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6218 static const UEMUSHORT TFbignan
[8] =
6219 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6220 static const UEMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6228 static const UEMUSHORT XFbignan
[6] =
6229 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6230 static const UEMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6238 static const UEMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6239 static const UEMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6247 static const UEMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6248 static const UEMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6255 make_nan (nan
, sign
, mode
)
6258 enum machine_mode mode
;
6264 size
= GET_MODE_BITSIZE (mode
);
6265 if (LARGEST_EXPONENT_IS_NORMAL (size
))
6267 warning ("%d-bit floats cannot hold NaNs", size
);
6268 saturate (nan
, sign
, size
, 0);
6273 /* Possibly the `reserved operand' patterns on a VAX can be
6274 used like NaN's, but probably not in the same way as IEEE. */
6275 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6277 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
6279 if (REAL_WORDS_BIG_ENDIAN
)
6289 if (REAL_WORDS_BIG_ENDIAN
)
6297 if (REAL_WORDS_BIG_ENDIAN
)
6306 if (REAL_WORDS_BIG_ENDIAN
)
6316 if (REAL_WORDS_BIG_ENDIAN
)
6317 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6320 if (! REAL_WORDS_BIG_ENDIAN
)
6321 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6326 /* Create a saturation value for a SIZE-bit float, assuming that
6327 LARGEST_EXPONENT_IS_NORMAL (SIZE).
6329 If SIGN is true, fill X with the most negative value, otherwise fill
6330 it with the most positive value. WARN is true if the function should
6331 warn about overflow. */
6334 saturate (x
, sign
, size
, warn
)
6336 int sign
, size
, warn
;
6340 if (warn
&& extra_warnings
)
6341 warning ("value exceeds the range of a %d-bit float", size
);
6343 /* Create the most negative value. */
6344 for (i
= 0; i
< size
/ EMUSHORT_SIZE
; i
++)
6347 /* Make it positive, if necessary. */
6349 x
[REAL_WORDS_BIG_ENDIAN
? 0 : i
- 1] = 0x7fff;
6353 /* This is the inverse of the function `etarsingle' invoked by
6354 REAL_VALUE_TO_TARGET_SINGLE. */
6357 ereal_unto_float (f
)
6364 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6365 This is the inverse operation to what the function `endian' does. */
6366 if (REAL_WORDS_BIG_ENDIAN
)
6368 s
[0] = (UEMUSHORT
) (f
>> 16);
6369 s
[1] = (UEMUSHORT
) f
;
6373 s
[0] = (UEMUSHORT
) f
;
6374 s
[1] = (UEMUSHORT
) (f
>> 16);
6376 /* Convert and promote the target float to E-type. */
6378 /* Output E-type to REAL_VALUE_TYPE. */
6384 /* This is the inverse of the function `etardouble' invoked by
6385 REAL_VALUE_TO_TARGET_DOUBLE. */
6388 ereal_unto_double (d
)
6395 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6396 if (REAL_WORDS_BIG_ENDIAN
)
6398 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6399 s
[1] = (UEMUSHORT
) d
[0];
6400 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6401 s
[3] = (UEMUSHORT
) d
[1];
6405 /* Target float words are little-endian. */
6406 s
[0] = (UEMUSHORT
) d
[0];
6407 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6408 s
[2] = (UEMUSHORT
) d
[1];
6409 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6411 /* Convert target double to E-type. */
6413 /* Output E-type to REAL_VALUE_TYPE. */
6419 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6420 This is somewhat like ereal_unto_float, but the input types
6421 for these are different. */
6424 ereal_from_float (f
)
6431 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6432 This is the inverse operation to what the function `endian' does. */
6433 if (REAL_WORDS_BIG_ENDIAN
)
6435 s
[0] = (UEMUSHORT
) (f
>> 16);
6436 s
[1] = (UEMUSHORT
) f
;
6440 s
[0] = (UEMUSHORT
) f
;
6441 s
[1] = (UEMUSHORT
) (f
>> 16);
6443 /* Convert and promote the target float to E-type. */
6445 /* Output E-type to REAL_VALUE_TYPE. */
6451 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6452 This is somewhat like ereal_unto_double, but the input types
6453 for these are different.
6455 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6456 data format, with no holes in the bit packing. The first element
6457 of the input array holds the bits that would come first in the
6458 target computer's memory. */
6461 ereal_from_double (d
)
6468 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6469 if (REAL_WORDS_BIG_ENDIAN
)
6471 #if HOST_BITS_PER_WIDE_INT == 32
6472 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6473 s
[1] = (UEMUSHORT
) d
[0];
6474 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6475 s
[3] = (UEMUSHORT
) d
[1];
6477 /* In this case the entire target double is contained in the
6478 first array element. The second element of the input is
6480 s
[0] = (UEMUSHORT
) (d
[0] >> 48);
6481 s
[1] = (UEMUSHORT
) (d
[0] >> 32);
6482 s
[2] = (UEMUSHORT
) (d
[0] >> 16);
6483 s
[3] = (UEMUSHORT
) d
[0];
6488 /* Target float words are little-endian. */
6489 s
[0] = (UEMUSHORT
) d
[0];
6490 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6491 #if HOST_BITS_PER_WIDE_INT == 32
6492 s
[2] = (UEMUSHORT
) d
[1];
6493 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6495 s
[2] = (UEMUSHORT
) (d
[0] >> 32);
6496 s
[3] = (UEMUSHORT
) (d
[0] >> 48);
6499 /* Convert target double to E-type. */
6501 /* Output E-type to REAL_VALUE_TYPE. */
6508 /* Convert target computer unsigned 64-bit integer to e-type.
6509 The endian-ness of DImode follows the convention for integers,
6510 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6514 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6521 if (WORDS_BIG_ENDIAN
)
6523 for (k
= M
; k
< M
+ 4; k
++)
6528 for (k
= M
+ 3; k
>= M
; k
--)
6531 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6532 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6533 ecleaz (yi
); /* it was zero */
6535 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6539 /* Convert target computer signed 64-bit integer to e-type. */
6543 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6546 unsigned EMULONG acc
;
6552 if (WORDS_BIG_ENDIAN
)
6554 for (k
= M
; k
< M
+ 4; k
++)
6559 for (k
= M
+ 3; k
>= M
; k
--)
6562 /* Take absolute value */
6568 for (k
= M
+ 3; k
>= M
; k
--)
6570 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6577 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6578 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6579 ecleaz (yi
); /* it was zero */
6581 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6588 /* Convert e-type to unsigned 64-bit int. */
6604 k
= (int) xi
[E
] - (EXONE
- 1);
6607 for (j
= 0; j
< 4; j
++)
6613 for (j
= 0; j
< 4; j
++)
6616 warning ("overflow on truncation to integer");
6621 /* Shift more than 16 bits: first shift up k-16 mod 16,
6622 then shift up by 16's. */
6623 j
= k
- ((k
>> 4) << 4);
6627 if (WORDS_BIG_ENDIAN
)
6638 if (WORDS_BIG_ENDIAN
)
6643 while ((k
-= 16) > 0);
6647 /* shift not more than 16 bits */
6652 if (WORDS_BIG_ENDIAN
)
6671 /* Convert e-type to signed 64-bit int. */
6678 unsigned EMULONG acc
;
6685 k
= (int) xi
[E
] - (EXONE
- 1);
6688 for (j
= 0; j
< 4; j
++)
6694 for (j
= 0; j
< 4; j
++)
6697 warning ("overflow on truncation to integer");
6703 /* Shift more than 16 bits: first shift up k-16 mod 16,
6704 then shift up by 16's. */
6705 j
= k
- ((k
>> 4) << 4);
6709 if (WORDS_BIG_ENDIAN
)
6720 if (WORDS_BIG_ENDIAN
)
6725 while ((k
-= 16) > 0);
6729 /* shift not more than 16 bits */
6732 if (WORDS_BIG_ENDIAN
)
6748 /* Negate if negative */
6752 if (WORDS_BIG_ENDIAN
)
6754 for (k
= 0; k
< 4; k
++)
6756 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6757 if (WORDS_BIG_ENDIAN
)
6769 /* Longhand square root routine. */
6772 static int esqinited
= 0;
6773 static unsigned short sqrndbit
[NI
];
6780 UEMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6782 int i
, j
, k
, n
, nlups
;
6787 sqrndbit
[NI
- 2] = 1;
6790 /* Check for arg <= 0 */
6791 i
= ecmp (x
, ezero
);
6796 mtherr ("esqrt", DOMAIN
);
6812 /* Bring in the arg and renormalize if it is denormal. */
6814 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6818 /* Divide exponent by 2 */
6820 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6822 /* Adjust if exponent odd */
6832 n
= 8; /* get 8 bits of result per inner loop */
6838 /* bring in next word of arg */
6840 num
[NI
- 1] = xx
[j
+ 3];
6841 /* Do additional bit on last outer loop, for roundoff. */
6844 for (i
= 0; i
< n
; i
++)
6846 /* Next 2 bits of arg */
6849 /* Shift up answer */
6851 /* Make trial divisor */
6852 for (k
= 0; k
< NI
; k
++)
6855 eaddm (sqrndbit
, temp
);
6856 /* Subtract and insert answer bit if it goes in */
6857 if (ecmpm (temp
, num
) <= 0)
6867 /* Adjust for extra, roundoff loop done. */
6868 exp
+= (NBITS
- 1) - rndprc
;
6870 /* Sticky bit = 1 if the remainder is nonzero. */
6872 for (i
= 3; i
< NI
; i
++)
6875 /* Renormalize and round off. */
6876 emdnorm (sq
, k
, 0, exp
, !ROUND_TOWARDS_ZERO
);
6881 /* Return the binary precision of the significand for a given
6882 floating point mode. The mode can hold an integer value
6883 that many bits wide, without losing any bits. */
6886 significand_size (mode
)
6887 enum machine_mode mode
;
6890 /* Don't test the modes, but their sizes, lest this
6891 code won't work for BITS_PER_UNIT != 8 . */
6893 switch (GET_MODE_BITSIZE (mode
))
6897 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6904 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6907 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6910 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6913 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6926 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)