strtod.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Read decimal floating point numbers.
  2. This file is part of the GNU C Library.
  3. Copyright (C) 1995-2019 Free Software Foundation, Inc.
  4. Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
  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. 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. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <bits/floatn.h>
  17. #ifdef FLOAT
  18. # define BUILD_DOUBLE 0
  19. #else
  20. # define BUILD_DOUBLE 1
  21. #endif
  22. #if BUILD_DOUBLE
  23. # if __HAVE_FLOAT64 && !__HAVE_DISTINCT_FLOAT64
  24. # define strtof64 __hide_strtof64
  25. # define wcstof64 __hide_wcstof64
  26. # endif
  27. # if __HAVE_FLOAT32X && !__HAVE_DISTINCT_FLOAT32X
  28. # define strtof32x __hide_strtof32x
  29. # define wcstof32x __hide_wcstof32x
  30. # endif
  31. #endif
  32. #include <stdlib.h>
  33. #include <wchar.h>
  34. #include <locale/localeinfo.h>
  35. #ifndef FLOAT
  36. # include <math_ldbl_opt.h>
  37. # define FLOAT double
  38. # ifdef USE_WIDE_CHAR
  39. # define STRTOF wcstod
  40. # define STRTOF_L __wcstod_l
  41. # else
  42. # define STRTOF strtod
  43. # define STRTOF_L __strtod_l
  44. # endif
  45. #endif
  46. #ifdef USE_WIDE_CHAR
  47. # include <wctype.h>
  48. # define STRING_TYPE wchar_t
  49. #else
  50. # define STRING_TYPE char
  51. #endif
  52. #define INTERNAL(x) INTERNAL1(x)
  53. #define INTERNAL1(x) __##x##_internal
  54. FLOAT
  55. INTERNAL (STRTOF) (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group)
  56. {
  57. return INTERNAL(STRTOF_L) (nptr, endptr, group, _NL_CURRENT_LOCALE);
  58. }
  59. #if defined _LIBC
  60. libc_hidden_def (INTERNAL (STRTOF))
  61. #endif
  62. FLOAT
  63. #ifdef weak_function
  64. weak_function
  65. #endif
  66. STRTOF (const STRING_TYPE *nptr, STRING_TYPE **endptr)
  67. {
  68. return INTERNAL(STRTOF_L) (nptr, endptr, 0, _NL_CURRENT_LOCALE);
  69. }
  70. #if defined _LIBC
  71. libc_hidden_def (STRTOF)
  72. #endif
  73. #ifdef LONG_DOUBLE_COMPAT
  74. # if LONG_DOUBLE_COMPAT(libc, GLIBC_2_0)
  75. # ifdef USE_WIDE_CHAR
  76. compat_symbol (libc, wcstod, wcstold, GLIBC_2_0);
  77. compat_symbol (libc, __wcstod_internal, __wcstold_internal, GLIBC_2_0);
  78. # else
  79. compat_symbol (libc, strtod, strtold, GLIBC_2_0);
  80. compat_symbol (libc, __strtod_internal, __strtold_internal, GLIBC_2_0);
  81. # endif
  82. # endif
  83. #endif
  84. #if BUILD_DOUBLE
  85. # if __HAVE_FLOAT64 && !__HAVE_DISTINCT_FLOAT64
  86. # undef strtof64
  87. # undef wcstof64
  88. # ifdef USE_WIDE_CHAR
  89. weak_alias (wcstod, wcstof64)
  90. # else
  91. weak_alias (strtod, strtof64)
  92. # endif
  93. # endif
  94. # if __HAVE_FLOAT32X && !__HAVE_DISTINCT_FLOAT32X
  95. # undef strtof32x
  96. # undef wcstof32x
  97. # ifdef USE_WIDE_CHAR
  98. weak_alias (wcstod, wcstof32x)
  99. # else
  100. weak_alias (strtod, strtof32x)
  101. # endif
  102. # endif
  103. #endif