annotate lib/modfl.c @ 17255:d81be792518a

update from texinfo
author Karl Berry <karl@freefriends.org>
date Tue, 01 Jan 2013 15:51:49 -0800
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16408
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Get signed integer and fractional parts of a floating-point number.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16469
diff changeset
2 Copyright (C) 2012-2013 Free Software Foundation, Inc.
16408
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Specification. */
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <math.h>
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 long double
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 modfl (long double x, long double *iptr)
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 {
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 double integer_part;
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 double fractional_part = modf (x, &integer_part);
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 *iptr = integer_part;
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 return fractional_part;
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 }
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #else
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 long double
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 modfl (long double x, long double *iptr)
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 {
16469
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
38 if (isfinite (x))
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
39 {
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
40 long double integer_part = truncl (x);
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
41 *iptr = integer_part;
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
42 return x - integer_part;
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
43 }
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
44 else
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
45 {
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
46 if (isinf (x))
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
47 {
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
48 *iptr = x;
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
49 return 1.0L / x;
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
50 }
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
51 else /* isnanl (x) */
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
52 {
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
53 *iptr = x;
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
54 return x;
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
55 }
d2bb16b4df01 modfl-ieee: Fix test failures.
Bruno Haible <bruno@clisp.org>
parents: 16408
diff changeset
56 }
16408
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 }
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58
b895d48831cd New module 'modfl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 #endif