refresh 01-gnulib-directory.patch
[gnulib.git] / tests / test-rintl.c
1 /* Test of rintl() function.
2    Copyright (C) 2010-2011 Free Software Foundation, Inc.
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 /* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
18
19 #include <config.h>
20
21 #include <math.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (rintl, long double, (long double));
25
26 #include <float.h>
27 #include <stdio.h>
28
29 #include "fpucw.h"
30 #include "isnanl-nolibm.h"
31 #include "minus-zero.h"
32 #include "infinity.h"
33 #include "nan.h"
34 #include "macros.h"
35
36 int
37 main ()
38 {
39   DECL_LONG_DOUBLE_ROUNDING
40
41   BEGIN_LONG_DOUBLE_ROUNDING ();
42
43   /* Consider the current rounding mode, cf.
44      <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/float.h.html>  */
45   if (FLT_ROUNDS == 1)
46     {
47       /* The current rounding mode is round-to-nearest
48          (the default in IEEE 754).  */
49
50       /* Zero.  */
51       ASSERT (rintl (0.0L) == 0.0L);
52       ASSERT (rintl (minus_zerol) == 0.0L);
53       /* Positive numbers.  */
54       ASSERT (rintl (0.3L) == 0.0L);
55       ASSERT (rintl (0.5L) == 0.0L); /* unlike roundl() */
56       ASSERT (rintl (0.7L) == 1.0L);
57       ASSERT (rintl (1.0L) == 1.0L);
58       ASSERT (rintl (1.5L) == 2.0L);
59       ASSERT (rintl (1.999L) == 2.0L);
60       ASSERT (rintl (2.0L) == 2.0L);
61       ASSERT (rintl (2.1L) == 2.0L);
62       ASSERT (rintl (2.5L) == 2.0L); /* unlike roundl() */
63       ASSERT (rintl (2.7L) == 3.0L);
64       ASSERT (rintl (65535.999L) == 65536.0L);
65       ASSERT (rintl (65536.0L) == 65536.0L);
66       ASSERT (rintl (65536.001L) == 65536.0L);
67       ASSERT (rintl (2.341e31L) == 2.341e31L);
68       /* Negative numbers.  */
69       ASSERT (rintl (-0.3L) == 0.0L);
70       ASSERT (rintl (-0.5L) == 0.0L); /* unlike roundl() */
71       ASSERT (rintl (-0.7L) == -1.0L);
72       ASSERT (rintl (-1.0L) == -1.0L);
73       ASSERT (rintl (-1.5L) == -2.0L);
74       ASSERT (rintl (-1.999L) == -2.0L);
75       ASSERT (rintl (-2.0L) == -2.0L);
76       ASSERT (rintl (-2.1L) == -2.0L);
77       ASSERT (rintl (-2.5L) == -2.0L); /* unlike roundl() */
78       ASSERT (rintl (-2.7L) == -3.0L);
79       ASSERT (rintl (-65535.999L) == -65536.0L);
80       ASSERT (rintl (-65536.0L) == -65536.0L);
81       ASSERT (rintl (-65536.001L) == -65536.0L);
82       ASSERT (rintl (-2.341e31L) == -2.341e31L);
83       /* Infinite numbers.  */
84       ASSERT (rintl (Infinityl ()) == Infinityl ());
85       ASSERT (rintl (- Infinityl ()) == - Infinityl ());
86       /* NaNs.  */
87       ASSERT (isnanl (rintl (NaNl ())));
88
89       return 0;
90     }
91   else
92     {
93       fputs ("Skipping test: non-standard rounding mode\n", stderr);
94       return 77;
95     }
96 }