1 /* Copyright (C) 2007-2016 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 3, or (at your option) any later
10 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
24 #include "bid_internal.h"
26 #define MAX_FORMAT_DIGITS 16
27 #define DECIMAL_EXPONENT_BIAS 398
28 #define MAX_DECIMAL_EXPONENT 767
30 #if DECIMAL_CALL_BY_REFERENCE
33 bid64_scalb (UINT64
* pres
, UINT64
* px
,
34 int *pn _RND_MODE_PARAM _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
41 bid64_scalb (UINT64 x
,
42 int n _RND_MODE_PARAM _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
45 UINT64 sign_x
, coefficient_x
, res
;
47 int exponent_x
, rmode
;
49 #if DECIMAL_CALL_BY_REFERENCE
50 #if !DECIMAL_GLOBAL_ROUNDING
51 _IDEC_round rnd_mode
= *prnd_mode
;
57 // unpack arguments, check for NaN or Infinity
58 if (!unpack_BID64 (&sign_x
, &exponent_x
, &coefficient_x
, x
)) {
59 // x is Inf. or NaN or 0
60 #ifdef SET_STATUS_FLAGS
61 if ((x
& SNAN_MASK64
) == SNAN_MASK64
) // y is sNaN
62 __set_status_flags (pfpsf
, INVALID_EXCEPTION
);
65 res
= coefficient_x
& QUIET_MASK64
;
67 exp64
= (SINT64
) exponent_x
+ (SINT64
) n
;
69 if(exp64
>MAX_DECIMAL_EXPONENT
) exp64
=MAX_DECIMAL_EXPONENT
;
71 res
= very_fast_get_BID64 (sign_x
, exponent_x
, coefficient_x
); // 0
76 exp64
= (SINT64
) exponent_x
+ (SINT64
) n
;
79 if ((UINT32
) exponent_x
<= MAX_DECIMAL_EXPONENT
) {
80 res
= very_fast_get_BID64 (sign_x
, exponent_x
, coefficient_x
);
84 if (exp64
> MAX_DECIMAL_EXPONENT
) {
85 // try to normalize coefficient
86 while ((coefficient_x
< 1000000000000000ull)
87 && (exp64
> MAX_DECIMAL_EXPONENT
)) {
88 // coefficient_x < 10^15, scale by 10
89 coefficient_x
= (coefficient_x
<< 1) + (coefficient_x
<< 3);
93 if (exp64
<= MAX_DECIMAL_EXPONENT
) {
94 res
= very_fast_get_BID64 (sign_x
, exponent_x
, coefficient_x
);
97 exponent_x
= 0x7fffffff; // overflow
100 // the BID pack routine will round the coefficient
102 res
= get_BID64 (sign_x
, exponent_x
, coefficient_x
, rmode
, pfpsf
);