1 /* Test nan functions payload handling (bug 16961).
2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
25 /* Avoid built-in functions. */
26 #define WRAP_NAN(FUNC, STR) \
27 ({ const char *volatile wns = (STR); FUNC (wns); })
28 #define WRAP_STRTO(FUNC, STR) \
29 ({ const char *volatile wss = (STR); FUNC (wss, NULL); })
31 #define CHECK_IS_NAN(TYPE, A) \
35 puts ("PASS: " #TYPE " " #A); \
38 puts ("FAIL: " #TYPE " " #A); \
44 #define CHECK_SAME_NAN(TYPE, A, B) \
47 if (memcmp (&(A), &(B), sizeof (A)) == 0) \
48 puts ("PASS: " #TYPE " " #A " = " #B); \
51 puts ("FAIL: " #TYPE " " #A " = " #B); \
57 #define CHECK_DIFF_NAN(TYPE, A, B) \
60 if (memcmp (&(A), &(B), sizeof (A)) != 0) \
61 puts ("PASS: " #TYPE " " #A " != " #B); \
64 puts ("FAIL: " #TYPE " " #A " != " #B); \
70 /* Cannot test payloads by memcmp for formats where NaNs have padding
72 #define CAN_TEST_EQ(MANT_DIG) ((MANT_DIG) != 64 && (MANT_DIG) != 106)
74 #define RUN_TESTS(TYPE, SFUNC, FUNC, MANT_DIG) \
77 TYPE n123 = WRAP_NAN (FUNC, "123"); \
78 CHECK_IS_NAN (TYPE, n123); \
79 TYPE s123 = WRAP_STRTO (SFUNC, "NAN(123)"); \
80 CHECK_IS_NAN (TYPE, s123); \
81 TYPE n456 = WRAP_NAN (FUNC, "456"); \
82 CHECK_IS_NAN (TYPE, n456); \
83 TYPE s456 = WRAP_STRTO (SFUNC, "NAN(456)"); \
84 CHECK_IS_NAN (TYPE, s456); \
85 TYPE n123x = WRAP_NAN (FUNC, "123)"); \
86 CHECK_IS_NAN (TYPE, n123x); \
87 TYPE nemp = WRAP_NAN (FUNC, ""); \
88 CHECK_IS_NAN (TYPE, nemp); \
89 TYPE semp = WRAP_STRTO (SFUNC, "NAN()"); \
90 CHECK_IS_NAN (TYPE, semp); \
91 TYPE sx = WRAP_STRTO (SFUNC, "NAN"); \
92 CHECK_IS_NAN (TYPE, sx); \
93 if (CAN_TEST_EQ (MANT_DIG)) \
94 CHECK_SAME_NAN (TYPE, n123, s123); \
95 if (CAN_TEST_EQ (MANT_DIG)) \
96 CHECK_SAME_NAN (TYPE, n456, s456); \
97 if (CAN_TEST_EQ (MANT_DIG)) \
98 CHECK_SAME_NAN (TYPE, nemp, semp); \
99 if (CAN_TEST_EQ (MANT_DIG)) \
100 CHECK_SAME_NAN (TYPE, n123x, sx); \
101 CHECK_DIFF_NAN (TYPE, n123, n456); \
102 CHECK_DIFF_NAN (TYPE, n123, nemp); \
103 CHECK_DIFF_NAN (TYPE, n123, n123x); \
104 CHECK_DIFF_NAN (TYPE, n456, nemp); \
105 CHECK_DIFF_NAN (TYPE, n456, n123x); \
113 RUN_TESTS (float, strtof
, nanf
, FLT_MANT_DIG
);
114 RUN_TESTS (double, strtod
, nan
, DBL_MANT_DIG
);
115 #ifndef NO_LONG_DOUBLE
116 RUN_TESTS (long double, strtold
, nanl
, LDBL_MANT_DIG
);
121 #define TEST_FUNCTION do_test ()
122 #include "../test-skeleton.c"