]>
Commit | Line | Data |
---|---|---|
200359e8 L |
1 | /* Copyright (C) 2007 Free Software Foundation, Inc. |
2 | ||
3 | This file is part of GCC. | |
4 | ||
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 2, or (at your option) any later | |
8 | version. | |
9 | ||
10 | In addition to the permissions in the GNU General Public License, the | |
11 | Free Software Foundation gives you unlimited permission to link the | |
12 | compiled version of this file into combinations with other programs, | |
13 | and to distribute those combinations without any restriction coming | |
14 | from the use of this file. (The General Public License restrictions | |
15 | do apply in other respects; for example, they cover modification of | |
16 | the file, and distribution when not linked into a combine | |
17 | executable.) | |
18 | ||
19 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
20 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
22 | for more details. | |
23 | ||
24 | You should have received a copy of the GNU General Public License | |
25 | along with GCC; see the file COPYING. If not, write to the Free | |
26 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA | |
27 | 02110-1301, USA. */ | |
28 | ||
29 | #include "bid_internal.h" | |
30 | ||
31 | #define MAX_FORMAT_DIGITS 16 | |
32 | #define DECIMAL_EXPONENT_BIAS 398 | |
33 | #define MAX_DECIMAL_EXPONENT 767 | |
34 | ||
35 | #if DECIMAL_CALL_BY_REFERENCE | |
36 | ||
37 | void | |
b2a00c89 | 38 | bid64_scalb (UINT64 * pres, UINT64 * px, |
200359e8 L |
39 | int *pn _RND_MODE_PARAM _EXC_FLAGS_PARAM _EXC_MASKS_PARAM |
40 | _EXC_INFO_PARAM) { | |
41 | UINT64 x; | |
42 | int n; | |
43 | #else | |
44 | ||
45 | UINT64 | |
b2a00c89 | 46 | bid64_scalb (UINT64 x, |
200359e8 L |
47 | int n _RND_MODE_PARAM _EXC_FLAGS_PARAM _EXC_MASKS_PARAM |
48 | _EXC_INFO_PARAM) { | |
49 | #endif | |
50 | UINT64 sign_x, coefficient_x, res; | |
b2a00c89 | 51 | SINT64 exp64; |
200359e8 L |
52 | int exponent_x, rmode; |
53 | ||
54 | #if DECIMAL_CALL_BY_REFERENCE | |
55 | #if !DECIMAL_GLOBAL_ROUNDING | |
56 | _IDEC_round rnd_mode = *prnd_mode; | |
57 | #endif | |
58 | x = *px; | |
59 | n = *pn; | |
60 | #endif | |
61 | ||
62 | // unpack arguments, check for NaN or Infinity | |
63 | if (!unpack_BID64 (&sign_x, &exponent_x, &coefficient_x, x)) { | |
64 | // x is Inf. or NaN or 0 | |
b2a00c89 L |
65 | #ifdef SET_STATUS_FLAGS |
66 | if ((x & SNAN_MASK64) == SNAN_MASK64) // y is sNaN | |
67 | __set_status_flags (pfpsf, INVALID_EXCEPTION); | |
68 | #endif | |
69 | if (coefficient_x) | |
70 | res = coefficient_x & QUIET_MASK64; | |
71 | else { | |
72 | exp64 = (SINT64) exponent_x + (SINT64) n; | |
73 | if(exp64<0) exp64=0; | |
74 | if(exp64>MAX_DECIMAL_EXPONENT) exp64=MAX_DECIMAL_EXPONENT; | |
75 | exponent_x = exp64; | |
76 | res = very_fast_get_BID64 (sign_x, exponent_x, coefficient_x); // 0 | |
77 | } | |
200359e8 L |
78 | BID_RETURN (res); |
79 | } | |
80 | ||
b2a00c89 L |
81 | exp64 = (SINT64) exponent_x + (SINT64) n; |
82 | exponent_x = exp64; | |
200359e8 L |
83 | |
84 | if ((UINT32) exponent_x <= MAX_DECIMAL_EXPONENT) { | |
85 | res = very_fast_get_BID64 (sign_x, exponent_x, coefficient_x); | |
86 | BID_RETURN (res); | |
87 | } | |
88 | // check for overflow | |
b2a00c89 | 89 | if (exp64 > MAX_DECIMAL_EXPONENT) { |
200359e8 L |
90 | // try to normalize coefficient |
91 | while ((coefficient_x < 1000000000000000ull) | |
b2a00c89 | 92 | && (exp64 > MAX_DECIMAL_EXPONENT)) { |
200359e8 L |
93 | // coefficient_x < 10^15, scale by 10 |
94 | coefficient_x = (coefficient_x << 1) + (coefficient_x << 3); | |
95 | exponent_x--; | |
b2a00c89 | 96 | exp64--; |
200359e8 | 97 | } |
b2a00c89 | 98 | if (exp64 <= MAX_DECIMAL_EXPONENT) { |
200359e8 L |
99 | res = very_fast_get_BID64 (sign_x, exponent_x, coefficient_x); |
100 | BID_RETURN (res); | |
b2a00c89 L |
101 | } else |
102 | exponent_x = 0x7fffffff; // overflow | |
200359e8 L |
103 | } |
104 | // exponent < 0 | |
105 | // the BID pack routine will round the coefficient | |
106 | rmode = rnd_mode; | |
107 | res = get_BID64 (sign_x, exponent_x, coefficient_x, rmode, pfpsf); | |
108 | BID_RETURN (res); | |
109 | ||
110 | } |