]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/libbid/bid64_logb.c
Update copyright years.
[thirdparty/gcc.git] / libgcc / config / libbid / bid64_logb.c
CommitLineData
a5544970 1/* Copyright (C) 2007-2019 Free Software Foundation, Inc.
200359e8
L
2
3This file is part of GCC.
4
5GCC is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free
748086b7 7Software Foundation; either version 3, or (at your option) any later
200359e8
L
8version.
9
200359e8
L
10GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11WARRANTY; without even the implied warranty of MERCHANTABILITY or
12FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13for more details.
14
748086b7
JJ
15Under Section 7 of GPL version 3, you are granted additional
16permissions described in the GCC Runtime Library Exception, version
173.1, as published by the Free Software Foundation.
18
19You should have received a copy of the GNU General Public License and
20a copy of the GCC Runtime Library Exception along with this program;
21see 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
31void
b2a00c89
L
32bid64_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
37int
38bid64_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}