Mercurial > hg > octave-shane > gnulib-hg
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 |
rev | line source |
---|---|
16408 | 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 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 #include <config.h> | |
18 | |
19 /* Specification. */ | |
20 #include <math.h> | |
21 | |
22 #if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE | |
23 | |
24 long double | |
25 modfl (long double x, long double *iptr) | |
26 { | |
27 double integer_part; | |
28 double fractional_part = modf (x, &integer_part); | |
29 *iptr = integer_part; | |
30 return fractional_part; | |
31 } | |
32 | |
33 #else | |
34 | |
35 long double | |
36 modfl (long double x, long double *iptr) | |
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 | 57 } |
58 | |
59 #endif |