Mercurial > gnulib
annotate lib/logb.c @ 40231:9b3c79fdfe0b
strtod: fix clash with strtold
Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817).
* lib/strtod.c (compute_minus_zero, minus_zero):
Simplify by remving the macro / external variable,
and having just a function. User changed. This avoids
the need for an external variable that might clash.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 11 Mar 2019 16:40:29 -0700 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
16751
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Floating-point exponent. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2012-2019 Free Software Foundation, Inc. |
16751
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
19190 | 15 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
16751
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 #if ! (defined USE_LONG_DOUBLE || defined USE_FLOAT) |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 # include <config.h> |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #endif |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 /* Specification. */ |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 #include <math.h> |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #ifdef USE_LONG_DOUBLE |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 # define LOGB logbl |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 # define DOUBLE long double |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 # define L_(literal) literal##L |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 # define HUGEVAL HUGE_VALL |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 # define FREXP frexpl |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 # define ISNAN isnanl |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 #elif ! defined USE_FLOAT |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 # define LOGB logb |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 # define DOUBLE double |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 # define L_(literal) literal |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 # define HUGEVAL HUGE_VAL |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 # define FREXP frexp |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 # define ISNAN isnand |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 #else /* defined USE_FLOAT */ |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 # define LOGB logbf |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 # define DOUBLE float |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 # define L_(literal) literal##f |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 # define HUGEVAL HUGE_VALF |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 # define FREXP frexpf |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 # define ISNAN isnanf |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 #endif |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 DOUBLE |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 LOGB (DOUBLE x) |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 { |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 if (isfinite (x)) |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 { |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 if (x == L_(0.0)) |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 /* Return -Infinity. */ |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 return - HUGEVAL; |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 else |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 { |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 int e; |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 (void) FREXP (x, &e); |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 return (DOUBLE) (e - 1); |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 } |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 } |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 else |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 { |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 if (ISNAN (x)) |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 return x; /* NaN */ |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 else |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 /* Return +Infinity. */ |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 return HUGEVAL; |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 } |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 } |