4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Conversion from decimal to binary floating point
35 #include "base_conversion.h"
38 * Convert the integer part of a nonzero base-10^4 _big_float *pd
39 * to base 2^16 in **ppb. The converted value is accurate to nsig
40 * significant bits. On exit, *sticky is nonzero if *pd had a
41 * nonzero fractional part. If pd->exponent > 0 and **ppb is not
42 * large enough to hold the final converted value (i.e., the con-
43 * verted significand scaled by 10^pd->exponent), then on exit,
44 * *ppb will point to a newly allocated _big_float, which must be
45 * freed by the caller. (The number of significant bits we need
46 * should fit in pb, but __big_float_times_power may allocate new
47 * storage anyway because the exact product could require more than
50 * This routine does not check that **ppb is large enough to hold
51 * the result of converting the significand of *pd.
54 __big_decimal_to_big_binary(_big_float
*pd
, int nsig
, _big_float
**ppb
,
63 /* convert pd a digit at a time, most significant first */
64 if (pd
->bexponent
+ ((pd
->blength
- 1) << 2) >= 0) {
65 pb
->bsignificand
[0] = pd
->bsignificand
[pd
->blength
- 1];
67 for (i
= pd
->blength
- 2; i
>= 0 &&
68 pd
->bexponent
+ (i
<< 2) >= 0; i
--) {
69 /* multiply pb by 10^4 and add next digit */
70 carry
= pd
->bsignificand
[i
];
71 for (j
= 0; j
< len
; j
++) {
72 carry
+= (unsigned int)pb
->bsignificand
[j
]
74 pb
->bsignificand
[j
] = carry
& 0xffff;
78 pb
->bsignificand
[j
++] = carry
;
86 /* convert any partial digit */
87 if (i
>= 0 && pd
->bexponent
+ (i
<< 2) > -4) {
88 s
= pd
->bexponent
+ (i
<< 2) + 4;
89 /* multiply pb by 10^s and add partial digit */
90 carry
= pd
->bsignificand
[i
];
94 for (j
= 0; j
< len
; j
++) {
95 carry
+= (unsigned int)pb
->bsignificand
[j
]
97 pb
->bsignificand
[j
] = carry
& 0xffff;
103 for (j
= 0; j
< len
; j
++) {
104 carry
+= (unsigned int)pb
->bsignificand
[j
]
106 pb
->bsignificand
[j
] = carry
& 0xffff;
112 for (j
= 0; j
< len
; j
++) {
113 carry
+= (unsigned int)pb
->bsignificand
[j
]
115 pb
->bsignificand
[j
] = carry
& 0xffff;
120 pb
->bsignificand
[j
++] = carry
;
130 /* continue accumulating sticky flag */
132 s
|= pd
->bsignificand
[i
--];
135 if (pd
->bexponent
> 0) {
136 /* scale pb by 10^pd->exponent */
137 __big_float_times_power(pb
, 10, pd
->bexponent
, nsig
, ppb
);
142 * Convert the decimal_record *pd to an unpacked datum *px accurately
143 * enough that *px can be rounded correctly to sigbits significant bits.
144 * (We may assume sigbits <= 113.)
147 __decimal_to_unpacked(unpacked
*px
, decimal_record
*pd
, int sigbits
)
149 _big_float d
, b
, *pbd
, *pbb
;
151 int ids
, i
, ix
, exp
, ndigs
;
152 int sticky
, powtwo
, sigdigits
;
155 px
->fpclass
= pd
->fpclass
;
160 /* remove trailing zeroes */
161 while (ndigs
> 0 && ds
[ndigs
- 1] == '0') {
167 px
->fpclass
= fp_zero
;
171 /* convert remaining digits to a base-10^4 _big_float */
172 d
.bsize
= _BIG_FLOAT_SIZE
;
174 d
.blength
= (ndigs
+ 3) >> 2;
176 ids
= ndigs
- (d
.blength
<< 2);
179 d
.bsignificand
[i
] = 100 * ds
[ids
+ 1] +
180 10 * ds
[ids
+ 2] + ds
[ids
+ 3] - 111 * '0';
186 d
.bsignificand
[i
] = 10 * ds
[ids
+ 2] + ds
[ids
+ 3] - 11 * '0';
192 d
.bsignificand
[i
] = ds
[ids
+ 3] - '0';
198 d
.bsignificand
[i
] = 1000 * ds
[ids
] + 100 * ds
[ids
+ 1] +
199 10 * ds
[ids
+ 2] + ds
[ids
+ 3] - 1111 * '0';
207 /* pre-scale to get the bits we want into the integer part */
209 /* i is a lower bound on log10(x) */
211 if (i
<= 0 || ((i
* 217705) >> 16) < sigbits
+ 2) {
213 * Scale by 2^(sigbits + 2 + u) where
214 * u is an upper bound on -log2(x).
216 powtwo
= sigbits
+ 2;
218 powtwo
+= ((-i
* 217706) + 65535) >> 16;
220 powtwo
-= (i
* 217705) >> 16;
222 * Take sigdigits large enough to get
223 * all integral digits correct.
225 sigdigits
= i
+ 1 + (((powtwo
* 19729) + 65535) >> 16);
226 __big_float_times_power(&d
, 2, powtwo
, sigdigits
, &pbd
);
230 /* convert to base 2^16 */
231 b
.bsize
= _BIG_FLOAT_SIZE
;
233 __big_decimal_to_big_binary(pbd
, sigbits
+ 2, &pbb
, &sticky
);
235 /* adjust pbb->bexponent based on the scale factor above */
236 pbb
->bexponent
-= powtwo
;
238 /* convert to unpacked */
240 for (i
= pbb
->blength
- 1; i
> 0 && ix
< 5; i
-= 2) {
241 px
->significand
[ix
++] = (pbb
->bsignificand
[i
] << 16) |
242 pbb
->bsignificand
[i
- 1];
245 /* pad with zeroes */
247 px
->significand
[ix
++] = pbb
->bsignificand
[i
] << 16;
249 px
->significand
[ix
++] = 0;
251 /* truncate and set a sticky bit if necessary */
252 while (i
>= 0 && pbb
->bsignificand
[i
] == 0)
255 px
->significand
[4] |= 1;
257 if (sticky
| pd
->more
)
258 px
->significand
[4] |= 1;
259 px
->exponent
= pbb
->bexponent
+ (pbb
->blength
<< 4) - 1;
261 /* normalize so the most significant bit is set */
262 while (px
->significand
[0] < 0x80000000u
) {
263 px
->significand
[0] = (px
->significand
[0] << 1) |
264 (px
->significand
[1] >> 31);
265 px
->significand
[1] = (px
->significand
[1] << 1) |
266 (px
->significand
[2] >> 31);
267 px
->significand
[2] = (px
->significand
[2] << 1) |
268 (px
->significand
[3] >> 31);
269 px
->significand
[3] = (px
->significand
[3] << 1) |
270 (px
->significand
[4] >> 31);
271 px
->significand
[4] <<= 1;
276 (void) free((void *)pbd
);
278 (void) free((void *)pbb
);
282 * Convert a string s consisting of n <= 18 ASCII decimal digits
283 * to an integer value in double precision format, and set *pe
284 * to the number of rounding errors incurred (0 or 1).
287 __digits_to_double(char *s
, int n
, int *pe
)
294 for (i
= 1; i
< n
; i
++) {
295 /* acc <- 10 * acc + next digit */
296 acc
= (acc
<< 1) + (acc
<< 3) + s
[i
] - '0';
302 for (i
= 1; i
< (n
- 9); i
++) {
303 /* acc <- 10 * acc + next digit */
304 acc
= (acc
<< 1) + (acc
<< 3) + s
[i
] - '0';
306 th
= 1.0e9
* (double)acc
; /* this will be exact */
307 acc
= s
[n
- 9] - '0';
308 for (i
= n
- 8; i
< n
; i
++) {
309 /* acc <- 10 * acc + next digit */
310 acc
= (acc
<< 1) + (acc
<< 3) + s
[i
] - '0';
313 /* add and indicate whether or not the sum is exact */
315 *pe
= ((t
- th
) == tl
)? 0 : 1;
324 #ifdef _LITTLE_ENDIAN
325 { 0x00000000, 0x3cc40000 },
327 { 0x3cc40000, 0x00000000 }, /* 5 * 2^-53 */
331 #define five2m53 C[0].d
334 __fast_decimal_to_single(single
*px
, decimal_mode
*pm
, decimal_record
*pd
,
335 fp_exception_field_type
*ps
)
337 double dds
, delta
, ddsplus
, ddsminus
, df1
;
338 int n
, exp
, rounded
, e
;
340 __ieee_flags_type fb
;
342 if (pm
->rd
!= fp_nearest
)
346 if (pd
->ndigits
<= 18) {
352 exp
+= pd
->ndigits
- 18;
355 * exp must be in the range of the table, and the result
356 * must not underflow or overflow.
358 if (exp
< -__TBL_TENS_MAX
|| exp
+ n
< -36 || exp
+ n
> 38)
361 __get_ieee_flags(&fb
);
362 dds
= __digits_to_double(pd
->ds
, n
, &e
);
366 /* small positive exponent */
367 if (exp
> __TBL_TENS_EXACT
)
370 dds
*= __tbl_tens
[exp
];
372 dds
= __mul_set(dds
, __tbl_tens
[exp
], &e
);
376 } else if (exp
< 0) {
377 /* small negative exponent */
378 if (-exp
> __TBL_TENS_EXACT
)
381 dds
/= __tbl_tens
[-exp
];
383 dds
= __div_set(dds
, __tbl_tens
[-exp
], &e
);
390 * At this point dds may have four rounding errors due to
391 * (i) truncation of pd->ds to 18 digits, (ii) inexact con-
392 * version of pd->ds to binary, (iii) scaling by a power of
393 * ten that is not exactly representable, and (iv) roundoff
394 * error in the multiplication. Below we will incur one more
395 * rounding error when we add or subtract delta and dds. We
396 * construct delta so that even after this last rounding error,
397 * ddsplus is an upper bound on the exact value and ddsminus
398 * is a lower bound. Then as long as both of these quantities
399 * round to the same single precision number, that number
400 * will be the correctly rounded single precision result.
401 * (If any rounding errors have been committed, then we must
402 * also be certain that the result can't be exact.)
404 delta
= five2m53
* dds
;
405 ddsplus
= dds
+ delta
;
406 ddsminus
= dds
- delta
;
407 f1
= (float)(ddsplus
);
408 f2
= (float)(ddsminus
);
410 __set_ieee_flags(&fb
);
415 * If ddsminus <= f1 <= ddsplus, the result might be
416 * exact; we have to convert the long way to be sure.
418 if (ddsminus
<= df1
&& df1
<= ddsplus
)
420 *ps
= (1 << fp_inexact
);
422 *ps
= (df1
== dds
)? 0 : (1 << fp_inexact
);
424 *px
= (pd
->sign
)? -f1
: f1
;
429 * Attempt conversion to double using floating-point arithmetic.
430 * Return 1 if it works (at most one rounding error), 0 if it doesn't.
433 __fast_decimal_to_double(double *px
, decimal_mode
*pm
, decimal_record
*pd
,
434 fp_exception_field_type
*ps
)
438 __ieee_flags_type fb
;
440 if (pm
->rd
!= fp_nearest
|| pd
->ndigits
> 18 || pd
->exponent
441 > __TBL_TENS_EXACT
|| pd
->exponent
< -__TBL_TENS_EXACT
)
444 __get_ieee_flags(&fb
);
445 dds
= __digits_to_double(pd
->ds
, pd
->ndigits
, &e
);
447 __set_ieee_flags(&fb
);
450 if (pd
->exponent
> 0)
451 dds
= __mul_set(dds
, __tbl_tens
[pd
->exponent
], &e
);
452 else if (pd
->exponent
< 0)
453 dds
= __div_set(dds
, __tbl_tens
[-pd
->exponent
], &e
);
454 *px
= (pd
->sign
)? -dds
: dds
;
455 *ps
= (e
)? (1 << fp_inexact
) : 0;
456 __set_ieee_flags(&fb
);
460 /* PUBLIC FUNCTIONS */
463 * The following routines convert the decimal record *pd to a floating
464 * point value *px observing the rounding mode specified in pm->rd and
465 * passing back any floating point exceptions that occur in *ps.
467 * pd->sign and pd->fpclass are always taken into account. pd->exponent
468 * and pd->ds are used when pd->fpclass is fp_normal or fp_subnormal.
469 * In these cases, pd->ds must contain a null-terminated string of one
470 * or more ASCII digits, the first of which is not zero, and pd->ndigits
471 * must equal the length of this string. If m is the integer represented
472 * by the string pd->ds, then *px will be set to a correctly rounded
475 * -1**(pd->sign) * m * 10**(pd->exponent)
477 * (If pd->more != 0 then additional nonzero digits are assumed to follow
478 * those in pd->ds, so m is effectively replaced by m + epsilon in the
481 * For example, if pd->exponent == -2 and pd->ds holds "1234", then *px
482 * will be a correctly rounded approximation to 12.34.
484 * Note that the only mode that matters is the rounding direction pm->rd;
485 * pm->df and pm->ndigits are never used.
488 /* maximum decimal exponent we need to consider */
489 #define SINGLE_MAXE 47
490 #define DOUBLE_MAXE 326
491 #define EXTENDED_MAXE 4968
492 #define QUAD_MAXE 4968
495 decimal_to_single(single
*px
, decimal_mode
*pm
, decimal_record
*pd
,
496 fp_exception_field_type
*ps
)
498 single_equivalence
*kluge
;
500 fp_exception_field_type ef
;
504 kluge
= (single_equivalence
*)px
;
505 switch (pd
->fpclass
) {
507 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
508 kluge
->f
.msw
.exponent
= 0;
509 kluge
->f
.msw
.significand
= 0;
514 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
515 kluge
->f
.msw
.exponent
= 0xff;
516 kluge
->f
.msw
.significand
= 0;
521 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
522 kluge
->f
.msw
.exponent
= 0xff;
523 kluge
->f
.msw
.significand
= 0x7fffff;
528 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
529 kluge
->f
.msw
.exponent
= 0xff;
530 kluge
->f
.msw
.significand
= 0x3fffff;
537 if (pd
->exponent
+ pd
->ndigits
> SINGLE_MAXE
) {
538 /* result must overflow */
539 u
.sign
= (pd
->sign
!= 0);
540 u
.fpclass
= fp_normal
;
541 u
.exponent
= 0x000fffff;
542 u
.significand
[0] = 0x80000000;
543 for (i
= 1; i
< UNPACKED_SIZE
; i
++)
544 u
.significand
[i
] = 0;
545 } else if (pd
->exponent
+ pd
->ndigits
< -SINGLE_MAXE
) {
546 /* result must underflow completely */
547 u
.sign
= (pd
->sign
!= 0);
548 u
.fpclass
= fp_normal
;
549 u
.exponent
= -0x000fffff;
550 u
.significand
[0] = 0x80000000;
551 for (i
= 1; i
< UNPACKED_SIZE
; i
++)
552 u
.significand
[i
] = 0;
554 /* result may be in range */
555 if (__fast_decimal_to_single(px
, pm
, pd
, &ef
) == 1) {
558 __base_conversion_set_exception(ef
);
561 __decimal_to_unpacked(&u
, pd
, 24);
563 __pack_single(&u
, px
, pm
->rd
, &ef
);
566 __base_conversion_set_exception(ef
);
570 decimal_to_double(double *px
, decimal_mode
*pm
, decimal_record
*pd
,
571 fp_exception_field_type
*ps
)
573 double_equivalence
*kluge
;
575 fp_exception_field_type ef
;
579 kluge
= (double_equivalence
*)px
;
580 switch (pd
->fpclass
) {
582 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
583 kluge
->f
.msw
.exponent
= 0;
584 kluge
->f
.msw
.significand
= 0;
585 kluge
->f
.significand2
= 0;
590 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
591 kluge
->f
.msw
.exponent
= 0x7ff;
592 kluge
->f
.msw
.significand
= 0;
593 kluge
->f
.significand2
= 0;
598 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
599 kluge
->f
.msw
.exponent
= 0x7ff;
600 kluge
->f
.msw
.significand
= 0xfffff;
601 kluge
->f
.significand2
= 0xffffffff;
606 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
607 kluge
->f
.msw
.exponent
= 0x7ff;
608 kluge
->f
.msw
.significand
= 0x7ffff;
609 kluge
->f
.significand2
= 0xffffffff;
616 if (pd
->exponent
+ pd
->ndigits
> DOUBLE_MAXE
) {
617 /* result must overflow */
618 u
.sign
= (pd
->sign
!= 0);
619 u
.fpclass
= fp_normal
;
620 u
.exponent
= 0x000fffff;
621 u
.significand
[0] = 0x80000000;
622 for (i
= 1; i
< UNPACKED_SIZE
; i
++)
623 u
.significand
[i
] = 0;
624 } else if (pd
->exponent
+ pd
->ndigits
< -DOUBLE_MAXE
) {
625 /* result must underflow completely */
626 u
.sign
= (pd
->sign
!= 0);
627 u
.fpclass
= fp_normal
;
628 u
.exponent
= -0x000fffff;
629 u
.significand
[0] = 0x80000000;
630 for (i
= 1; i
< UNPACKED_SIZE
; i
++)
631 u
.significand
[i
] = 0;
633 /* result may be in range */
634 if (__fast_decimal_to_double(px
, pm
, pd
, &ef
) == 1) {
637 __base_conversion_set_exception(ef
);
640 __decimal_to_unpacked(&u
, pd
, 53);
642 __pack_double(&u
, px
, pm
->rd
, &ef
);
645 __base_conversion_set_exception(ef
);
649 decimal_to_extended(extended
*px
, decimal_mode
*pm
, decimal_record
*pd
,
650 fp_exception_field_type
*ps
)
652 extended_equivalence
*kluge
;
654 double_equivalence dd
;
655 fp_exception_field_type ef
;
659 kluge
= (extended_equivalence
*)px
;
660 switch (pd
->fpclass
) {
662 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
663 kluge
->f
.msw
.exponent
= 0;
664 kluge
->f
.significand
= 0;
665 kluge
->f
.significand2
= 0;
670 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
671 kluge
->f
.msw
.exponent
= 0x7fff;
672 kluge
->f
.significand
= 0x80000000;
673 kluge
->f
.significand2
= 0;
678 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
679 kluge
->f
.msw
.exponent
= 0x7fff;
680 kluge
->f
.significand
= 0xffffffff;
681 kluge
->f
.significand2
= 0xffffffff;
686 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
687 kluge
->f
.msw
.exponent
= 0x7fff;
688 kluge
->f
.significand
= 0xbfffffff;
689 kluge
->f
.significand2
= 0xffffffff;
696 if (pd
->exponent
+ pd
->ndigits
> EXTENDED_MAXE
) {
697 /* result must overflow */
698 u
.sign
= (pd
->sign
!= 0);
699 u
.fpclass
= fp_normal
;
700 u
.exponent
= 0x000fffff;
701 u
.significand
[0] = 0x80000000;
702 for (i
= 1; i
< UNPACKED_SIZE
; i
++)
703 u
.significand
[i
] = 0;
704 } else if (pd
->exponent
+ pd
->ndigits
< -EXTENDED_MAXE
) {
705 /* result must underflow completely */
706 u
.sign
= (pd
->sign
!= 0);
707 u
.fpclass
= fp_normal
;
708 u
.exponent
= -0x000fffff;
709 u
.significand
[0] = 0x80000000;
710 for (i
= 1; i
< UNPACKED_SIZE
; i
++)
711 u
.significand
[i
] = 0;
713 /* result may be in range */
714 if (__fast_decimal_to_double(&dd
.x
, pm
, pd
, &ef
) == 1 &&
716 u
.sign
= dd
.f
.msw
.sign
;
717 u
.fpclass
= fp_normal
;
718 u
.exponent
= dd
.f
.msw
.exponent
- DOUBLE_BIAS
;
719 u
.significand
[0] = ((0x100000 |
720 dd
.f
.msw
.significand
) << 11) |
721 (dd
.f
.significand2
>> 21);
722 u
.significand
[1] = dd
.f
.significand2
<< 11;
723 for (i
= 2; i
< UNPACKED_SIZE
; i
++)
724 u
.significand
[i
] = 0;
726 __decimal_to_unpacked(&u
, pd
, 64);
729 __pack_extended(&u
, px
, pm
->rd
, &ef
);
732 __base_conversion_set_exception(ef
);
736 decimal_to_quadruple(quadruple
*px
, decimal_mode
*pm
, decimal_record
*pd
,
737 fp_exception_field_type
*ps
)
739 quadruple_equivalence
*kluge
;
741 double_equivalence dd
;
742 fp_exception_field_type ef
;
746 kluge
= (quadruple_equivalence
*)px
;
747 switch (pd
->fpclass
) {
749 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
750 kluge
->f
.msw
.exponent
= 0;
751 kluge
->f
.msw
.significand
= 0;
752 kluge
->f
.significand2
= 0;
753 kluge
->f
.significand3
= 0;
754 kluge
->f
.significand4
= 0;
759 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
760 kluge
->f
.msw
.exponent
= 0x7fff;
761 kluge
->f
.msw
.significand
= 0;
762 kluge
->f
.significand2
= 0;
763 kluge
->f
.significand3
= 0;
764 kluge
->f
.significand4
= 0;
769 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
770 kluge
->f
.msw
.exponent
= 0x7fff;
771 kluge
->f
.msw
.significand
= 0xffff;
772 kluge
->f
.significand2
= 0xffffffff;
773 kluge
->f
.significand3
= 0xffffffff;
774 kluge
->f
.significand4
= 0xffffffff;
779 kluge
->f
.msw
.sign
= (pd
->sign
)? 1 : 0;
780 kluge
->f
.msw
.exponent
= 0x7fff;
781 kluge
->f
.msw
.significand
= 0x7fff;
782 kluge
->f
.significand2
= 0xffffffff;
783 kluge
->f
.significand3
= 0xffffffff;
784 kluge
->f
.significand4
= 0xffffffff;
791 if (pd
->exponent
+ pd
->ndigits
> QUAD_MAXE
) {
792 /* result must overflow */
793 u
.sign
= (pd
->sign
!= 0);
794 u
.fpclass
= fp_normal
;
795 u
.exponent
= 0x000fffff;
796 u
.significand
[0] = 0x80000000;
797 for (i
= 1; i
< UNPACKED_SIZE
; i
++)
798 u
.significand
[i
] = 0;
799 } else if (pd
->exponent
+ pd
->ndigits
< -QUAD_MAXE
) {
800 /* result must underflow completely */
801 u
.sign
= (pd
->sign
!= 0);
802 u
.fpclass
= fp_normal
;
803 u
.exponent
= -0x000fffff;
804 u
.significand
[0] = 0x80000000;
805 for (i
= 1; i
< UNPACKED_SIZE
; i
++)
806 u
.significand
[i
] = 0;
808 /* result may be in range */
809 if (__fast_decimal_to_double(&dd
.x
, pm
, pd
, &ef
) == 1 &&
811 u
.sign
= dd
.f
.msw
.sign
;
812 u
.fpclass
= fp_normal
;
813 u
.exponent
= dd
.f
.msw
.exponent
- DOUBLE_BIAS
;
814 u
.significand
[0] = ((0x100000 |
815 dd
.f
.msw
.significand
) << 11) |
816 (dd
.f
.significand2
>> 21);
817 u
.significand
[1] = dd
.f
.significand2
<< 11;
818 for (i
= 2; i
< UNPACKED_SIZE
; i
++)
819 u
.significand
[i
] = 0;
821 __decimal_to_unpacked(&u
, pd
, 113);
824 __pack_quadruple(&u
, px
, pm
->rd
, &ef
);
827 __base_conversion_set_exception(ef
);