attribute: Clarify which file to include.
[gnulib.git] / tests / test-modf.h
blob58154b821c5fe01f627c40ff3f1ffe436a405f03
1 /* Test of modf*() function family.
2 Copyright (C) 2012-2020 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 static void
18 test_function (void)
20 int i;
21 const DOUBLE TWO_MANT_DIG =
22 /* Assume MANT_DIG <= 5 * 31.
23 Use the identity
24 n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
25 (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
26 * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
27 * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
28 * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
29 * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
31 /* Randomized tests. */
32 for (i = 0; i < SIZEOF (RANDOM); i++)
34 DOUBLE x = RANDOM[i]; /* 0.0 <= x < 1.0 */
35 DOUBLE y;
36 DOUBLE z;
38 y = MODF (x, &z);
39 ASSERT (z == L_(0.0));
40 ASSERT (y == x);
42 y = MODF (- x, &z);
43 ASSERT (z == L_(0.0));
44 ASSERT (y == - x);
46 y = MODF (L_(1.0) + x, &z);
47 ASSERT (z == L_(1.0));
48 y -= x;
49 ASSERT (y >= - L_(1.0) / TWO_MANT_DIG);
50 ASSERT (y <= L_(1.0) / TWO_MANT_DIG);
52 y = MODF (- L_(1.0) - x, &z);
53 ASSERT (z == - L_(1.0));
54 y -= - x;
55 ASSERT (y >= - L_(1.0) / TWO_MANT_DIG);
56 ASSERT (y <= L_(1.0) / TWO_MANT_DIG);
60 volatile DOUBLE x;
61 DOUBLE y;
62 DOUBLE z;