annotate lib/copysignl.c @ 40186:8964917f9574

autoupdate
author Karl Berry <karl@freefriends.org>
date Mon, 18 Feb 2019 08:02:49 -0800
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15913
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Copy sign into another 'long double' number.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2011-2019 Free Software Foundation, Inc.
15913
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
15913
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Specification. */
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <math.h>
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
15922
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
22 #if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
23
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
24 long double
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
25 copysignl (long double x, long double y)
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
26 {
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
27 return copysign (x, y);
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
28 }
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
29
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
30 #else
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
31
16048
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
32 # if defined __hpux && !defined __GNUC__
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
33
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
34 # include <float.h>
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
35
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
36 /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0L. */
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
37 static long double
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
38 compute_minus_zerol (void)
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
39 {
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
40 return -LDBL_MIN * LDBL_MIN;
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
41 }
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
42 # define minus_zerol compute_minus_zerol ()
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
43
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
44 /* HP cc on HP-UX 11 has a bug: When x is a positive zero, - x comes out
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
45 as a positive zero, rather than as a minus zero. Work around it. */
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
46 static long double
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
47 unary_minus (long double x)
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
48 {
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
49 if (x == 0.0L)
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
50 {
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
51 if (signbit (x))
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
52 return 0.0L;
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
53 else
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
54 return minus_zerol;
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
55 }
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
56 else
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
57 return - x;
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
58 }
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
59
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
60 # endif
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
61
15913
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 long double
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 copysignl (long double x, long double y)
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 {
16048
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
65 # if defined __hpux && !defined __GNUC__
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
66 return (signbit (x) != signbit (y) ? unary_minus (x) : x);
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
67 # else
15913
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 return (signbit (x) != signbit (y) ? - x : x);
16048
e2ff993ff145 copysignl: Fix result for zero argument on HP-UX 11 with HP C.
Bruno Haible <bruno@clisp.org>
parents: 15922
diff changeset
69 # endif
15913
adefeca52f7d New module 'copysignl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 }
15922
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
71
e8d90530f5fd copysignl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 15913
diff changeset
72 #endif