1 /* Test of rintf() function.
2 Copyright (C) 2010-2011 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 <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
23 #include "signature.h"
24 SIGNATURE_CHECK (rintf, float, (float));
29 #include "isnanf-nolibm.h"
30 #include "minus-zero.h"
38 /* Consider the current rounding mode, cf.
39 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/float.h.html> */
42 /* The current rounding mode is round-to-nearest
43 (the default in IEEE 754). */
46 ASSERT (rintf (0.0f) == 0.0f);
47 ASSERT (rintf (minus_zerof) == 0.0f);
48 /* Positive numbers. */
49 ASSERT (rintf (0.3f) == 0.0f);
50 ASSERT (rintf (0.5f) == 0.0f); /* unlike roundf() */
51 ASSERT (rintf (0.7f) == 1.0f);
52 ASSERT (rintf (1.0f) == 1.0f);
53 ASSERT (rintf (1.5f) == 2.0f);
54 ASSERT (rintf (1.999f) == 2.0f);
55 ASSERT (rintf (2.0f) == 2.0f);
56 ASSERT (rintf (2.1f) == 2.0f);
57 ASSERT (rintf (2.5f) == 2.0f); /* unlike roundf() */
58 ASSERT (rintf (2.7f) == 3.0f);
59 ASSERT (rintf (65535.99f) == 65536.0f);
60 ASSERT (rintf (65536.0f) == 65536.0f);
61 ASSERT (rintf (65536.01f) == 65536.0f);
62 ASSERT (rintf (2.341e31f) == 2.341e31f);
63 /* Negative numbers. */
64 ASSERT (rintf (-0.3f) == 0.0f);
65 ASSERT (rintf (-0.5f) == 0.0f); /* unlike roundf() */
66 ASSERT (rintf (-0.7f) == -1.0f);
67 ASSERT (rintf (-1.0f) == -1.0f);
68 ASSERT (rintf (-1.5f) == -2.0f);
69 ASSERT (rintf (-1.999f) == -2.0f);
70 ASSERT (rintf (-2.0f) == -2.0f);
71 ASSERT (rintf (-2.1f) == -2.0f);
72 ASSERT (rintf (-2.5f) == -2.0f); /* unlike roundf() */
73 ASSERT (rintf (-2.7f) == -3.0f);
74 ASSERT (rintf (-65535.99f) == -65536.0f);
75 ASSERT (rintf (-65536.0f) == -65536.0f);
76 ASSERT (rintf (-65536.01f) == -65536.0f);
77 ASSERT (rintf (-2.341e31f) == -2.341e31f);
78 /* Infinite numbers. */
79 ASSERT (rintf (Infinityf ()) == Infinityf ());
80 ASSERT (rintf (- Infinityf ()) == - Infinityf ());
82 ASSERT (isnanf (rintf (NaNf ())));
88 fputs ("Skipping test: non-standard rounding mode\n", stderr);