tst-strtod.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Common utilities for testing strtod and its derivatives.
  2. This file is part of the GNU C Library.
  3. Copyright (C) 2016-2019 Free Software Foundation, Inc.
  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. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _TST_STRTOD_H
  16. #define _TST_STRTOD_H
  17. #define FSTRLENMAX 128
  18. #include <bits/floatn.h>
  19. #define F16 __f16 ()
  20. #define F32 __f32 ()
  21. #define F64 __f64 ()
  22. #define F128 __f128 ()
  23. #define F32X __f32x ()
  24. #define F64X __f64x ()
  25. #define F128X __f128x ()
  26. /* Test strfromfN and strtofN on all platforms that provide them,
  27. whether or not the type _FloatN is ABI-distinct from other types;
  28. likewise _FloatNx functions. */
  29. #if __HAVE_FLOAT16
  30. # define IF_FLOAT16(x) x
  31. #else
  32. # define IF_FLOAT16(x)
  33. #endif
  34. #if __HAVE_FLOAT32
  35. # define IF_FLOAT32(x) x
  36. #else
  37. # define IF_FLOAT32(x)
  38. #endif
  39. #if __HAVE_FLOAT64
  40. # define IF_FLOAT64(x) x
  41. #else
  42. # define IF_FLOAT64(x)
  43. #endif
  44. #if __HAVE_FLOAT128
  45. # define IF_FLOAT128(x) x
  46. #else
  47. # define IF_FLOAT128(x)
  48. #endif
  49. #if __HAVE_FLOAT32X
  50. # define IF_FLOAT32X(x) x
  51. #else
  52. # define IF_FLOAT32X(x)
  53. #endif
  54. #if __HAVE_FLOAT64X
  55. # define IF_FLOAT64X(x) x
  56. #else
  57. # define IF_FLOAT64X(x)
  58. #endif
  59. #if __HAVE_FLOAT128X
  60. # define IF_FLOAT128X(x) x
  61. #else
  62. # define IF_FLOAT128X(x)
  63. #endif
  64. /* Provide an extra parameter expansion for mfunc. */
  65. #define MMFUNC(mmfunc, ...) mmfunc (__VA_ARGS__)
  66. /* Splat n variants of the same test for the various strtod functions. */
  67. #define GEN_TEST_STRTOD_FOREACH(mfunc, ...) \
  68. mfunc ( f, float, strfromf, f, f, ##__VA_ARGS__) \
  69. mfunc ( d, double, strfromd, , , ##__VA_ARGS__) \
  70. mfunc ( ld, long double, strfroml, L, l, ##__VA_ARGS__) \
  71. IF_FLOAT16 (MMFUNC \
  72. (mfunc, f16, _Float16, strfromf16, F16, f16, ##__VA_ARGS__)) \
  73. IF_FLOAT32 (MMFUNC \
  74. (mfunc, f32, _Float32, strfromf32, F32, f32, ##__VA_ARGS__)) \
  75. IF_FLOAT64 (MMFUNC \
  76. (mfunc, f64, _Float64, strfromf64, F64, f64, ##__VA_ARGS__)) \
  77. IF_FLOAT128 (MMFUNC \
  78. (mfunc, f128, _Float128, strfromf128, F128, f128, ##__VA_ARGS__)) \
  79. IF_FLOAT32X (MMFUNC \
  80. (mfunc, f32x, _Float32x, strfromf32x, F32X, f32x, ##__VA_ARGS__)) \
  81. IF_FLOAT64X (MMFUNC \
  82. (mfunc, f64x, _Float64x, strfromf64x, F64X, f64x, ##__VA_ARGS__)) \
  83. IF_FLOAT128X (MMFUNC \
  84. (mfunc, f128x, _Float128x, strfromf128x, F128X, f128x, ##__VA_ARGS__))
  85. /* The arguments to the generated macros are:
  86. FSUF - Function suffix
  87. FTYPE - float type
  88. FTOSTR - float to string func
  89. LSUF - Literal suffix
  90. CSUF - C standardish suffix for many of the math functions
  91. */
  92. #define STRTOD_TEST_FOREACH(mfunc, ...) \
  93. ({ \
  94. int result = 0; \
  95. result |= mfunc ## f (__VA_ARGS__); \
  96. result |= mfunc ## d (__VA_ARGS__); \
  97. result |= mfunc ## ld (__VA_ARGS__); \
  98. IF_FLOAT16 (result |= mfunc ## f16 (__VA_ARGS__)); \
  99. IF_FLOAT32 (result |= mfunc ## f32 (__VA_ARGS__)); \
  100. IF_FLOAT64 (result |= mfunc ## f64 (__VA_ARGS__)); \
  101. IF_FLOAT128 (result |= mfunc ## f128 (__VA_ARGS__)); \
  102. IF_FLOAT32X (result |= mfunc ## f32x (__VA_ARGS__)); \
  103. IF_FLOAT64X (result |= mfunc ## f64x (__VA_ARGS__)); \
  104. IF_FLOAT128X (result |= mfunc ## f128x (__VA_ARGS__)); \
  105. result; \
  106. })
  107. #endif