]>
Commit | Line | Data |
---|---|---|
a5544970 | 1 | /* Copyright (C) 2007-2019 Free Software Foundation, Inc. |
200359e8 L |
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 | |
748086b7 | 7 | Software Foundation; either version 3, or (at your option) any later |
200359e8 L |
8 | version. |
9 | ||
200359e8 L |
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 | |
13 | for more details. | |
14 | ||
748086b7 JJ |
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. | |
18 | ||
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/>. */ | |
200359e8 L |
23 | |
24 | #include "bid_internal.h" | |
25 | ||
26 | #define MAX_FORMAT_DIGITS 16 | |
27 | #define DECIMAL_EXPONENT_BIAS 398 | |
28 | ||
29 | #if DECIMAL_CALL_BY_REFERENCE | |
30 | ||
31 | void | |
b2a00c89 L |
32 | bid64_logb (int * pres, UINT64 * px |
33 | _EXC_FLAGS_PARAM _EXC_MASKS_PARAM _EXC_INFO_PARAM) { | |
200359e8 L |
34 | UINT64 x; |
35 | #else | |
36 | ||
b2a00c89 L |
37 | int |
38 | bid64_logb (UINT64 x _EXC_FLAGS_PARAM _EXC_MASKS_PARAM _EXC_INFO_PARAM) { | |
200359e8 | 39 | #endif |
b2a00c89 L |
40 | UINT64 sign_x, coefficient_x; |
41 | int_double dx; | |
42 | int exponent_x, bin_expon_cx, digits; | |
200359e8 L |
43 | |
44 | #if DECIMAL_CALL_BY_REFERENCE | |
200359e8 L |
45 | x = *px; |
46 | #endif | |
200359e8 L |
47 | // unpack arguments, check for NaN or Infinity |
48 | if (!unpack_BID64 (&sign_x, &exponent_x, &coefficient_x, x)) { | |
49 | // x is Inf. or NaN | |
200359e8 | 50 | #ifdef SET_STATUS_FLAGS |
b2a00c89 | 51 | __set_status_flags (pfpsf, INVALID_EXCEPTION); |
200359e8 | 52 | #endif |
b2a00c89 | 53 | BID_RETURN (0x80000000); |
200359e8 | 54 | } |
b2a00c89 L |
55 | // find number of digits in coefficient |
56 | if (coefficient_x >= 1000000000000000ull) { | |
57 | digits = 16; | |
58 | } else { | |
59 | dx.d = (double)coefficient_x; // exact conversion; | |
60 | bin_expon_cx = (int)(dx.i >> 52) - 1023; | |
61 | digits = estimate_decimal_digits[bin_expon_cx]; | |
62 | if (coefficient_x >= power10_table_128[digits].w[0]) | |
63 | digits++; | |
64 | } | |
65 | exponent_x = exponent_x - DECIMAL_EXPONENT_BIAS + digits - 1; | |
200359e8 | 66 | |
b2a00c89 | 67 | BID_RETURN (exponent_x); |
200359e8 | 68 | } |