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
31 /* To enable support of XFmode extended real floating point, define
32 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
34 Machine files (tm.h etc) must not contain any code
35 that tries to use host floating point arithmetic to convert
36 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
37 etc. In cross-compile situations a REAL_VALUE_TYPE may not
38 be intelligible to the host computer's native arithmetic.
40 The first part of this file interfaces gcc to a floating point
41 arithmetic suite that was not written with gcc in mind. Avoid
42 changing the low-level arithmetic routines unless you have suitable
43 test programs available. A special version of the PARANOIA floating
44 point arithmetic tester, modified for this purpose, can be found on
45 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
46 XFmode and TFmode transcendental functions, can be obtained by ftp from
47 netlib.att.com: netlib/cephes. */
49 /* Type of computer arithmetic.
50 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
52 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
53 to big-endian IEEE floating-point data structure. This definition
54 should work in SFmode `float' type and DFmode `double' type on
55 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
56 has been defined to be 96, then IEEE also invokes the particular
57 XFmode (`long double' type) data structure used by the Motorola
58 680x0 series processors.
60 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
61 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
62 has been defined to be 96, then IEEE also invokes the particular
63 XFmode `long double' data structure used by the Intel 80x86 series
66 `DEC' refers specifically to the Digital Equipment Corp PDP-11
67 and VAX floating point data structure. This model currently
68 supports no type wider than DFmode.
70 `IBM' refers specifically to the IBM System/370 and compatible
71 floating point data structure. This model currently supports
72 no type wider than DFmode. The IBM conversions were contributed by
73 frank@atom.ansto.gov.au (Frank Crawford).
75 `C4X' refers specifically to the floating point format used on
76 Texas Instruments TMS320C3x and TMS320C4x digital signal
77 processors. This supports QFmode (32-bit float, double) and HFmode
78 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
79 floats, C4x floats are not rounded to be even. The C4x conversions
80 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
81 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
83 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
84 then `long double' and `double' are both implemented, but they
87 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
88 and may deactivate XFmode since `long double' is used to refer
89 to both modes. Defining INTEL_EXTENDED_IEEE_FORMAT to non-zero
90 at the same time enables 80387-style 80-bit floats in a 128-bit
91 padded image, as seen on IA-64.
93 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
94 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
95 separate the floating point unit's endian-ness from that of
96 the integer addressing. This permits one to define a big-endian
97 FPU on a little-endian machine (e.g., ARM). An extension to
98 BYTES_BIG_ENDIAN may be required for some machines in the future.
99 These optional macros may be defined in tm.h. In real.h, they
100 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
101 them for any normal host or target machine on which the floats
102 and the integers have the same endian-ness. */
105 /* The following converts gcc macros into the ones used by this file. */
107 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
108 /* PDP-11, Pro350, VAX: */
110 #else /* it's not VAX */
111 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
112 /* IBM System/370 style */
114 #else /* it's also not an IBM */
115 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
116 /* TMS320C3x/C4x style */
118 #else /* it's also not a C4X */
119 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
121 #else /* it's not IEEE either */
122 /* UNKnown arithmetic. We don't support this and can't go on. */
123 unknown arithmetic type
125 #endif /* not IEEE */
130 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
132 /* Make sure that the endianness is correct for IBM and DEC. */
134 #undef LARGEST_EXPONENT_IS_NORMAL
135 #define LARGEST_EXPONENT_IS_NORMAL(x) 1
136 #undef REAL_WORDS_BIG_ENDIAN
137 /* Strangely enough, DEC float most closely resembles big endian IEEE */
138 #define REAL_WORDS_BIG_ENDIAN 1
139 /* ... but the halfwords are reversed from IEEE big endian. */
140 #ifndef VAX_HALFWORD_ORDER
141 #define VAX_HALFWORD_ORDER 1
144 #if defined(IBM) && !REAL_WORDS_BIG_ENDIAN
145 #error "Little-endian representations are not supported for IBM."
149 #if defined(DEC) && !defined (TARGET_G_FLOAT)
150 #define TARGET_G_FLOAT 0
153 #ifndef VAX_HALFWORD_ORDER
154 #define VAX_HALFWORD_ORDER 0
157 /* Define INFINITY for support of infinity.
158 Define NANS for support of Not-a-Number's (NaN's). */
159 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
164 /* Support of NaNs requires support of infinity. */
171 /* Find a host integer type that is at least 16 bits wide,
172 and another type at least twice whatever that size is. */
174 #if HOST_BITS_PER_CHAR >= 16
175 #define EMUSHORT char
176 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
177 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
179 #if HOST_BITS_PER_SHORT >= 16
180 #define EMUSHORT short
181 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
182 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
184 #if HOST_BITS_PER_INT >= 16
186 #define EMUSHORT_SIZE HOST_BITS_PER_INT
187 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
189 #if HOST_BITS_PER_LONG >= 16
190 #define EMUSHORT long
191 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
192 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
194 #error "You will have to modify this program to have a smaller unit size."
200 /* If no 16-bit type has been found and the compiler is GCC, try HImode. */
201 #if defined(__GNUC__) && EMUSHORT_SIZE != 16
202 typedef int HItype
__attribute__ ((mode (HI
)));
203 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
207 #define EMUSHORT HItype
208 #define UEMUSHORT UHItype
209 #define EMUSHORT_SIZE 16
210 #define EMULONG_SIZE 32
212 #define UEMUSHORT unsigned EMUSHORT
215 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
216 #define EMULONG short
218 #if HOST_BITS_PER_INT >= EMULONG_SIZE
221 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
224 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
225 #define EMULONG long long int
227 #error "You will have to modify this program to have a smaller unit size."
233 #if EMUSHORT_SIZE != 16
234 #error "The host interface doesn't work if no 16-bit size exists."
237 /* Calculate the size of the generic "e" type. This always has
238 identical in-memory size to REAL_VALUE_TYPE. The sizes are supposed
239 to be the same as well, but when REAL_VALUE_TYPE_SIZE is not evenly
240 divisible by HOST_BITS_PER_WIDE_INT we have some padding in
242 There are only two supported sizes: ten and six 16-bit words (160
245 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !INTEL_EXTENDED_IEEE_FORMAT
248 # define MAXDECEXP 4932
249 # define MINDECEXP -4977
252 # define MAXDECEXP 4932
253 # define MINDECEXP -4956
256 /* Fail compilation if 2*NE is not the appropriate size.
257 If HOST_BITS_PER_WIDE_INT is 64, we're going to have padding
258 at the end of the array, because neither 96 nor 160 is
259 evenly divisible by 64. */
260 struct compile_test_dummy
{
261 char twice_NE_must_equal_sizeof_REAL_VALUE_TYPE
262 [(sizeof (REAL_VALUE_TYPE
) >= 2*NE
) ? 1 : -1];
265 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
266 In GET_REAL and PUT_REAL, r and e are pointers.
267 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
268 in memory, with no holes. */
269 #define GET_REAL(r, e) memcpy ((e), (r), 2*NE)
270 #define PUT_REAL(e, r) \
272 memcpy (r, e, 2*NE); \
273 if (2*NE < sizeof (*r)) \
274 memset ((char *) (r) + 2*NE, 0, sizeof (*r) - 2*NE); \
277 /* Number of 16 bit words in internal format */
280 /* Array offset to exponent */
283 /* Array offset to high guard word */
286 /* Number of bits of precision */
287 #define NBITS ((NI-4)*16)
289 /* Maximum number of decimal digits in ASCII conversion
292 #define NDEC (NBITS*8/27)
294 /* The exponent of 1.0 */
295 #define EXONE (0x3fff)
297 #if defined(HOST_EBCDIC)
298 /* bit 8 is significant in EBCDIC */
299 #define CHARMASK 0xff
301 #define CHARMASK 0x7f
304 /* Information about the various IEEE precisions. At the moment, we only
305 support exponents of 15 bits or less. */
311 /* Size of the exponent in bits. */
314 /* Overall size of the value in bits. */
317 /* Mode used for representing the value. */
318 enum machine_mode mode
;
320 /* Exponent adjustment for offsets. */
325 /* IEEE float (24 bits). */
326 static const struct ieee_format ieee_24
=
335 /* IEEE double (53 bits). */
336 static const struct ieee_format ieee_53
=
345 /* IEEE extended double (64 bits). */
346 static const struct ieee_format ieee_64
=
355 /* IEEE long double (113 bits). */
356 static const struct ieee_format ieee_113
=
367 /* DEC F float (24 bits). */
368 static const struct ieee_format dec_f
=
377 /* DEC D float (56 bits). */
378 static const struct ieee_format dec_d
=
387 /* DEC G float (53 bits). */
388 static const struct ieee_format dec_g
=
397 /* DEC H float (113 bits). (not yet used) */
398 static const struct ieee_format dec_h
=
408 extern int extra_warnings
;
409 extern const UEMUSHORT ezero
[NE
], ehalf
[NE
], eone
[NE
], etwo
[NE
];
410 extern const UEMUSHORT elog2
[NE
], esqrt2
[NE
];
412 static void endian
PARAMS ((const UEMUSHORT
*, long *,
414 static void eclear
PARAMS ((UEMUSHORT
*));
415 static void emov
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
417 static void eabs
PARAMS ((UEMUSHORT
*));
419 static void eneg
PARAMS ((UEMUSHORT
*));
420 static int eisneg
PARAMS ((const UEMUSHORT
*));
421 static int eisinf
PARAMS ((const UEMUSHORT
*));
422 static int eisnan
PARAMS ((const UEMUSHORT
*));
423 static void einfin
PARAMS ((UEMUSHORT
*));
425 static void enan
PARAMS ((UEMUSHORT
*, int));
426 static void einan
PARAMS ((UEMUSHORT
*));
427 static int eiisnan
PARAMS ((const UEMUSHORT
*));
428 static void make_nan
PARAMS ((UEMUSHORT
*, int, enum machine_mode
));
430 static int eiisneg
PARAMS ((const UEMUSHORT
*));
431 static void saturate
PARAMS ((UEMUSHORT
*, int, int, int));
432 static void emovi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
433 static void emovo
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
434 static void ecleaz
PARAMS ((UEMUSHORT
*));
435 static void ecleazs
PARAMS ((UEMUSHORT
*));
436 static void emovz
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
438 static void eiinfin
PARAMS ((UEMUSHORT
*));
441 static int eiisinf
PARAMS ((const UEMUSHORT
*));
443 static int ecmpm
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
444 static void eshdn1
PARAMS ((UEMUSHORT
*));
445 static void eshup1
PARAMS ((UEMUSHORT
*));
446 static void eshdn8
PARAMS ((UEMUSHORT
*));
447 static void eshup8
PARAMS ((UEMUSHORT
*));
448 static void eshup6
PARAMS ((UEMUSHORT
*));
449 static void eshdn6
PARAMS ((UEMUSHORT
*));
450 static void eaddm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));\f
451 static void esubm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
452 static void m16m
PARAMS ((unsigned int, const UEMUSHORT
*, UEMUSHORT
*));
453 static int edivm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
454 static int emulm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
455 static void emdnorm
PARAMS ((UEMUSHORT
*, int, int, EMULONG
, int));
456 static void esub
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
458 static void eadd
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
460 static void eadd1
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
462 static void ediv
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
464 static void emul
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
466 static void e53toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
467 static void e64toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
468 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
469 static void e113toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
471 static void e24toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
472 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
473 static void etoe113
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
474 static void toe113
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
476 static void etoe64
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
477 static void toe64
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
478 static void etoe53
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
479 static void toe53
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
480 static void etoe24
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
481 static void toe24
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
482 static void ieeetoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
483 const struct ieee_format
*));
484 static void etoieee
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
485 const struct ieee_format
*));
486 static void toieee
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
487 const struct ieee_format
*));
488 static int ecmp
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
490 static void eround
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
492 static void ltoe
PARAMS ((const HOST_WIDE_INT
*, UEMUSHORT
*));
493 static void ultoe
PARAMS ((const unsigned HOST_WIDE_INT
*, UEMUSHORT
*));
494 static void eifrac
PARAMS ((const UEMUSHORT
*, HOST_WIDE_INT
*,
496 static void euifrac
PARAMS ((const UEMUSHORT
*, unsigned HOST_WIDE_INT
*,
498 static int eshift
PARAMS ((UEMUSHORT
*, int));
499 static int enormlz
PARAMS ((UEMUSHORT
*));
501 static void e24toasc
PARAMS ((const UEMUSHORT
*, char *, int));
502 static void e53toasc
PARAMS ((const UEMUSHORT
*, char *, int));
503 static void e64toasc
PARAMS ((const UEMUSHORT
*, char *, int));
504 static void e113toasc
PARAMS ((const UEMUSHORT
*, char *, int));
506 static void etoasc
PARAMS ((const UEMUSHORT
*, char *, int));
507 static void asctoe24
PARAMS ((const char *, UEMUSHORT
*));
508 static void asctoe53
PARAMS ((const char *, UEMUSHORT
*));
509 static void asctoe64
PARAMS ((const char *, UEMUSHORT
*));
510 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
511 static void asctoe113
PARAMS ((const char *, UEMUSHORT
*));
513 static void asctoe
PARAMS ((const char *, UEMUSHORT
*));
514 static void asctoeg
PARAMS ((const char *, UEMUSHORT
*, int));
515 static void efloor
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
517 static void efrexp
PARAMS ((const UEMUSHORT
*, int *,
520 static void eldexp
PARAMS ((const UEMUSHORT
*, int, UEMUSHORT
*));
522 static void eremain
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
525 static void eiremain
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
526 static void mtherr
PARAMS ((const char *, int));
528 static void dectoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
529 static void etodec
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
530 static void todec
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
533 static void ibmtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
535 static void etoibm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
537 static void toibm
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
541 static void c4xtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
543 static void etoc4x
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
545 static void toc4x
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
549 static void uditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
550 static void ditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
551 static void etoudi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
552 static void etodi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
553 static void esqrt
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
556 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
557 swapping ends if required, into output array of longs. The
558 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
564 enum machine_mode mode
;
568 if (REAL_WORDS_BIG_ENDIAN
&& !VAX_HALFWORD_ORDER
)
573 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
574 /* Swap halfwords in the fourth long. */
575 th
= (unsigned long) e
[6] & 0xffff;
576 t
= (unsigned long) e
[7] & 0xffff;
585 /* Swap halfwords in the third long. */
586 th
= (unsigned long) e
[4] & 0xffff;
587 t
= (unsigned long) e
[5] & 0xffff;
593 /* Swap halfwords in the second word. */
594 th
= (unsigned long) e
[2] & 0xffff;
595 t
= (unsigned long) e
[3] & 0xffff;
602 /* Swap halfwords in the first word. */
603 th
= (unsigned long) e
[0] & 0xffff;
604 t
= (unsigned long) e
[1] & 0xffff;
615 /* Pack the output array without swapping. */
620 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
621 /* Pack the fourth long. */
622 th
= (unsigned long) e
[7] & 0xffff;
623 t
= (unsigned long) e
[6] & 0xffff;
632 /* Pack the third long.
633 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
635 th
= (unsigned long) e
[5] & 0xffff;
636 t
= (unsigned long) e
[4] & 0xffff;
642 /* Pack the second long */
643 th
= (unsigned long) e
[3] & 0xffff;
644 t
= (unsigned long) e
[2] & 0xffff;
651 /* Pack the first long */
652 th
= (unsigned long) e
[1] & 0xffff;
653 t
= (unsigned long) e
[0] & 0xffff;
665 /* This is the implementation of the REAL_ARITHMETIC macro. */
668 earith (value
, icode
, r1
, r2
)
669 REAL_VALUE_TYPE
*value
;
674 UEMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
680 /* Return NaN input back to the caller. */
683 PUT_REAL (d1
, value
);
688 PUT_REAL (d2
, value
);
692 code
= (enum tree_code
) icode
;
700 esub (d2
, d1
, v
); /* d1 - d2 */
709 if (ecmp (d2
, ezero
) == 0)
712 ediv (d2
, d1
, v
); /* d1/d2 */
715 case MIN_EXPR
: /* min (d1,d2) */
716 if (ecmp (d1
, d2
) < 0)
722 case MAX_EXPR
: /* max (d1,d2) */
723 if (ecmp (d1
, d2
) > 0)
736 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
737 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
743 UEMUSHORT f
[NE
], g
[NE
];
759 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
760 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
766 UEMUSHORT f
[NE
], g
[NE
];
768 unsigned HOST_WIDE_INT l
;
782 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
783 string to binary, rounding off as indicated by the machine_mode argument.
784 Then it promotes the rounded value to REAL_VALUE_TYPE. */
791 UEMUSHORT tem
[NE
], e
[NE
];
817 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
837 /* Expansion of REAL_NEGATE. */
853 /* Round real toward zero to HOST_WIDE_INT;
854 implements REAL_VALUE_FIX (x). */
860 UEMUSHORT f
[NE
], g
[NE
];
867 warning ("conversion from NaN to int");
875 /* Round real toward zero to unsigned HOST_WIDE_INT
876 implements REAL_VALUE_UNSIGNED_FIX (x).
877 Negative input returns zero. */
879 unsigned HOST_WIDE_INT
883 UEMUSHORT f
[NE
], g
[NE
];
884 unsigned HOST_WIDE_INT l
;
890 warning ("conversion from NaN to unsigned int");
899 /* REAL_VALUE_FROM_INT macro. */
902 ereal_from_int (d
, i
, j
, mode
)
905 enum machine_mode mode
;
907 UEMUSHORT df
[NE
], dg
[NE
];
908 HOST_WIDE_INT low
, high
;
911 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
918 /* complement and add 1 */
925 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
926 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
928 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
933 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
934 Avoid double-rounding errors later by rounding off now from the
935 extra-wide internal format to the requested precision. */
936 switch (GET_MODE_BITSIZE (mode
))
954 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
971 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
974 ereal_from_uint (d
, i
, j
, mode
)
976 unsigned HOST_WIDE_INT i
, j
;
977 enum machine_mode mode
;
979 UEMUSHORT df
[NE
], dg
[NE
];
980 unsigned HOST_WIDE_INT low
, high
;
982 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
986 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
992 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
993 Avoid double-rounding errors later by rounding off now from the
994 extra-wide internal format to the requested precision. */
995 switch (GET_MODE_BITSIZE (mode
))
1013 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
1030 /* REAL_VALUE_TO_INT macro. */
1033 ereal_to_int (low
, high
, rr
)
1034 HOST_WIDE_INT
*low
, *high
;
1037 UEMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
1044 warning ("conversion from NaN to int");
1050 /* convert positive value */
1057 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
1058 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
1059 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
1060 emul (df
, dh
, dg
); /* fractional part is the low word */
1061 euifrac (dg
, (unsigned HOST_WIDE_INT
*) low
, dh
);
1064 /* complement and add 1 */
1074 /* REAL_VALUE_LDEXP macro. */
1081 UEMUSHORT e
[NE
], y
[NE
];
1094 /* Check for infinity in a REAL_VALUE_TYPE. */
1098 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1104 return (eisinf (e
));
1110 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1114 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1120 return (eisnan (e
));
1127 /* Check for a negative REAL_VALUE_TYPE number.
1128 This just checks the sign bit, so that -0 counts as negative. */
1134 return ereal_isneg (x
);
1137 /* Expansion of REAL_VALUE_TRUNCATE.
1138 The result is in floating point, rounded to nearest or even. */
1141 real_value_truncate (mode
, arg
)
1142 enum machine_mode mode
;
1143 REAL_VALUE_TYPE arg
;
1145 UEMUSHORT e
[NE
], t
[NE
];
1157 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
1194 /* If an unsupported type was requested, presume that
1195 the machine files know something useful to do with
1196 the unmodified value. */
1205 /* Return true if ARG can be represented exactly in MODE. */
1208 exact_real_truncate (mode
, arg
)
1209 enum machine_mode mode
;
1210 REAL_VALUE_TYPE
*arg
;
1212 REAL_VALUE_TYPE trunc
;
1214 if (target_isnan (*arg
))
1217 trunc
= real_value_truncate (mode
, *arg
);
1218 return ereal_cmp (*arg
, trunc
) == 0;
1221 /* Try to change R into its exact multiplicative inverse in machine mode
1222 MODE. Return nonzero function value if successful. */
1225 exact_real_inverse (mode
, r
)
1226 enum machine_mode mode
;
1229 UEMUSHORT e
[NE
], einv
[NE
];
1230 REAL_VALUE_TYPE rinv
;
1235 /* Test for input in range. Don't transform IEEE special values. */
1236 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1239 /* Test for a power of 2: all significand bits zero except the MSB.
1240 We are assuming the target has binary (or hex) arithmetic. */
1241 if (e
[NE
- 2] != 0x8000)
1244 for (i
= 0; i
< NE
- 2; i
++)
1250 /* Compute the inverse and truncate it to the required mode. */
1251 ediv (e
, eone
, einv
);
1252 PUT_REAL (einv
, &rinv
);
1253 rinv
= real_value_truncate (mode
, rinv
);
1255 #ifdef CHECK_FLOAT_VALUE
1256 /* This check is not redundant. It may, for example, flush
1257 a supposedly IEEE denormal value to zero. */
1259 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1262 GET_REAL (&rinv
, einv
);
1264 /* Check the bits again, because the truncation might have
1265 generated an arbitrary saturation value on overflow. */
1266 if (einv
[NE
- 2] != 0x8000)
1269 for (i
= 0; i
< NE
- 2; i
++)
1275 /* Fail if the computed inverse is out of range. */
1276 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1279 /* Output the reciprocal and return success flag. */
1284 /* Used for debugging--print the value of R in human-readable format
1293 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1294 fprintf (stderr
, "%s", dstr
);
1298 /* The following routines convert REAL_VALUE_TYPE to the various floating
1299 point formats that are meaningful to supported computers.
1301 The results are returned in 32-bit pieces, each piece stored in a `long'.
1302 This is so they can be printed by statements like
1304 fprintf (file, "%lx, %lx", L[0], L[1]);
1306 that will work on both narrow- and wide-word host computers. */
1308 /* Convert R to a 128-bit long double precision value. The output array L
1309 contains four 32-bit pieces of the result, in the order they would appear
1320 #if INTEL_EXTENDED_IEEE_FORMAT == 0
1325 endian (e
, l
, TFmode
);
1328 /* Convert R to a double extended precision value. The output array L
1329 contains three 32-bit pieces of the result, in the order they would
1330 appear in memory. */
1341 endian (e
, l
, XFmode
);
1344 /* Convert R to a double precision value. The output array L contains two
1345 32-bit pieces of the result, in the order they would appear in memory. */
1356 endian (e
, l
, DFmode
);
1359 /* Convert R to a single precision float value stored in the least-significant
1360 bits of a `long'. */
1371 endian (e
, &l
, SFmode
);
1375 /* Convert X to a decimal ASCII string S for output to an assembly
1376 language file. Note, there is no standard way to spell infinity or
1377 a NaN, so these values may require special treatment in the tm.h
1381 ereal_to_decimal (x
, s
)
1391 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1392 or -2 if either is a NaN. */
1396 REAL_VALUE_TYPE x
, y
;
1398 UEMUSHORT ex
[NE
], ey
[NE
];
1402 return (ecmp (ex
, ey
));
1405 /* Return 1 if the sign bit of X is set, else return 0. */
1414 return (eisneg (ex
));
1419 Extended precision IEEE binary floating point arithmetic routines
1421 Numbers are stored in C language as arrays of 16-bit unsigned
1422 short integers. The arguments of the routines are pointers to
1425 External e type data structure, similar to Intel 8087 chip
1426 temporary real format but possibly with a larger significand:
1428 NE-1 significand words (least significant word first,
1429 most significant bit is normally set)
1430 exponent (value = EXONE for 1.0,
1431 top bit is the sign)
1434 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1436 ei[0] sign word (0 for positive, 0xffff for negative)
1437 ei[1] biased exponent (value = EXONE for the number 1.0)
1438 ei[2] high guard word (always zero after normalization)
1440 to ei[NI-2] significand (NI-4 significand words,
1441 most significant word first,
1442 most significant bit is set)
1443 ei[NI-1] low guard word (0x8000 bit is rounding place)
1447 Routines for external format e-type numbers
1449 asctoe (string, e) ASCII string to extended double e type
1450 asctoe64 (string, &d) ASCII string to long double
1451 asctoe53 (string, &d) ASCII string to double
1452 asctoe24 (string, &f) ASCII string to single
1453 asctoeg (string, e, prec) ASCII string to specified precision
1454 e24toe (&f, e) IEEE single precision to e type
1455 e53toe (&d, e) IEEE double precision to e type
1456 e64toe (&d, e) IEEE long double precision to e type
1457 e113toe (&d, e) 128-bit long double precision to e type
1459 eabs (e) absolute value
1461 eadd (a, b, c) c = b + a
1463 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1464 -1 if a < b, -2 if either a or b is a NaN.
1465 ediv (a, b, c) c = b / a
1466 efloor (a, b) truncate to integer, toward -infinity
1467 efrexp (a, exp, s) extract exponent and significand
1468 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1469 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1470 einfin (e) set e to infinity, leaving its sign alone
1471 eldexp (a, n, b) multiply by 2**n
1473 emul (a, b, c) c = b * a
1476 eround (a, b) b = nearest integer value to a
1478 esub (a, b, c) c = b - a
1480 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1481 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1482 e64toasc (&d, str, n) 80-bit long double to ASCII string
1483 e113toasc (&d, str, n) 128-bit long double to ASCII string
1485 etoasc (e, str, n) e to ASCII string, n digits after decimal
1486 etoe24 (e, &f) convert e type to IEEE single precision
1487 etoe53 (e, &d) convert e type to IEEE double precision
1488 etoe64 (e, &d) convert e type to IEEE long double precision
1489 ltoe (&l, e) HOST_WIDE_INT to e type
1490 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1491 eisneg (e) 1 if sign bit of e != 0, else 0
1492 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1493 or is infinite (IEEE)
1494 eisnan (e) 1 if e is a NaN
1497 Routines for internal format exploded e-type numbers
1499 eaddm (ai, bi) add significands, bi = bi + ai
1501 ecleazs (ei) set ei = 0 but leave its sign alone
1502 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1503 edivm (ai, bi) divide significands, bi = bi / ai
1504 emdnorm (ai,l,s,exp) normalize and round off
1505 emovi (a, ai) convert external a to internal ai
1506 emovo (ai, a) convert internal ai to external a
1507 emovz (ai, bi) bi = ai, low guard word of bi = 0
1508 emulm (ai, bi) multiply significands, bi = bi * ai
1509 enormlz (ei) left-justify the significand
1510 eshdn1 (ai) shift significand and guards down 1 bit
1511 eshdn8 (ai) shift down 8 bits
1512 eshdn6 (ai) shift down 16 bits
1513 eshift (ai, n) shift ai n bits up (or down if n < 0)
1514 eshup1 (ai) shift significand and guards up 1 bit
1515 eshup8 (ai) shift up 8 bits
1516 eshup6 (ai) shift up 16 bits
1517 esubm (ai, bi) subtract significands, bi = bi - ai
1518 eiisinf (ai) 1 if infinite
1519 eiisnan (ai) 1 if a NaN
1520 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1521 einan (ai) set ai = NaN
1523 eiinfin (ai) set ai = infinity
1526 The result is always normalized and rounded to NI-4 word precision
1527 after each arithmetic operation.
1529 Exception flags are NOT fully supported.
1531 Signaling NaN's are NOT supported; they are treated the same
1534 Define INFINITY for support of infinity; otherwise a
1535 saturation arithmetic is implemented.
1537 Define NANS for support of Not-a-Number items; otherwise the
1538 arithmetic will never produce a NaN output, and might be confused
1540 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1541 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1542 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1545 Denormals are always supported here where appropriate (e.g., not
1546 for conversion to DEC numbers). */
1548 /* Definitions for error codes that are passed to the common error handling
1551 For Digital Equipment PDP-11 and VAX computers, certain
1552 IBM systems, and others that use numbers with a 56-bit
1553 significand, the symbol DEC should be defined. In this
1554 mode, most floating point constants are given as arrays
1555 of octal integers to eliminate decimal to binary conversion
1556 errors that might be introduced by the compiler.
1558 For computers, such as IBM PC, that follow the IEEE
1559 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1560 Std 754-1985), the symbol IEEE should be defined.
1561 These numbers have 53-bit significands. In this mode, constants
1562 are provided as arrays of hexadecimal 16 bit integers.
1563 The endian-ness of generated values is controlled by
1564 REAL_WORDS_BIG_ENDIAN.
1566 To accommodate other types of computer arithmetic, all
1567 constants are also provided in a normal decimal radix
1568 which one can hope are correctly converted to a suitable
1569 format by the available C language compiler. To invoke
1570 this mode, the symbol UNK is defined.
1572 An important difference among these modes is a predefined
1573 set of machine arithmetic constants for each. The numbers
1574 MACHEP (the machine roundoff error), MAXNUM (largest number
1575 represented), and several other parameters are preset by
1576 the configuration symbol. Check the file const.c to
1577 ensure that these values are correct for your computer.
1579 For ANSI C compatibility, define ANSIC equal to 1. Currently
1580 this affects only the atan2 function and others that use it. */
1582 /* Constant definitions for math error conditions. */
1584 #define DOMAIN 1 /* argument domain error */
1585 #define SING 2 /* argument singularity */
1586 #define OVERFLOW 3 /* overflow range error */
1587 #define UNDERFLOW 4 /* underflow range error */
1588 #define TLOSS 5 /* total loss of precision */
1589 #define PLOSS 6 /* partial loss of precision */
1590 #define INVALID 7 /* NaN-producing operation */
1592 /* e type constants used by high precision check routines */
1594 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
1596 const UEMUSHORT ezero
[NE
] =
1597 {0x0000, 0x0000, 0x0000, 0x0000,
1598 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1601 const UEMUSHORT ehalf
[NE
] =
1602 {0x0000, 0x0000, 0x0000, 0x0000,
1603 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1606 const UEMUSHORT eone
[NE
] =
1607 {0x0000, 0x0000, 0x0000, 0x0000,
1608 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1611 const UEMUSHORT etwo
[NE
] =
1612 {0x0000, 0x0000, 0x0000, 0x0000,
1613 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1616 const UEMUSHORT e32
[NE
] =
1617 {0x0000, 0x0000, 0x0000, 0x0000,
1618 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1620 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1621 const UEMUSHORT elog2
[NE
] =
1622 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1623 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1625 /* 1.41421356237309504880168872420969807856967187537695E0 */
1626 const UEMUSHORT esqrt2
[NE
] =
1627 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1628 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1630 /* 3.14159265358979323846264338327950288419716939937511E0 */
1631 const UEMUSHORT epi
[NE
] =
1632 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1633 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1636 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1637 const UEMUSHORT ezero
[NE
] =
1638 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1639 const UEMUSHORT ehalf
[NE
] =
1640 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1641 const UEMUSHORT eone
[NE
] =
1642 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1643 const UEMUSHORT etwo
[NE
] =
1644 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1645 const UEMUSHORT e32
[NE
] =
1646 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1647 const UEMUSHORT elog2
[NE
] =
1648 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1649 const UEMUSHORT esqrt2
[NE
] =
1650 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1651 const UEMUSHORT epi
[NE
] =
1652 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1655 /* Control register for rounding precision.
1656 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1661 /* Clear out entire e-type number X. */
1669 for (i
= 0; i
< NE
; i
++)
1673 /* Move e-type number from A to B. */
1682 for (i
= 0; i
< NE
; i
++)
1688 /* Absolute value of e-type X. */
1694 /* sign is top bit of last word of external format */
1695 x
[NE
- 1] &= 0x7fff;
1699 /* Negate the e-type number X. */
1706 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1709 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1713 const UEMUSHORT x
[];
1716 if (x
[NE
- 1] & 0x8000)
1722 /* Return 1 if e-type number X is infinity, else return zero. */
1726 const UEMUSHORT x
[];
1733 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1739 /* Check if e-type number is not a number. The bit pattern is one that we
1740 defined, so we know for sure how to detect it. */
1744 const UEMUSHORT x
[] ATTRIBUTE_UNUSED
;
1749 /* NaN has maximum exponent */
1750 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1752 /* ... and non-zero significand field. */
1753 for (i
= 0; i
< NE
- 1; i
++)
1763 /* Fill e-type number X with infinity pattern (IEEE)
1764 or largest possible number (non-IEEE). */
1773 for (i
= 0; i
< NE
- 1; i
++)
1777 for (i
= 0; i
< NE
- 1; i
++)
1805 /* Output an e-type NaN.
1806 This generates Intel's quiet NaN pattern for extended real.
1807 The exponent is 7fff, the leading mantissa word is c000. */
1817 for (i
= 0; i
< NE
- 2; i
++)
1820 *x
= (sign
<< 15) | 0x7fff;
1824 /* Move in an e-type number A, converting it to exploded e-type B. */
1836 p
= a
+ (NE
- 1); /* point to last word of external number */
1837 /* get the sign bit */
1842 /* get the exponent */
1844 *q
++ &= 0x7fff; /* delete the sign bit */
1846 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1852 for (i
= 3; i
< NI
; i
++)
1858 for (i
= 2; i
< NI
; i
++)
1864 /* clear high guard word */
1866 /* move in the significand */
1867 for (i
= 0; i
< NE
- 1; i
++)
1869 /* clear low guard word */
1873 /* Move out exploded e-type number A, converting it to e type B. */
1886 q
= b
+ (NE
- 1); /* point to output exponent */
1887 /* combine sign and exponent */
1890 *q
-- = *p
++ | 0x8000;
1894 if (*(p
- 1) == 0x7fff)
1899 enan (b
, eiisneg (a
));
1907 /* skip over guard word */
1909 /* move the significand */
1910 for (j
= 0; j
< NE
- 1; j
++)
1914 /* Clear out exploded e-type number XI. */
1922 for (i
= 0; i
< NI
; i
++)
1926 /* Clear out exploded e-type XI, but don't touch the sign. */
1935 for (i
= 0; i
< NI
- 1; i
++)
1939 /* Move exploded e-type number from A to B. */
1948 for (i
= 0; i
< NI
- 1; i
++)
1950 /* clear low guard word */
1954 /* Generate exploded e-type NaN.
1955 The explicit pattern for this is maximum exponent and
1956 top two significant bits set. */
1970 /* Return nonzero if exploded e-type X is a NaN. */
1975 const UEMUSHORT x
[];
1979 if ((x
[E
] & 0x7fff) == 0x7fff)
1981 for (i
= M
+ 1; i
< NI
; i
++)
1991 /* Return nonzero if sign of exploded e-type X is nonzero. */
1995 const UEMUSHORT x
[];
2002 /* Fill exploded e-type X with infinity pattern.
2003 This has maximum exponent and significand all zeros. */
2015 /* Return nonzero if exploded e-type X is infinite. */
2020 const UEMUSHORT x
[];
2027 if ((x
[E
] & 0x7fff) == 0x7fff)
2031 #endif /* INFINITY */
2033 /* Compare significands of numbers in internal exploded e-type format.
2034 Guard words are included in the comparison.
2042 const UEMUSHORT
*a
, *b
;
2046 a
+= M
; /* skip up to significand area */
2048 for (i
= M
; i
< NI
; i
++)
2056 if (*(--a
) > *(--b
))
2062 /* Shift significand of exploded e-type X down by 1 bit. */
2071 x
+= M
; /* point to significand area */
2074 for (i
= M
; i
< NI
; i
++)
2086 /* Shift significand of exploded e-type X up by 1 bit. */
2098 for (i
= M
; i
< NI
; i
++)
2111 /* Shift significand of exploded e-type X down by 8 bits. */
2117 UEMUSHORT newbyt
, oldbyt
;
2122 for (i
= M
; i
< NI
; i
++)
2132 /* Shift significand of exploded e-type X up by 8 bits. */
2139 UEMUSHORT newbyt
, oldbyt
;
2144 for (i
= M
; i
< NI
; i
++)
2154 /* Shift significand of exploded e-type X up by 16 bits. */
2166 for (i
= M
; i
< NI
- 1; i
++)
2172 /* Shift significand of exploded e-type X down by 16 bits. */
2184 for (i
= M
; i
< NI
- 1; i
++)
2190 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2204 for (i
= M
; i
< NI
; i
++)
2206 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2217 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2231 for (i
= M
; i
< NI
; i
++)
2233 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2245 static UEMUSHORT equot
[NI
];
2249 /* Radix 2 shift-and-add versions of multiply and divide */
2252 /* Divide significands */
2256 UEMUSHORT den
[], num
[];
2266 for (i
= M
; i
< NI
; i
++)
2271 /* Use faster compare and subtraction if denominator has only 15 bits of
2277 for (i
= M
+ 3; i
< NI
; i
++)
2282 if ((den
[M
+ 1] & 1) != 0)
2290 for (i
= 0; i
< NBITS
+ 2; i
++)
2308 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2309 bit + 1 roundoff bit. */
2314 for (i
= 0; i
< NBITS
+ 2; i
++)
2316 if (ecmpm (den
, num
) <= 0)
2319 j
= 1; /* quotient bit = 1 */
2333 /* test for nonzero remainder after roundoff bit */
2336 for (i
= M
; i
< NI
; i
++)
2344 for (i
= 0; i
< NI
; i
++)
2350 /* Multiply significands */
2361 for (i
= M
; i
< NI
; i
++)
2366 while (*p
== 0) /* significand is not supposed to be zero */
2371 if ((*p
& 0xff) == 0)
2379 for (i
= 0; i
< k
; i
++)
2383 /* remember if there were any nonzero bits shifted out */
2390 for (i
= 0; i
< NI
; i
++)
2393 /* return flag for lost nonzero bits */
2399 /* Radix 65536 versions of multiply and divide. */
2401 /* Multiply significand of e-type number B
2402 by 16-bit quantity A, return e-type result to C. */
2407 const UEMUSHORT b
[];
2411 unsigned EMULONG carry
;
2412 const UEMUSHORT
*ps
;
2414 unsigned EMULONG aa
, m
;
2423 for (i
=M
+1; i
<NI
; i
++)
2433 m
= (unsigned EMULONG
) aa
* *ps
--;
2434 carry
= (m
& 0xffff) + *pp
;
2435 *pp
-- = (UEMUSHORT
) carry
;
2436 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2437 *pp
= (UEMUSHORT
) carry
;
2438 *(pp
-1) = carry
>> 16;
2441 for (i
=M
; i
<NI
; i
++)
2445 /* Divide significands of exploded e-types NUM / DEN. Neither the
2446 numerator NUM nor the denominator DEN is permitted to have its high guard
2451 const UEMUSHORT den
[];
2456 unsigned EMULONG tnum
;
2457 UEMUSHORT j
, tdenm
, tquot
;
2458 UEMUSHORT tprod
[NI
+1];
2464 for (i
=M
; i
<NI
; i
++)
2470 for (i
=M
; i
<NI
; i
++)
2472 /* Find trial quotient digit (the radix is 65536). */
2473 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2475 /* Do not execute the divide instruction if it will overflow. */
2476 if ((tdenm
* (unsigned long) 0xffff) < tnum
)
2479 tquot
= tnum
/ tdenm
;
2480 /* Multiply denominator by trial quotient digit. */
2481 m16m ((unsigned int) tquot
, den
, tprod
);
2482 /* The quotient digit may have been overestimated. */
2483 if (ecmpm (tprod
, num
) > 0)
2487 if (ecmpm (tprod
, num
) > 0)
2497 /* test for nonzero remainder after roundoff bit */
2500 for (i
=M
; i
<NI
; i
++)
2507 for (i
=0; i
<NI
; i
++)
2513 /* Multiply significands of exploded e-type A and B, result in B. */
2517 const UEMUSHORT a
[];
2522 UEMUSHORT pprod
[NI
];
2528 for (i
=M
; i
<NI
; i
++)
2534 for (i
=M
+1; i
<NI
; i
++)
2542 m16m ((unsigned int) *p
--, b
, pprod
);
2543 eaddm (pprod
, equot
);
2549 for (i
=0; i
<NI
; i
++)
2552 /* return flag for lost nonzero bits */
2558 /* Normalize and round off.
2560 The internal format number to be rounded is S.
2561 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2563 Input SUBFLG indicates whether the number was obtained
2564 by a subtraction operation. In that case if LOST is nonzero
2565 then the number is slightly smaller than indicated.
2567 Input EXP is the biased exponent, which may be negative.
2568 the exponent field of S is ignored but is replaced by
2569 EXP as adjusted by normalization and rounding.
2571 Input RCNTRL is the rounding control. If it is nonzero, the
2572 returned value will be rounded to RNDPRC bits.
2574 For future reference: In order for emdnorm to round off denormal
2575 significands at the right point, the input exponent must be
2576 adjusted to be the actual value it would have after conversion to
2577 the final floating point type. This adjustment has been
2578 implemented for all type conversions (etoe53, etc.) and decimal
2579 conversions, but not for the arithmetic functions (eadd, etc.).
2580 Data types having standard 15-bit exponents are not affected by
2581 this, but SFmode and DFmode are affected. For example, ediv with
2582 rndprc = 24 will not round correctly to 24-bit precision if the
2583 result is denormal. */
2585 static int rlast
= -1;
2587 static UEMUSHORT rmsk
= 0;
2588 static UEMUSHORT rmbit
= 0;
2589 static UEMUSHORT rebit
= 0;
2591 static UEMUSHORT rbit
[NI
];
2594 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2607 /* a blank significand could mean either zero or infinity. */
2620 if ((j
> NBITS
) && (exp
< 32767))
2628 if (exp
> (EMULONG
) (-NBITS
- 1))
2641 /* Round off, unless told not to by rcntrl. */
2644 /* Set up rounding parameters if the control register changed. */
2645 if (rndprc
!= rlast
)
2652 rw
= NI
- 1; /* low guard word */
2675 /* For DEC or IBM arithmetic */
2692 /* For C4x arithmetic */
2713 /* Shift down 1 temporarily if the data structure has an implied
2714 most significant bit and the number is denormal.
2715 Intel long double denormals also lose one bit of precision. */
2716 if ((exp
<= 0) && (rndprc
!= NBITS
)
2717 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2719 lost
|= s
[NI
- 1] & 1;
2722 /* Clear out all bits below the rounding bit,
2723 remembering in r if any were nonzero. */
2737 if ((r
& rmbit
) != 0)
2743 { /* round to even */
2744 if ((s
[re
] & rebit
) == 0)
2757 /* Undo the temporary shift for denormal values. */
2758 if ((exp
<= 0) && (rndprc
!= NBITS
)
2759 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2764 { /* overflow on roundoff */
2777 for (i
= 2; i
< NI
- 1; i
++)
2780 warning ("floating point overflow");
2784 for (i
= M
+ 1; i
< NI
- 1; i
++)
2787 if ((rndprc
< 64) || (rndprc
== 113))
2802 s
[1] = (UEMUSHORT
) exp
;
2805 /* Subtract. C = B - A, all e type numbers. */
2807 static int subflg
= 0;
2811 const UEMUSHORT
*a
, *b
;
2826 /* Infinity minus infinity is a NaN.
2827 Test for subtracting infinities of the same sign. */
2828 if (eisinf (a
) && eisinf (b
)
2829 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2831 mtherr ("esub", INVALID
);
2840 /* Add. C = A + B, all e type. */
2844 const UEMUSHORT
*a
, *b
;
2849 /* NaN plus anything is a NaN. */
2860 /* Infinity minus infinity is a NaN.
2861 Test for adding infinities of opposite signs. */
2862 if (eisinf (a
) && eisinf (b
)
2863 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2865 mtherr ("esub", INVALID
);
2874 /* Arithmetic common to both addition and subtraction. */
2878 const UEMUSHORT
*a
, *b
;
2881 UEMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2883 EMULONG lt
, lta
, ltb
;
2904 /* compare exponents */
2909 { /* put the larger number in bi */
2919 if (lt
< (EMULONG
) (-NBITS
- 1))
2920 goto done
; /* answer same as larger addend */
2922 lost
= eshift (ai
, k
); /* shift the smaller number down */
2926 /* exponents were the same, so must compare significands */
2929 { /* the numbers are identical in magnitude */
2930 /* if different signs, result is zero */
2936 /* if same sign, result is double */
2937 /* double denormalized tiny number */
2938 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2943 /* add 1 to exponent unless both are zero! */
2944 for (j
= 1; j
< NI
- 1; j
++)
2960 bi
[E
] = (UEMUSHORT
) ltb
;
2964 { /* put the larger number in bi */
2980 emdnorm (bi
, lost
, subflg
, ltb
, !ROUND_TOWARDS_ZERO
);
2986 /* Divide: C = B/A, all e type. */
2990 const UEMUSHORT
*a
, *b
;
2993 UEMUSHORT ai
[NI
], bi
[NI
];
2995 EMULONG lt
, lta
, ltb
;
2997 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2998 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2999 sign
= eisneg (a
) ^ eisneg (b
);
3002 /* Return any NaN input. */
3013 /* Zero over zero, or infinity over infinity, is a NaN. */
3014 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
3015 || (eisinf (a
) && eisinf (b
)))
3017 mtherr ("ediv", INVALID
);
3022 /* Infinity over anything else is infinity. */
3029 /* Anything else over infinity is zero. */
3041 { /* See if numerator is zero. */
3042 for (i
= 1; i
< NI
- 1; i
++)
3046 ltb
-= enormlz (bi
);
3056 { /* possible divide by zero */
3057 for (i
= 1; i
< NI
- 1; i
++)
3061 lta
-= enormlz (ai
);
3065 /* Divide by zero is not an invalid operation.
3066 It is a divide-by-zero operation! */
3068 mtherr ("ediv", SING
);
3074 /* calculate exponent */
3075 lt
= ltb
- lta
+ EXONE
;
3076 emdnorm (bi
, i
, 0, lt
, !ROUND_TOWARDS_ZERO
);
3083 && (ecmp (c
, ezero
) != 0)
3086 *(c
+(NE
-1)) |= 0x8000;
3088 *(c
+(NE
-1)) &= ~0x8000;
3091 /* Multiply e-types A and B, return e-type product C. */
3095 const UEMUSHORT
*a
, *b
;
3098 UEMUSHORT ai
[NI
], bi
[NI
];
3100 EMULONG lt
, lta
, ltb
;
3102 /* IEEE says if result is not a NaN, the sign is "-" if and only if
3103 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
3104 sign
= eisneg (a
) ^ eisneg (b
);
3107 /* NaN times anything is the same NaN. */
3118 /* Zero times infinity is a NaN. */
3119 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
3120 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
3122 mtherr ("emul", INVALID
);
3127 /* Infinity times anything else is infinity. */
3129 if (eisinf (a
) || eisinf (b
))
3141 for (i
= 1; i
< NI
- 1; i
++)
3145 lta
-= enormlz (ai
);
3156 for (i
= 1; i
< NI
- 1; i
++)
3160 ltb
-= enormlz (bi
);
3169 /* Multiply significands */
3171 /* calculate exponent */
3172 lt
= lta
+ ltb
- (EXONE
- 1);
3173 emdnorm (bi
, j
, 0, lt
, !ROUND_TOWARDS_ZERO
);
3180 && (ecmp (c
, ezero
) != 0)
3183 *(c
+(NE
-1)) |= 0x8000;
3185 *(c
+(NE
-1)) &= ~0x8000;
3188 /* Convert double precision PE to e-type Y. */
3192 const UEMUSHORT
*pe
;
3202 ibmtoe (pe
, y
, DFmode
);
3207 c4xtoe (pe
, y
, HFmode
);
3211 ieeetoe (pe
, y
, &ieee_53
);
3213 #endif /* not C4X */
3214 #endif /* not IBM */
3215 #endif /* not DEC */
3218 /* Convert double extended precision float PE to e type Y. */
3222 const UEMUSHORT
*pe
;
3232 for (i
= 0; i
< NE
- 5; i
++)
3235 /* REAL_WORDS_BIG_ENDIAN is always 0 for DEC and 1 for IBM.
3236 This precision is not ordinarily supported on DEC or IBM. */
3237 if (! REAL_WORDS_BIG_ENDIAN
)
3239 for (i
= 0; i
< 5; i
++)
3243 /* For denormal long double Intel format, shift significand up one
3244 -- but only if the top significand bit is zero. A top bit of 1
3245 is "pseudodenormal" when the exponent is zero. */
3246 if ((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3259 p
= &yy
[0] + (NE
- 1);
3262 for (i
= 0; i
< 4; i
++)
3265 #endif /* not C4X */
3267 /* Point to the exponent field and check max exponent cases. */
3269 if ((*p
& 0x7fff) == 0x7fff)
3272 if (! REAL_WORDS_BIG_ENDIAN
)
3274 for (i
= 0; i
< 4; i
++)
3276 if ((i
!= 3 && pe
[i
] != 0)
3277 /* Anything but 0x8000 here, including 0, is a NaN. */
3278 || (i
== 3 && pe
[i
] != 0x8000))
3280 enan (y
, (*p
& 0x8000) != 0);
3287 /* In Motorola extended precision format, the most significant
3288 bit of an infinity mantissa could be either 1 or 0. It is
3289 the lower order bits that tell whether the value is a NaN. */
3290 if ((pe
[2] & 0x7fff) != 0)
3293 for (i
= 3; i
<= 5; i
++)
3298 enan (y
, (*p
& 0x8000) != 0);
3310 #endif /* INFINITY */
3313 for (i
= 0; i
< NE
; i
++)
3317 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3318 /* Convert 128-bit long double precision float PE to e type Y. */
3322 const UEMUSHORT
*pe
;
3325 ieeetoe (pe
, y
, &ieee_113
);
3327 #endif /* INTEL_EXTENDED_IEEE_FORMAT == 0 */
3329 /* Convert single precision float PE to e type Y. */
3333 const UEMUSHORT
*pe
;
3338 ibmtoe (pe
, y
, SFmode
);
3344 c4xtoe (pe
, y
, QFmode
);
3349 ieeetoe (pe
, y
, &dec_f
);
3353 ieeetoe (pe
, y
, &ieee_24
);
3355 #endif /* not DEC */
3356 #endif /* not C4X */
3357 #endif /* not IBM */
3360 /* Convert machine format float of specified format PE to e type Y. */
3363 ieeetoe (pe
, y
, fmt
)
3364 const UEMUSHORT
*pe
;
3366 const struct ieee_format
*fmt
;
3373 int shortsm1
= fmt
->bits
/ 16 - 1;
3375 int expmask
= (1 << fmt
->expbits
) - 1;
3377 int expshift
= (fmt
->precision
- 1) & 0x0f;
3378 int highbit
= 1 << expshift
;
3383 if (! REAL_WORDS_BIG_ENDIAN
)
3389 yy
[M
] = (r
& (highbit
- 1)) | highbit
;
3390 r
= (r
& 0x7fff) >> expshift
;
3392 if (!LARGEST_EXPONENT_IS_NORMAL (fmt
->precision
) && r
== expmask
)
3395 /* First check the word where high order mantissa and exponent live */
3396 if ((*e
& (highbit
- 1)) != 0)
3398 enan (y
, yy
[0] != 0);
3401 if (! REAL_WORDS_BIG_ENDIAN
)
3403 for (i
= 0; i
< shortsm1
; i
++)
3407 enan (y
, yy
[0] != 0);
3414 for (i
= 1; i
< shortsm1
+ 1; i
++)
3418 enan (y
, yy
[0] != 0);
3430 #endif /* INFINITY */
3431 /* If zero exponent, then the significand is denormalized.
3432 So take back the understood high significand bit. */
3438 r
+= fmt
->adjustment
;
3441 if (! REAL_WORDS_BIG_ENDIAN
)
3443 for (i
= 0; i
< shortsm1
; i
++)
3449 for (i
= 0; i
< shortsm1
; i
++)
3452 if (fmt
->precision
== 113)
3454 /* denorm is left alone in 113 bit format */
3460 eshift (yy
, -(expshift
+ 1));
3462 { /* if zero exponent, then normalize the significand */
3463 if ((k
= enormlz (yy
)) > NBITS
)
3466 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3472 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3473 /* Convert e-type X to IEEE 128-bit long double format E. */
3480 etoieee (x
, e
, &ieee_113
);
3483 /* Convert exploded e-type X, that has already been rounded to
3484 113-bit precision, to IEEE 128-bit long double format Y. */
3490 toieee (x
, y
, &ieee_113
);
3493 #endif /* INTEL_EXTENDED_IEEE_FORMAT == 0 */
3495 /* Convert e-type X to IEEE double extended format E. */
3502 etoieee (x
, e
, &ieee_64
);
3505 /* Convert exploded e-type X, that has already been rounded to
3506 64-bit precision, to IEEE double extended format Y. */
3512 toieee (x
, y
, &ieee_64
);
3515 /* e type to double precision. */
3518 /* Convert e-type X to DEC-format double E. */
3528 /* Convert exploded e-type X, that has already been rounded to
3529 56-bit double precision, to DEC double Y. */
3540 /* Convert e-type X to IBM 370-format double E. */
3547 etoibm (x
, e
, DFmode
);
3550 /* Convert exploded e-type X, that has already been rounded to
3551 56-bit precision, to IBM 370 double Y. */
3557 toibm (x
, y
, DFmode
);
3560 #else /* it's neither DEC nor IBM */
3562 /* Convert e-type X to C4X-format long double E. */
3569 etoc4x (x
, e
, HFmode
);
3572 /* Convert exploded e-type X, that has already been rounded to
3573 56-bit precision, to IBM 370 double Y. */
3579 toc4x (x
, y
, HFmode
);
3582 #else /* it's neither DEC nor IBM nor C4X */
3584 /* Convert e-type X to IEEE double E. */
3591 etoieee (x
, e
, &ieee_53
);
3594 /* Convert exploded e-type X, that has already been rounded to
3595 53-bit precision, to IEEE double Y. */
3601 toieee (x
, y
, &ieee_53
);
3604 #endif /* not C4X */
3605 #endif /* not IBM */
3606 #endif /* not DEC */
3610 /* e type to single precision. */
3613 /* Convert e-type X to IBM 370 float E. */
3620 etoibm (x
, e
, SFmode
);
3623 /* Convert exploded e-type X, that has already been rounded to
3624 float precision, to IBM 370 float Y. */
3630 toibm (x
, y
, SFmode
);
3633 #else /* it's not IBM */
3636 /* Convert e-type X to C4X float E. */
3643 etoc4x (x
, e
, QFmode
);
3646 /* Convert exploded e-type X, that has already been rounded to
3647 float precision, to IBM 370 float Y. */
3653 toc4x (x
, y
, QFmode
);
3656 #else /* it's neither IBM nor C4X */
3660 /* Convert e-type X to DEC F-float E. */
3667 etoieee (x
, e
, &dec_f
);
3670 /* Convert exploded e-type X, that has already been rounded to
3671 float precision, to DEC F-float Y. */
3677 toieee (x
, y
, &dec_f
);
3682 /* Convert e-type X to IEEE float E. */
3689 etoieee (x
, e
, &ieee_24
);
3692 /* Convert exploded e-type X, that has already been rounded to
3693 float precision, to IEEE float Y. */
3699 toieee (x
, y
, &ieee_24
);
3702 #endif /* not DEC */
3703 #endif /* not C4X */
3704 #endif /* not IBM */
3707 /* Convert e-type X to the IEEE format described by FMT. */
3713 const struct ieee_format
*fmt
;
3722 make_nan (e
, eisneg (x
), fmt
->mode
);
3733 /* Adjust exponent for offset. */
3734 exp
= (EMULONG
) xi
[E
] - fmt
->adjustment
;
3736 /* Round off to nearest or even. */
3738 rndprc
= fmt
->precision
;
3739 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3744 toieee (xi
, e
, fmt
);
3747 /* Convert exploded e-type X, that has already been rounded to
3748 the necessary precision, to the IEEE format described by FMT. */
3753 const struct ieee_format
*fmt
;
3760 maxexp
= (1 << fmt
->expbits
) - 1;
3761 words
= (fmt
->bits
- fmt
->expbits
) / EMUSHORT_SIZE
;
3766 make_nan (y
, eiisneg (x
), fmt
->mode
);
3771 if (fmt
->expbits
< 15
3772 && LARGEST_EXPONENT_IS_NORMAL (fmt
->bits
)
3775 saturate (y
, eiisneg (x
), fmt
->bits
, 1);
3779 /* Point to the exponent. */
3780 if (REAL_WORDS_BIG_ENDIAN
)
3785 /* Copy the sign. */
3791 if (fmt
->expbits
< 15
3792 && !LARGEST_EXPONENT_IS_NORMAL (fmt
->bits
)
3795 /* Saturate at largest number less that infinity. */
3798 *q
|= maxexp
<< (15 - fmt
->expbits
);
3801 *q
|= (maxexp
<< (15 - fmt
->expbits
)) - 1;
3805 if (!REAL_WORDS_BIG_ENDIAN
)
3807 for (i
= 0; i
< words
; i
++)
3812 for (i
= 0; i
< words
; i
++)
3815 #if defined(INFINITY) && defined(ERANGE)
3821 /* If denormal and DEC float, return zero (DEC has no denormals) */
3825 for (i
= 0; i
< fmt
->bits
/ EMUSHORT_SIZE
; i
++)
3831 /* Delete the implied bit unless denormal, except for
3832 64-bit precision. */
3833 if (fmt
->precision
!= 64 && x
[E
] != 0)
3838 /* Shift denormal double extended Intel format significand down
3840 if (fmt
->precision
== 64 && x
[E
] == 0 && ! REAL_WORDS_BIG_ENDIAN
)
3843 if (fmt
->expbits
< 15)
3845 /* Shift the significand. */
3846 eshift (x
, 15 - fmt
->expbits
);
3848 /* Combine the exponent and upper bits of the significand. */
3849 *q
|= x
[E
] << (15 - fmt
->expbits
);
3850 *q
|= x
[M
] & (UEMUSHORT
) ~((maxexp
<< (15 - fmt
->expbits
)) | 0x8000);
3854 /* Copy the exponent. */
3858 /* Add padding after the exponent. At the moment, this is only necessary for
3859 64-bit precision; in this case, the padding is 16 bits. */
3860 if (fmt
->precision
== 64)
3865 if (REAL_WORDS_BIG_ENDIAN
)
3869 /* Copy the significand. */
3870 if (REAL_WORDS_BIG_ENDIAN
)
3872 for (i
= 0; i
< words
; i
++)
3873 *(++q
) = x
[i
+ M
+ 1];
3876 else if (fmt
->precision
== 64 && eiisinf (x
))
3878 /* Intel double extended infinity significand. */
3887 for (i
= 0; i
< words
; i
++)
3888 *(--q
) = x
[i
+ M
+ 1];
3893 /* Compare two e type numbers.
3897 -2 if either a or b is a NaN. */
3901 const UEMUSHORT
*a
, *b
;
3903 UEMUSHORT ai
[NI
], bi
[NI
];
3909 if (eisnan (a
) || eisnan (b
))
3918 { /* the signs are different */
3920 for (i
= 1; i
< NI
- 1; i
++)
3934 /* both are the same sign */
3949 return (0); /* equality */
3953 if (*(--p
) > *(--q
))
3954 return (msign
); /* p is bigger */
3956 return (-msign
); /* p is littler */
3960 /* Find e-type nearest integer to X, as floor (X + 0.5). */
3972 /* Convert HOST_WIDE_INT LP to e type Y. */
3976 const HOST_WIDE_INT
*lp
;
3980 unsigned HOST_WIDE_INT ll
;
3986 /* make it positive */
3987 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
3988 yi
[0] = 0xffff; /* put correct sign in the e type number */
3992 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
3994 /* move the long integer to yi significand area */
3995 #if HOST_BITS_PER_WIDE_INT == 64
3996 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
3997 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
3998 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
3999 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4000 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4002 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4003 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4004 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4007 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4008 ecleaz (yi
); /* it was zero */
4010 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
4011 emovo (yi
, y
); /* output the answer */
4014 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4018 const unsigned HOST_WIDE_INT
*lp
;
4022 unsigned HOST_WIDE_INT ll
;
4028 /* move the long integer to ayi significand area */
4029 #if HOST_BITS_PER_WIDE_INT == 64
4030 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4031 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4032 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4033 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4034 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4036 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4037 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4038 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4041 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4042 ecleaz (yi
); /* it was zero */
4044 yi
[E
] -= (UEMUSHORT
) k
; /* subtract shift count from exponent */
4045 emovo (yi
, y
); /* output the answer */
4049 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4050 part FRAC of e-type (packed internal format) floating point input X.
4051 The integer output I has the sign of the input, except that
4052 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4053 The output e-type fraction FRAC is the positive fractional
4064 unsigned HOST_WIDE_INT ll
;
4067 k
= (int) xi
[E
] - (EXONE
- 1);
4070 /* if exponent <= 0, integer = 0 and real output is fraction */
4075 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4077 /* long integer overflow: output large integer
4078 and correct fraction */
4080 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4083 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4084 /* In this case, let it overflow and convert as if unsigned. */
4085 euifrac (x
, &ll
, frac
);
4086 *i
= (HOST_WIDE_INT
) ll
;
4089 /* In other cases, return the largest positive integer. */
4090 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4095 warning ("overflow on truncation to integer");
4099 /* Shift more than 16 bits: first shift up k-16 mod 16,
4100 then shift up by 16's. */
4101 j
= k
- ((k
>> 4) << 4);
4108 ll
= (ll
<< 16) | xi
[M
];
4110 while ((k
-= 16) > 0);
4117 /* shift not more than 16 bits */
4119 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4126 if ((k
= enormlz (xi
)) > NBITS
)
4129 xi
[E
] -= (UEMUSHORT
) k
;
4135 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4136 FRAC of e-type X. A negative input yields integer output = 0 but
4137 correct fraction. */
4140 euifrac (x
, i
, frac
)
4142 unsigned HOST_WIDE_INT
*i
;
4145 unsigned HOST_WIDE_INT ll
;
4150 k
= (int) xi
[E
] - (EXONE
- 1);
4153 /* if exponent <= 0, integer = 0 and argument is fraction */
4158 if (k
> HOST_BITS_PER_WIDE_INT
)
4160 /* Long integer overflow: output large integer
4161 and correct fraction.
4162 Note, the BSD MicroVAX compiler says that ~(0UL)
4163 is a syntax error. */
4167 warning ("overflow on truncation to unsigned integer");
4171 /* Shift more than 16 bits: first shift up k-16 mod 16,
4172 then shift up by 16's. */
4173 j
= k
- ((k
>> 4) << 4);
4180 ll
= (ll
<< 16) | xi
[M
];
4182 while ((k
-= 16) > 0);
4187 /* shift not more than 16 bits */
4189 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4192 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4198 if ((k
= enormlz (xi
)) > NBITS
)
4201 xi
[E
] -= (UEMUSHORT
) k
;
4206 /* Shift the significand of exploded e-type X up or down by SC bits. */
4227 lost
|= *p
; /* remember lost bits */
4268 return ((int) lost
);
4271 /* Shift normalize the significand area of exploded e-type X.
4272 Return the shift count (up = positive). */
4287 return (0); /* already normalized */
4293 /* With guard word, there are NBITS+16 bits available.
4294 Return true if all are zero. */
4298 /* see if high byte is zero */
4299 while ((*p
& 0xff00) == 0)
4304 /* now shift 1 bit at a time */
4305 while ((*p
& 0x8000) == 0)
4311 mtherr ("enormlz", UNDERFLOW
);
4317 /* Normalize by shifting down out of the high guard word
4318 of the significand */
4333 mtherr ("enormlz", OVERFLOW
);
4340 /* Powers of ten used in decimal <-> binary conversions. */
4345 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
4346 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4348 {0x6576, 0x4a92, 0x804a, 0x153f,
4349 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4350 {0x6a32, 0xce52, 0x329a, 0x28ce,
4351 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4352 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4353 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4354 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4355 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4356 {0x851e, 0xeab7, 0x98fe, 0x901b,
4357 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4358 {0x0235, 0x0137, 0x36b1, 0x336c,
4359 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4360 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4361 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4362 {0x0000, 0x0000, 0x0000, 0x0000,
4363 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4364 {0x0000, 0x0000, 0x0000, 0x0000,
4365 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4366 {0x0000, 0x0000, 0x0000, 0x0000,
4367 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4368 {0x0000, 0x0000, 0x0000, 0x0000,
4369 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4370 {0x0000, 0x0000, 0x0000, 0x0000,
4371 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4372 {0x0000, 0x0000, 0x0000, 0x0000,
4373 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4376 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4378 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4379 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4380 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4381 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4382 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4383 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4384 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4385 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4386 {0xa23e, 0x5308, 0xfefb, 0x1155,
4387 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4388 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4389 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4390 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4391 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4392 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4393 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4394 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4395 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4396 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4397 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4398 {0xc155, 0xa4a8, 0x404e, 0x6113,
4399 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4400 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4401 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4402 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4403 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4406 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4407 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4409 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4410 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4411 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4412 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4413 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4414 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4415 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4416 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4417 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4418 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4419 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4420 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4421 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4424 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4426 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4427 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4428 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4429 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4430 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4431 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4432 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4433 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4434 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4435 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4436 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4437 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4438 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4443 /* Convert float value X to ASCII string STRING with NDIG digits after
4444 the decimal point. */
4447 e24toasc (x
, string
, ndigs
)
4448 const UEMUSHORT x
[];
4455 etoasc (w
, string
, ndigs
);
4458 /* Convert double value X to ASCII string STRING with NDIG digits after
4459 the decimal point. */
4462 e53toasc (x
, string
, ndigs
)
4463 const UEMUSHORT x
[];
4470 etoasc (w
, string
, ndigs
);
4473 /* Convert double extended value X to ASCII string STRING with NDIG digits
4474 after the decimal point. */
4477 e64toasc (x
, string
, ndigs
)
4478 const UEMUSHORT x
[];
4485 etoasc (w
, string
, ndigs
);
4488 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4489 after the decimal point. */
4492 e113toasc (x
, string
, ndigs
)
4493 const UEMUSHORT x
[];
4500 etoasc (w
, string
, ndigs
);
4504 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4505 the decimal point. */
4507 static char wstring
[80]; /* working storage for ASCII output */
4510 etoasc (x
, string
, ndigs
)
4511 const UEMUSHORT x
[];
4516 UEMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4517 const UEMUSHORT
*p
, *r
, *ten
;
4519 int i
, j
, k
, expon
, rndsav
;
4532 sprintf (wstring
, " NaN ");
4536 rndprc
= NBITS
; /* set to full precision */
4537 emov (x
, y
); /* retain external format */
4538 if (y
[NE
- 1] & 0x8000)
4541 y
[NE
- 1] &= 0x7fff;
4548 ten
= &etens
[NTEN
][0];
4550 /* Test for zero exponent */
4553 for (k
= 0; k
< NE
- 1; k
++)
4556 goto tnzro
; /* denormalized number */
4558 goto isone
; /* valid all zeros */
4562 /* Test for infinity. */
4563 if (y
[NE
- 1] == 0x7fff)
4566 sprintf (wstring
, " -Infinity ");
4568 sprintf (wstring
, " Infinity ");
4572 /* Test for exponent nonzero but significand denormalized.
4573 * This is an error condition.
4575 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4577 mtherr ("etoasc", DOMAIN
);
4578 sprintf (wstring
, "NaN");
4582 /* Compare to 1.0 */
4591 { /* Number is greater than 1 */
4592 /* Convert significand to an integer and strip trailing decimal zeros. */
4594 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4596 p
= &etens
[NTEN
- 4][0];
4602 for (j
= 0; j
< NE
- 1; j
++)
4615 /* Rescale from integer significand */
4616 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4618 /* Find power of 10 */
4622 /* An unordered compare result shouldn't happen here. */
4623 while (ecmp (ten
, u
) <= 0)
4625 if (ecmp (p
, u
) <= 0)
4638 { /* Number is less than 1.0 */
4639 /* Pad significand with trailing decimal zeros. */
4642 while ((y
[NE
- 2] & 0x8000) == 0)
4651 for (i
= 0; i
< NDEC
+ 1; i
++)
4653 if ((w
[NI
- 1] & 0x7) != 0)
4655 /* multiply by 10 */
4668 if (eone
[NE
- 1] <= u
[1])
4680 while (ecmp (eone
, w
) > 0)
4682 if (ecmp (p
, w
) >= 0)
4697 /* Find the first (leading) digit. */
4703 digit
= equot
[NI
- 1];
4704 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4712 digit
= equot
[NI
- 1];
4720 /* Examine number of digits requested by caller. */
4738 *s
++ = (char) digit
+ '0';
4741 /* Generate digits after the decimal point. */
4742 for (k
= 0; k
<= ndigs
; k
++)
4744 /* multiply current number by 10, without normalizing */
4751 *s
++ = (char) equot
[NI
- 1] + '0';
4753 digit
= equot
[NI
- 1];
4756 /* round off the ASCII string */
4759 /* Test for critical rounding case in ASCII output. */
4763 if (ecmp (t
, ezero
) != 0)
4764 goto roun
; /* round to nearest */
4766 if ((*(s
- 1) & 1) == 0)
4767 goto doexp
; /* round to even */
4770 /* Round up and propagate carry-outs */
4774 /* Carry out to most significant digit? */
4781 /* Most significant digit carries to 10? */
4789 /* Round up and carry out from less significant digits */
4799 /* Strip trailing zeros, but leave at least one. */
4800 while (ss
[-1] == '0' && ss
[-2] != '.')
4802 sprintf (ss
, "e%d", expon
);
4805 /* copy out the working string */
4808 while (*ss
== ' ') /* strip possible leading space */
4810 while ((*s
++ = *ss
++) != '\0')
4815 /* Convert ASCII string to floating point.
4817 Numeric input is a free format decimal number of any length, with
4818 or without decimal point. Entering E after the number followed by an
4819 integer number causes the second number to be interpreted as a power of
4820 10 to be multiplied by the first number (i.e., "scientific" notation). */
4822 /* Convert ASCII string S to single precision float value Y. */
4833 /* Convert ASCII string S to double precision value Y. */
4840 #if defined(DEC) || defined(IBM)
4852 /* Convert ASCII string S to double extended value Y. */
4862 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
4863 /* Convert ASCII string S to 128-bit long double Y. */
4870 asctoeg (s
, y
, 113);
4874 /* Convert ASCII string S to e type Y. */
4881 asctoeg (s
, y
, NBITS
);
4884 /* Convert ASCII string SS to e type Y, with a specified rounding precision
4885 of OPREC bits. BASE is 16 for C99 hexadecimal floating constants. */
4888 asctoeg (ss
, y
, oprec
)
4893 UEMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
4894 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
4895 int i
, k
, trail
, c
, rndsav
;
4898 char *sp
, *s
, *lstr
;
4901 /* Copy the input string. */
4902 lstr
= (char *) alloca (strlen (ss
) + 1);
4904 while (*ss
== ' ') /* skip leading spaces */
4908 while ((*sp
++ = *ss
++) != '\0')
4912 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
4919 rndprc
= NBITS
; /* Set to full precision */
4932 if ((k
>= 0) && (k
< base
))
4934 /* Ignore leading zeros */
4935 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
4937 /* Identify and strip trailing zeros after the decimal point. */
4938 if ((trail
== 0) && (decflg
!= 0))
4941 while (ISDIGIT (*sp
) || (base
== 16 && ISXDIGIT (*sp
)))
4943 /* Check for syntax error */
4945 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
4946 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
4948 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
4950 goto unexpected_char_error
;
4959 /* If enough digits were given to more than fill up the yy register,
4960 continuing until overflow into the high guard word yy[2]
4961 guarantees that there will be a roundoff bit at the top
4962 of the low guard word after normalization. */
4969 nexp
+= 4; /* count digits after decimal point */
4971 eshup1 (yy
); /* multiply current number by 16 */
4979 nexp
+= 1; /* count digits after decimal point */
4981 eshup1 (yy
); /* multiply current number by 10 */
4987 /* Insert the current digit. */
4989 xt
[NI
- 2] = (UEMUSHORT
) k
;
4994 /* Mark any lost non-zero digit. */
4996 /* Count lost digits before the decimal point. */
5018 case '.': /* decimal point */
5020 goto unexpected_char_error
;
5026 goto unexpected_char_error
;
5031 goto unexpected_char_error
;
5044 unexpected_char_error
:
5048 mtherr ("asctoe", DOMAIN
);
5057 /* Exponent interpretation */
5059 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5060 for (k
= 0; k
< NI
; k
++)
5071 /* check for + or - */
5079 while (ISDIGIT (*s
))
5088 if ((exp
> MAXDECEXP
) && (base
== 10))
5092 yy
[E
] = 0x7fff; /* infinity */
5095 if ((exp
< MINDECEXP
) && (base
== 10))
5105 /* Base 16 hexadecimal floating constant. */
5106 if ((k
= enormlz (yy
)) > NBITS
)
5111 /* Adjust the exponent. NEXP is the number of hex digits,
5112 EXP is a power of 2. */
5113 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5123 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5124 while ((nexp
> 0) && (yy
[2] == 0))
5136 if ((k
= enormlz (yy
)) > NBITS
)
5141 lexp
= (EXONE
- 1 + NBITS
) - k
;
5142 emdnorm (yy
, lost
, 0, lexp
, 64);
5145 /* Convert to external format:
5147 Multiply by 10**nexp. If precision is 64 bits,
5148 the maximum relative error incurred in forming 10**n
5149 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5150 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5151 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5166 /* Punt. Can't handle this without 2 divides. */
5167 emovi (etens
[0], tt
);
5180 emul (etens
[i
], xt
, xt
);
5184 while (exp
<= MAXP
);
5203 /* Round and convert directly to the destination type */
5205 lexp
-= EXONE
- 0x3ff;
5207 else if (oprec
== 24 || oprec
== 32)
5208 lexp
-= (EXONE
- 0x7f);
5211 else if (oprec
== 24 || oprec
== 56)
5212 lexp
-= EXONE
- (0x41 << 2);
5215 else if (oprec
== 24)
5216 lexp
-= dec_f
.adjustment
;
5217 else if (oprec
== 56)
5220 lexp
-= dec_g
.adjustment
;
5222 lexp
-= dec_d
.adjustment
;
5225 else if (oprec
== 24)
5226 lexp
-= EXONE
- 0177;
5231 emdnorm (yy
, lost
, 0, lexp
, 64);
5246 toibm (yy
, y
, DFmode
);
5251 toc4x (yy
, y
, HFmode
);
5264 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5277 /* Return Y = largest integer not greater than X (truncated toward minus
5280 static const UEMUSHORT bmask
[] =
5303 const UEMUSHORT x
[];
5310 emov (x
, f
); /* leave in external format */
5311 expon
= (int) f
[NE
- 1];
5312 e
= (expon
& 0x7fff) - (EXONE
- 1);
5318 /* number of bits to clear out */
5330 /* clear the remaining bits */
5332 /* truncate negatives toward minus infinity */
5335 if ((UEMUSHORT
) expon
& (UEMUSHORT
) 0x8000)
5337 for (i
= 0; i
< NE
- 1; i
++)
5350 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5351 For example, 1.1 = 0.55 * 2^1. */
5355 const UEMUSHORT x
[];
5363 /* Handle denormalized numbers properly using long integer exponent. */
5364 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5372 *exp
= (int) (li
- 0x3ffe);
5376 /* Return e type Y = X * 2^PWR2. */
5380 const UEMUSHORT x
[];
5392 emdnorm (xi
, i
, i
, li
, !ROUND_TOWARDS_ZERO
);
5398 /* C = remainder after dividing B by A, all e type values.
5399 Least significant integer quotient bits left in EQUOT. */
5403 const UEMUSHORT a
[], b
[];
5406 UEMUSHORT den
[NI
], num
[NI
];
5410 || (ecmp (a
, ezero
) == 0)
5418 if (ecmp (a
, ezero
) == 0)
5420 mtherr ("eremain", SING
);
5426 eiremain (den
, num
);
5427 /* Sign of remainder = sign of quotient */
5436 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5437 remainder in NUM. */
5441 UEMUSHORT den
[], num
[];
5447 ld
-= enormlz (den
);
5449 ln
-= enormlz (num
);
5453 if (ecmpm (den
, num
) <= 0)
5465 emdnorm (num
, 0, 0, ln
, 0);
5468 /* Report an error condition CODE encountered in function NAME.
5470 Mnemonic Value Significance
5472 DOMAIN 1 argument domain error
5473 SING 2 function singularity
5474 OVERFLOW 3 overflow range error
5475 UNDERFLOW 4 underflow range error
5476 TLOSS 5 total loss of precision
5477 PLOSS 6 partial loss of precision
5478 INVALID 7 NaN - producing operation
5479 EDOM 33 Unix domain error code
5480 ERANGE 34 Unix range error code
5482 The order of appearance of the following messages is bound to the
5483 error codes defined above. */
5493 /* The string passed by the calling program is supposed to be the
5494 name of the function in which the error occurred.
5495 The code argument selects which error message string will be printed. */
5497 if (strcmp (name
, "esub") == 0)
5498 name
= "subtraction";
5499 else if (strcmp (name
, "ediv") == 0)
5501 else if (strcmp (name
, "emul") == 0)
5502 name
= "multiplication";
5503 else if (strcmp (name
, "enormlz") == 0)
5504 name
= "normalization";
5505 else if (strcmp (name
, "etoasc") == 0)
5506 name
= "conversion to text";
5507 else if (strcmp (name
, "asctoe") == 0)
5509 else if (strcmp (name
, "eremain") == 0)
5511 else if (strcmp (name
, "esqrt") == 0)
5512 name
= "square root";
5517 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5518 case SING
: warning ("%s: function singularity" , name
); break;
5519 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5520 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5521 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5522 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5523 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5528 /* Set global error message word */
5533 /* Convert DEC double precision D to e type E. */
5541 ieeetoe (d
, e
, &dec_g
);
5543 ieeetoe (d
, e
, &dec_d
);
5546 /* Convert e type X to DEC double precision D. */
5556 const struct ieee_format
*fmt
;
5564 /* Adjust exponent for offsets. */
5565 exp
= (EMULONG
) xi
[E
] - fmt
->adjustment
;
5566 /* Round off to nearest or even. */
5568 rndprc
= fmt
->precision
;
5569 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5574 /* Convert exploded e-type X, that has already been rounded to
5575 56-bit precision, to DEC format double Y. */
5582 toieee (x
, y
, &dec_g
);
5584 toieee (x
, y
, &dec_d
);
5589 /* Convert IBM single/double precision to e type. */
5595 enum machine_mode mode
;
5600 ecleaz (y
); /* start with a zero */
5601 p
= y
; /* point to our number */
5602 r
= *d
; /* get IBM exponent word */
5603 if (*d
& (unsigned int) 0x8000)
5604 *p
= 0xffff; /* fill in our sign */
5605 ++p
; /* bump pointer to our exponent word */
5606 r
&= 0x7f00; /* strip the sign bit */
5607 r
>>= 6; /* shift exponent word down 6 bits */
5608 /* in fact shift by 8 right and 2 left */
5609 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5610 /* add our e type exponent offset */
5611 *p
++ = r
; /* to form our exponent */
5613 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5614 /* strip off the IBM exponent and sign bits */
5615 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5617 *p
++ = *d
++; /* fill in the rest of our mantissa */
5622 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5625 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5626 /* handle change in RADIX */
5632 /* Convert e type to IBM single/double precision. */
5638 enum machine_mode mode
;
5645 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5646 /* round off to nearest or even */
5649 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5651 toibm (xi
, d
, mode
);
5657 enum machine_mode mode
;
5710 /* Convert C4X single/double precision to e type. */
5716 enum machine_mode mode
;
5734 /* Short-circuit the zero case. */
5735 if ((dn
[0] == 0x8000)
5736 && (dn
[1] == 0x0000)
5737 && ((mode
== QFmode
) || ((dn
[2] == 0x0000) && (dn
[3] == 0x0000))))
5748 ecleaz (y
); /* start with a zero */
5749 r
= dn
[0]; /* get sign/exponent part */
5750 if (r
& (unsigned int) 0x0080)
5752 y
[0] = 0xffff; /* fill in our sign */
5758 r
>>= 8; /* Shift exponent word down 8 bits. */
5759 if (r
& 0x80) /* Make the exponent negative if it is. */
5760 r
= r
| (~0 & ~0xff);
5764 /* Now do the high order mantissa. We don't "or" on the high bit
5765 because it is 2 (not 1) and is handled a little differently
5767 y
[M
] = dn
[0] & 0x7f;
5770 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5772 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
5780 /* Now do the two's complement on the data. */
5782 carry
= 1; /* Initially add 1 for the two's complement. */
5783 for (i
=size
+ M
; i
> M
; i
--)
5785 if (carry
&& (y
[i
] == 0x0000))
5786 /* We overflowed into the next word, carry is the same. */
5787 y
[i
] = carry
? 0x0000 : 0xffff;
5790 /* No overflow, just invert and add carry. */
5791 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
5806 /* Add our e type exponent offset to form our exponent. */
5810 /* Now do the high order mantissa strip off the exponent and sign
5811 bits and add the high 1 bit. */
5812 y
[M
] = (dn
[0] & 0x7f) | 0x80;
5815 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5817 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
5827 /* Convert e type to C4X single/double precision. */
5833 enum machine_mode mode
;
5841 /* Adjust exponent for offsets. */
5842 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
5844 /* Round off to nearest or even. */
5846 rndprc
= mode
== QFmode
? 24 : 32;
5847 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5849 toc4x (xi
, d
, mode
);
5855 enum machine_mode mode
;
5861 /* Short-circuit the zero case */
5862 if ((x
[0] == 0) /* Zero exponent and sign */
5864 && (x
[M
] == 0) /* The rest is for zero mantissa */
5866 /* Only check for double if necessary */
5867 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
5869 /* We have a zero. Put it into the output and return. */
5882 /* Negative number require a two's complement conversion of the
5888 i
= ((int) x
[1]) - 0x7f;
5890 /* Now add 1 to the inverted data to do the two's complement. */
5899 x
[v
] = carry
? 0x0000 : 0xffff;
5902 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
5908 /* The following is a special case. The C4X negative float requires
5909 a zero in the high bit (because the format is (2 - x) x 2^m), so
5910 if a one is in that bit, we have to shift left one to get rid
5911 of it. This only occurs if the number is -1 x 2^m. */
5912 if (x
[M
+1] & 0x8000)
5914 /* This is the case of -1 x 2^m, we have to rid ourselves of the
5915 high sign bit and shift the exponent. */
5921 i
= ((int) x
[1]) - 0x7f;
5923 if ((i
< -128) || (i
> 127))
5931 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
5932 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
5940 y
[0] |= ((i
& 0xff) << 8);
5944 y
[0] |= x
[M
] & 0x7f;
5950 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
5951 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
5956 /* Output a binary NaN bit pattern in the target machine's format. */
5958 /* If special NaN bit patterns are required, define them in tm.h
5959 as arrays of unsigned 16-bit shorts. Otherwise, use the default
5965 static const UEMUSHORT TFbignan
[8] =
5966 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5967 static const UEMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
5975 static const UEMUSHORT XFbignan
[6] =
5976 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5977 static const UEMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
5985 static const UEMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
5986 static const UEMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
5994 static const UEMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
5995 static const UEMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6002 make_nan (nan
, sign
, mode
)
6005 enum machine_mode mode
;
6011 size
= GET_MODE_BITSIZE (mode
);
6012 if (LARGEST_EXPONENT_IS_NORMAL (size
))
6014 warning ("%d-bit floats cannot hold NaNs", size
);
6015 saturate (nan
, sign
, size
, 0);
6020 /* Possibly the `reserved operand' patterns on a VAX can be
6021 used like NaN's, but probably not in the same way as IEEE. */
6022 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6024 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
6026 if (REAL_WORDS_BIG_ENDIAN
)
6036 if (REAL_WORDS_BIG_ENDIAN
)
6044 if (REAL_WORDS_BIG_ENDIAN
)
6053 if (REAL_WORDS_BIG_ENDIAN
)
6063 if (REAL_WORDS_BIG_ENDIAN
)
6064 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6067 if (! REAL_WORDS_BIG_ENDIAN
)
6068 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6073 /* Create a saturation value for a SIZE-bit float, assuming that
6074 LARGEST_EXPONENT_IS_NORMAL (SIZE).
6076 If SIGN is true, fill X with the most negative value, otherwise fill
6077 it with the most positive value. WARN is true if the function should
6078 warn about overflow. */
6081 saturate (x
, sign
, size
, warn
)
6083 int sign
, size
, warn
;
6087 if (warn
&& extra_warnings
)
6088 warning ("value exceeds the range of a %d-bit float", size
);
6090 /* Create the most negative value. */
6091 for (i
= 0; i
< size
/ EMUSHORT_SIZE
; i
++)
6094 /* Make it positive, if necessary. */
6096 x
[REAL_WORDS_BIG_ENDIAN
? 0 : i
- 1] = 0x7fff;
6100 /* This is the inverse of the function `etarsingle' invoked by
6101 REAL_VALUE_TO_TARGET_SINGLE. */
6104 ereal_unto_float (f
)
6111 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6112 This is the inverse operation to what the function `endian' does. */
6113 if (REAL_WORDS_BIG_ENDIAN
)
6115 s
[0] = (UEMUSHORT
) (f
>> 16);
6116 s
[1] = (UEMUSHORT
) f
;
6120 s
[0] = (UEMUSHORT
) f
;
6121 s
[1] = (UEMUSHORT
) (f
>> 16);
6123 /* Convert and promote the target float to E-type. */
6125 /* Output E-type to REAL_VALUE_TYPE. */
6131 /* This is the inverse of the function `etardouble' invoked by
6132 REAL_VALUE_TO_TARGET_DOUBLE. */
6135 ereal_unto_double (d
)
6142 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6143 if (REAL_WORDS_BIG_ENDIAN
)
6145 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6146 s
[1] = (UEMUSHORT
) d
[0];
6147 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6148 s
[3] = (UEMUSHORT
) d
[1];
6152 /* Target float words are little-endian. */
6153 s
[0] = (UEMUSHORT
) d
[0];
6154 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6155 s
[2] = (UEMUSHORT
) d
[1];
6156 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6158 /* Convert target double to E-type. */
6160 /* Output E-type to REAL_VALUE_TYPE. */
6166 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6167 This is somewhat like ereal_unto_float, but the input types
6168 for these are different. */
6171 ereal_from_float (f
)
6178 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6179 This is the inverse operation to what the function `endian' does. */
6180 if (REAL_WORDS_BIG_ENDIAN
)
6182 s
[0] = (UEMUSHORT
) (f
>> 16);
6183 s
[1] = (UEMUSHORT
) f
;
6187 s
[0] = (UEMUSHORT
) f
;
6188 s
[1] = (UEMUSHORT
) (f
>> 16);
6190 /* Convert and promote the target float to E-type. */
6192 /* Output E-type to REAL_VALUE_TYPE. */
6198 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6199 This is somewhat like ereal_unto_double, but the input types
6200 for these are different.
6202 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6203 data format, with no holes in the bit packing. The first element
6204 of the input array holds the bits that would come first in the
6205 target computer's memory. */
6208 ereal_from_double (d
)
6215 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6216 if (REAL_WORDS_BIG_ENDIAN
)
6218 #if HOST_BITS_PER_WIDE_INT == 32
6219 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6220 s
[1] = (UEMUSHORT
) d
[0];
6221 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6222 s
[3] = (UEMUSHORT
) d
[1];
6224 /* In this case the entire target double is contained in the
6225 first array element. The second element of the input is
6227 s
[0] = (UEMUSHORT
) (d
[0] >> 48);
6228 s
[1] = (UEMUSHORT
) (d
[0] >> 32);
6229 s
[2] = (UEMUSHORT
) (d
[0] >> 16);
6230 s
[3] = (UEMUSHORT
) d
[0];
6235 /* Target float words are little-endian. */
6236 s
[0] = (UEMUSHORT
) d
[0];
6237 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6238 #if HOST_BITS_PER_WIDE_INT == 32
6239 s
[2] = (UEMUSHORT
) d
[1];
6240 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6242 s
[2] = (UEMUSHORT
) (d
[0] >> 32);
6243 s
[3] = (UEMUSHORT
) (d
[0] >> 48);
6246 /* Convert target double to E-type. */
6248 /* Output E-type to REAL_VALUE_TYPE. */
6255 /* Convert target computer unsigned 64-bit integer to e-type.
6256 The endian-ness of DImode follows the convention for integers,
6257 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6261 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6268 if (WORDS_BIG_ENDIAN
)
6270 for (k
= M
; k
< M
+ 4; k
++)
6275 for (k
= M
+ 3; k
>= M
; k
--)
6278 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6279 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6280 ecleaz (yi
); /* it was zero */
6282 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6286 /* Convert target computer signed 64-bit integer to e-type. */
6290 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6293 unsigned EMULONG acc
;
6299 if (WORDS_BIG_ENDIAN
)
6301 for (k
= M
; k
< M
+ 4; k
++)
6306 for (k
= M
+ 3; k
>= M
; k
--)
6309 /* Take absolute value */
6315 for (k
= M
+ 3; k
>= M
; k
--)
6317 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6324 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6325 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6326 ecleaz (yi
); /* it was zero */
6328 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6335 /* Convert e-type to unsigned 64-bit int. */
6351 k
= (int) xi
[E
] - (EXONE
- 1);
6354 for (j
= 0; j
< 4; j
++)
6360 for (j
= 0; j
< 4; j
++)
6363 warning ("overflow on truncation to integer");
6368 /* Shift more than 16 bits: first shift up k-16 mod 16,
6369 then shift up by 16's. */
6370 j
= k
- ((k
>> 4) << 4);
6374 if (WORDS_BIG_ENDIAN
)
6385 if (WORDS_BIG_ENDIAN
)
6390 while ((k
-= 16) > 0);
6394 /* shift not more than 16 bits */
6399 if (WORDS_BIG_ENDIAN
)
6418 /* Convert e-type to signed 64-bit int. */
6425 unsigned EMULONG acc
;
6432 k
= (int) xi
[E
] - (EXONE
- 1);
6435 for (j
= 0; j
< 4; j
++)
6441 for (j
= 0; j
< 4; j
++)
6444 warning ("overflow on truncation to integer");
6450 /* Shift more than 16 bits: first shift up k-16 mod 16,
6451 then shift up by 16's. */
6452 j
= k
- ((k
>> 4) << 4);
6456 if (WORDS_BIG_ENDIAN
)
6467 if (WORDS_BIG_ENDIAN
)
6472 while ((k
-= 16) > 0);
6476 /* shift not more than 16 bits */
6479 if (WORDS_BIG_ENDIAN
)
6495 /* Negate if negative */
6499 if (WORDS_BIG_ENDIAN
)
6501 for (k
= 0; k
< 4; k
++)
6503 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6504 if (WORDS_BIG_ENDIAN
)
6516 /* Longhand square root routine. */
6519 static int esqinited
= 0;
6520 static unsigned short sqrndbit
[NI
];
6527 UEMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6529 int i
, j
, k
, n
, nlups
;
6534 sqrndbit
[NI
- 2] = 1;
6537 /* Check for arg <= 0 */
6538 i
= ecmp (x
, ezero
);
6543 mtherr ("esqrt", DOMAIN
);
6559 /* Bring in the arg and renormalize if it is denormal. */
6561 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6565 /* Divide exponent by 2 */
6567 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6569 /* Adjust if exponent odd */
6579 n
= 8; /* get 8 bits of result per inner loop */
6585 /* bring in next word of arg */
6587 num
[NI
- 1] = xx
[j
+ 3];
6588 /* Do additional bit on last outer loop, for roundoff. */
6591 for (i
= 0; i
< n
; i
++)
6593 /* Next 2 bits of arg */
6596 /* Shift up answer */
6598 /* Make trial divisor */
6599 for (k
= 0; k
< NI
; k
++)
6602 eaddm (sqrndbit
, temp
);
6603 /* Subtract and insert answer bit if it goes in */
6604 if (ecmpm (temp
, num
) <= 0)
6614 /* Adjust for extra, roundoff loop done. */
6615 exp
+= (NBITS
- 1) - rndprc
;
6617 /* Sticky bit = 1 if the remainder is nonzero. */
6619 for (i
= 3; i
< NI
; i
++)
6622 /* Renormalize and round off. */
6623 emdnorm (sq
, k
, 0, exp
, !ROUND_TOWARDS_ZERO
);
6628 /* Return the binary precision of the significand for a given
6629 floating point mode. The mode can hold an integer value
6630 that many bits wide, without losing any bits. */
6633 significand_size (mode
)
6634 enum machine_mode mode
;
6637 /* Don't test the modes, but their sizes, lest this
6638 code won't work for BITS_PER_UNIT != 8 . */
6640 switch (GET_MODE_BITSIZE (mode
))
6661 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)