Add a generic scalb implementation
[glibc.git] / stdlib / strtod.c
blob0db5e5f10d9ee468b9d7620380b0c9700a6504b6
1 /* Read decimal floating point numbers.
2 This file is part of the GNU C Library.
3 Copyright (C) 1995-2020 Free Software Foundation, Inc.
4 Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 #include <bits/floatn.h>
22 #ifdef FLOAT
23 # define BUILD_DOUBLE 0
24 #else
25 # define BUILD_DOUBLE 1
26 #endif
28 #if BUILD_DOUBLE
29 # if __HAVE_FLOAT64 && !__HAVE_DISTINCT_FLOAT64
30 # define strtof64 __hide_strtof64
31 # define wcstof64 __hide_wcstof64
32 # endif
33 # if __HAVE_FLOAT32X && !__HAVE_DISTINCT_FLOAT32X
34 # define strtof32x __hide_strtof32x
35 # define wcstof32x __hide_wcstof32x
36 # endif
37 #endif
39 #include <stdlib.h>
40 #include <wchar.h>
41 #include <locale/localeinfo.h>
44 #ifndef FLOAT
45 # include <math_ldbl_opt.h>
46 # define FLOAT double
47 # ifdef USE_WIDE_CHAR
48 # define STRTOF wcstod
49 # define STRTOF_L __wcstod_l
50 # else
51 # define STRTOF strtod
52 # define STRTOF_L __strtod_l
53 # endif
54 #endif
56 #ifdef USE_WIDE_CHAR
57 # include <wctype.h>
58 # define STRING_TYPE wchar_t
59 #else
60 # define STRING_TYPE char
61 #endif
63 #define INTERNAL(x) INTERNAL1(x)
64 #define INTERNAL1(x) __##x##_internal
67 FLOAT
68 INTERNAL (STRTOF) (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group)
70 return INTERNAL(STRTOF_L) (nptr, endptr, group, _NL_CURRENT_LOCALE);
72 #if defined _LIBC
73 libc_hidden_def (INTERNAL (STRTOF))
74 #endif
77 FLOAT
78 #ifdef weak_function
79 weak_function
80 #endif
81 STRTOF (const STRING_TYPE *nptr, STRING_TYPE **endptr)
83 return INTERNAL(STRTOF_L) (nptr, endptr, 0, _NL_CURRENT_LOCALE);
85 #if defined _LIBC
86 libc_hidden_def (STRTOF)
87 #endif
89 #ifdef LONG_DOUBLE_COMPAT
90 # if LONG_DOUBLE_COMPAT(libc, GLIBC_2_0)
91 # ifdef USE_WIDE_CHAR
92 compat_symbol (libc, wcstod, wcstold, GLIBC_2_0);
93 compat_symbol (libc, __wcstod_internal, __wcstold_internal, GLIBC_2_0);
94 # else
95 compat_symbol (libc, strtod, strtold, GLIBC_2_0);
96 compat_symbol (libc, __strtod_internal, __strtold_internal, GLIBC_2_0);
97 # endif
98 # endif
99 #endif
101 #if BUILD_DOUBLE
102 # if __HAVE_FLOAT64 && !__HAVE_DISTINCT_FLOAT64
103 # undef strtof64
104 # undef wcstof64
105 # ifdef USE_WIDE_CHAR
106 weak_alias (wcstod, wcstof64)
107 # else
108 weak_alias (strtod, strtof64)
109 # endif
110 # endif
111 # if __HAVE_FLOAT32X && !__HAVE_DISTINCT_FLOAT32X
112 # undef strtof32x
113 # undef wcstof32x
114 # ifdef USE_WIDE_CHAR
115 weak_alias (wcstod, wcstof32x)
116 # else
117 weak_alias (strtod, strtof32x)
118 # endif
119 # endif
120 #endif