Quash warning in s_sincosl.
[platform/upstream/glibc.git] / stdio-common / tst-sprintf3.c
1 /* Copyright (C) 2012 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library 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 GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
17
18 /* Test bug #13941.  */
19
20 #include <float.h>
21 #include <math.h>
22 #include <stdio.h>
23 #include <string.h>
24
25 int
26 main (void)
27 {
28 #if LDBL_MANT_DIG >= 106
29   volatile union { long double l; long long x[2]; } u, v;
30   char buf[64];
31 #endif
32   int result = 0;
33
34 #if LDBL_MANT_DIG == 106 || LDBL_MANT_DIG == 113
35 # define COMPARE_LDBL(u, v) \
36   ((u).l == (v).l && (u).x[0] == (v).x[0] && (u).x[1] == (v).x[1])
37 #else
38 # define COMPARE_LDBL(u, v) ((u).l == (v).l)
39 #endif
40
41 #define TEST(val) \
42   do                                                                       \
43     {                                                                      \
44       u.l = (val);                                                         \
45       snprintf (buf, sizeof buf, "%.30LgL", u.l);                          \
46       if (strcmp (buf, #val) != 0)                                         \
47         {                                                                  \
48           printf ("Error on line %d: %s != %s\n", __LINE__, buf, #val);    \
49           result = 1;                                                      \
50         }                                                                  \
51       if (sscanf (#val, "%Lg", &v.l) != 1 || !COMPARE_LDBL (u, v))         \
52         {                                                                  \
53           printf ("Error sscanf on line %d: %.30Lg != %.30Lg\n", __LINE__, \
54                   u.l, v.l);                                               \
55           result = 1;                                                      \
56         }                                                                  \
57       /* printf ("%s %Lg %016Lx %016Lx\n", #val, u.l, u.x[0], u.x[1]); */  \
58     }                                                                      \
59   while (0)
60
61 #if LDBL_MANT_DIG >= 106
62 # if LDBL_MANT_DIG == 106
63   TEST (2.22507385850719347803989925739e-308L);
64   TEST (2.22507385850719397210554509863e-308L);
65   TEST (2.22507385850720088902458687609e-308L);
66 # endif
67   TEST (2.22507385850720138309023271733e-308L);
68   TEST (2.22507385850720187715587855858e-308L);
69   TEST (2.2250738585074419930597574044e-308L);
70   TEST (4.45014771701440227211481959342e-308L);
71   TEST (4.45014771701440276618046543466e-308L);
72   TEST (4.45014771701440375431175711716e-308L);
73   TEST (4.45014771701440474244304879965e-308L);
74   TEST (7.12023634722304600689881138745e-307L);
75   TEST (1.13923781555569064960474854133e-305L);
76   TEST (1.13777777777777776389998996996L);
77   TEST (1.13777777777777765287768750745L);
78   TEST (20988295479420645138.2044444444L);
79   TEST (20988295479420643090.2044444444L);
80   TEST (2.14668699894294423266045294316e-292L);
81 # if LDBL_MANT_DIG == 106
82   TEST (-2.35993711055432139266626434123e-292L);
83   TEST (6.26323524637968345414769634658e-302L);
84   TEST (1.49327164802066885331814201989e-308L);
85   TEST (3.71834550652787023640837473722e-308L);
86   TEST (9.51896449671134907001349268087e-306L);
87 # endif
88 #endif
89   return result;
90 }