1 /* Common utilities for testing strtod and its derivatives.
2    This file is part of the GNU C Library.
3    Copyright (C) 2016-2022 Free Software Foundation, Inc.
4 
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.
9 
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.
14 
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    <https://www.gnu.org/licenses/>.  */
18 
19 #ifndef _TST_STRTOD_H
20 #define _TST_STRTOD_H
21 
22 #define FSTRLENMAX 128
23 
24 #include <bits/floatn.h>
25 
26 #define F16 __f16 ()
27 #define F32 __f32 ()
28 #define F64 __f64 ()
29 #define F128 __f128 ()
30 #define F32X __f32x ()
31 #define F64X __f64x ()
32 #define F128X __f128x ()
33 
34 /* Test strfromfN and strtofN on all platforms that provide them,
35    whether or not the type _FloatN is ABI-distinct from other types;
36    likewise _FloatNx functions.  */
37 #if __HAVE_FLOAT16
38 # define IF_FLOAT16(x) x
39 #else
40 # define IF_FLOAT16(x)
41 #endif
42 
43 #if __HAVE_FLOAT32
44 # define IF_FLOAT32(x) x
45 #else
46 # define IF_FLOAT32(x)
47 #endif
48 
49 #if __HAVE_FLOAT64
50 # define IF_FLOAT64(x) x
51 #else
52 # define IF_FLOAT64(x)
53 #endif
54 
55 #if __HAVE_FLOAT128
56 # define IF_FLOAT128(x) x
57 #else
58 # define IF_FLOAT128(x)
59 #endif
60 
61 #if __HAVE_FLOAT32X
62 # define IF_FLOAT32X(x) x
63 #else
64 # define IF_FLOAT32X(x)
65 #endif
66 
67 #if __HAVE_FLOAT64X
68 # define IF_FLOAT64X(x) x
69 #else
70 # define IF_FLOAT64X(x)
71 #endif
72 
73 #if __HAVE_FLOAT128X
74 # define IF_FLOAT128X(x) x
75 #else
76 # define IF_FLOAT128X(x)
77 #endif
78 
79 /* Provide an extra parameter expansion for mfunc.  */
80 #define MMFUNC(mmfunc, ...) mmfunc (__VA_ARGS__)
81 
82 /* Splat n variants of the same test for the various strtod functions.  */
83 #define GEN_TEST_STRTOD_FOREACH(mfunc, ...)				      \
84   mfunc (  f,       float, strfromf, f, f, ##__VA_ARGS__)		      \
85   mfunc (  d,      double, strfromd,  ,  , ##__VA_ARGS__)		      \
86   mfunc ( ld, long double, strfroml, L, l, ##__VA_ARGS__)		      \
87   IF_FLOAT16 (MMFUNC							      \
88    (mfunc, f16, _Float16, strfromf16, F16, f16, ##__VA_ARGS__))		      \
89   IF_FLOAT32 (MMFUNC							      \
90    (mfunc, f32, _Float32, strfromf32, F32, f32, ##__VA_ARGS__))		      \
91   IF_FLOAT64 (MMFUNC							      \
92    (mfunc, f64, _Float64, strfromf64, F64, f64, ##__VA_ARGS__))		      \
93   IF_FLOAT128 (MMFUNC							      \
94    (mfunc, f128, _Float128, strfromf128, F128, f128, ##__VA_ARGS__))	      \
95   IF_FLOAT32X (MMFUNC							      \
96    (mfunc, f32x, _Float32x, strfromf32x, F32X, f32x, ##__VA_ARGS__))	      \
97   IF_FLOAT64X (MMFUNC							      \
98    (mfunc, f64x, _Float64x, strfromf64x, F64X, f64x, ##__VA_ARGS__))	      \
99   IF_FLOAT128X (MMFUNC							      \
100    (mfunc, f128x, _Float128x, strfromf128x, F128X, f128x, ##__VA_ARGS__))
101 /* The arguments to the generated macros are:
102    FSUF - Function suffix
103    FTYPE - float type
104    FTOSTR - float to string func
105    LSUF - Literal suffix
106    CSUF - C standardish suffix for many of the math functions
107 */
108 
109 
110 
111 #define STRTOD_TEST_FOREACH(mfunc, ...)				\
112 ({								\
113    int result = 0;						\
114    result |= mfunc ## f  (__VA_ARGS__);				\
115    result |= mfunc ## d  (__VA_ARGS__);				\
116    result |= mfunc ## ld (__VA_ARGS__);				\
117    IF_FLOAT16 (result |= mfunc ## f16 (__VA_ARGS__));		\
118    IF_FLOAT32 (result |= mfunc ## f32 (__VA_ARGS__));		\
119    IF_FLOAT64 (result |= mfunc ## f64 (__VA_ARGS__));		\
120    IF_FLOAT128 (result |= mfunc ## f128 (__VA_ARGS__));		\
121    IF_FLOAT32X (result |= mfunc ## f32x (__VA_ARGS__));		\
122    IF_FLOAT64X (result |= mfunc ## f64x (__VA_ARGS__));		\
123    IF_FLOAT128X (result |= mfunc ## f128x (__VA_ARGS__));	\
124    result;							\
125 })
126 
127 
128 #endif
129