Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/logb.c @ 17426:90f3d53e01f5
sig2str: port to C++
* lib/sig2str.h (sig2str, str2sig): Declare as extern "C".
Reported by Daniel J Sebald in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-06/msg00000.html>.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sun, 02 Jun 2013 11:52:41 -0700 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
16751
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Floating-point exponent. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16751
diff
changeset
|
2 Copyright (C) 2012-2013 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 |
9d599e388a0f
logb: Provide replacement and workarounds.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
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 } |