strtod_l.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827
  1. /* Convert string representing a number to float value, using given locale.
  2. Copyright (C) 1997-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  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_l __hide_strtof64_l
  25. # define wcstof64_l __hide_wcstof64_l
  26. # endif
  27. # if __HAVE_FLOAT32X && !__HAVE_DISTINCT_FLOAT32X
  28. # define strtof32x_l __hide_strtof32x_l
  29. # define wcstof32x_l __hide_wcstof32x_l
  30. # endif
  31. #endif
  32. #include <locale.h>
  33. extern double ____strtod_l_internal (const char *, char **, int, locale_t);
  34. /* Configuration part. These macros are defined by `strtold.c',
  35. `strtof.c', `wcstod.c', `wcstold.c', and `wcstof.c' to produce the
  36. `long double' and `float' versions of the reader. */
  37. #ifndef FLOAT
  38. # include <math_ldbl_opt.h>
  39. # define FLOAT double
  40. # define FLT DBL
  41. # ifdef USE_WIDE_CHAR
  42. # define STRTOF wcstod_l
  43. # define __STRTOF __wcstod_l
  44. # define STRTOF_NAN __wcstod_nan
  45. # else
  46. # define STRTOF strtod_l
  47. # define __STRTOF __strtod_l
  48. # define STRTOF_NAN __strtod_nan
  49. # endif
  50. # define MPN2FLOAT __mpn_construct_double
  51. # define FLOAT_HUGE_VAL HUGE_VAL
  52. #endif
  53. /* End of configuration part. */
  54. #include <ctype.h>
  55. #include <errno.h>
  56. #include <float.h>
  57. #include "../locale/localeinfo.h"
  58. #include <math.h>
  59. #include <math-barriers.h>
  60. #include <math-narrow-eval.h>
  61. #include <stdlib.h>
  62. #include <string.h>
  63. #include <stdint.h>
  64. #include <rounding-mode.h>
  65. #include <tininess.h>
  66. /* The gmp headers need some configuration frobs. */
  67. #define HAVE_ALLOCA 1
  68. /* Include gmp-mparam.h first, such that definitions of _SHORT_LIMB
  69. and _LONG_LONG_LIMB in it can take effect into gmp.h. */
  70. #include <gmp-mparam.h>
  71. #include <gmp.h>
  72. #include "gmp-impl.h"
  73. #include "longlong.h"
  74. #include "fpioconst.h"
  75. #include <assert.h>
  76. /* We use this code for the extended locale handling where the
  77. function gets as an additional argument the locale which has to be
  78. used. To access the values we have to redefine the _NL_CURRENT and
  79. _NL_CURRENT_WORD macros. */
  80. #undef _NL_CURRENT
  81. #define _NL_CURRENT(category, item) \
  82. (current->values[_NL_ITEM_INDEX (item)].string)
  83. #undef _NL_CURRENT_WORD
  84. #define _NL_CURRENT_WORD(category, item) \
  85. ((uint32_t) current->values[_NL_ITEM_INDEX (item)].word)
  86. #if defined _LIBC || defined HAVE_WCHAR_H
  87. # include <wchar.h>
  88. #endif
  89. #ifdef USE_WIDE_CHAR
  90. # include <wctype.h>
  91. # define STRING_TYPE wchar_t
  92. # define CHAR_TYPE wint_t
  93. # define L_(Ch) L##Ch
  94. # define ISSPACE(Ch) __iswspace_l ((Ch), loc)
  95. # define ISDIGIT(Ch) __iswdigit_l ((Ch), loc)
  96. # define ISXDIGIT(Ch) __iswxdigit_l ((Ch), loc)
  97. # define TOLOWER(Ch) __towlower_l ((Ch), loc)
  98. # define TOLOWER_C(Ch) __towlower_l ((Ch), _nl_C_locobj_ptr)
  99. # define STRNCASECMP(S1, S2, N) \
  100. __wcsncasecmp_l ((S1), (S2), (N), _nl_C_locobj_ptr)
  101. #else
  102. # define STRING_TYPE char
  103. # define CHAR_TYPE char
  104. # define L_(Ch) Ch
  105. # define ISSPACE(Ch) __isspace_l ((Ch), loc)
  106. # define ISDIGIT(Ch) __isdigit_l ((Ch), loc)
  107. # define ISXDIGIT(Ch) __isxdigit_l ((Ch), loc)
  108. # define TOLOWER(Ch) __tolower_l ((Ch), loc)
  109. # define TOLOWER_C(Ch) __tolower_l ((Ch), _nl_C_locobj_ptr)
  110. # define STRNCASECMP(S1, S2, N) \
  111. __strncasecmp_l ((S1), (S2), (N), _nl_C_locobj_ptr)
  112. #endif
  113. /* Constants we need from float.h; select the set for the FLOAT precision. */
  114. #define MANT_DIG PASTE(FLT,_MANT_DIG)
  115. #define DIG PASTE(FLT,_DIG)
  116. #define MAX_EXP PASTE(FLT,_MAX_EXP)
  117. #define MIN_EXP PASTE(FLT,_MIN_EXP)
  118. #define MAX_10_EXP PASTE(FLT,_MAX_10_EXP)
  119. #define MIN_10_EXP PASTE(FLT,_MIN_10_EXP)
  120. #define MAX_VALUE PASTE(FLT,_MAX)
  121. #define MIN_VALUE PASTE(FLT,_MIN)
  122. /* Extra macros required to get FLT expanded before the pasting. */
  123. #define PASTE(a,b) PASTE1(a,b)
  124. #define PASTE1(a,b) a##b
  125. /* Function to construct a floating point number from an MP integer
  126. containing the fraction bits, a base 2 exponent, and a sign flag. */
  127. extern FLOAT MPN2FLOAT (mp_srcptr mpn, int exponent, int negative);
  128. /* Definitions according to limb size used. */
  129. #if BITS_PER_MP_LIMB == 32
  130. # define MAX_DIG_PER_LIMB 9
  131. # define MAX_FAC_PER_LIMB 1000000000UL
  132. #elif BITS_PER_MP_LIMB == 64
  133. # define MAX_DIG_PER_LIMB 19
  134. # define MAX_FAC_PER_LIMB 10000000000000000000ULL
  135. #else
  136. # error "mp_limb_t size " BITS_PER_MP_LIMB "not accounted for"
  137. #endif
  138. extern const mp_limb_t _tens_in_limb[MAX_DIG_PER_LIMB + 1];
  139. #ifndef howmany
  140. #define howmany(x,y) (((x)+((y)-1))/(y))
  141. #endif
  142. #define SWAP(x, y) ({ typeof(x) _tmp = x; x = y; y = _tmp; })
  143. #define RETURN_LIMB_SIZE howmany (MANT_DIG, BITS_PER_MP_LIMB)
  144. #define RETURN(val,end) \
  145. do { if (endptr != NULL) *endptr = (STRING_TYPE *) (end); \
  146. return val; } while (0)
  147. /* Maximum size necessary for mpn integers to hold floating point
  148. numbers. The largest number we need to hold is 10^n where 2^-n is
  149. 1/4 ulp of the smallest representable value (that is, n = MANT_DIG
  150. - MIN_EXP + 2). Approximate using 10^3 < 2^10. */
  151. #define MPNSIZE (howmany (1 + ((MANT_DIG - MIN_EXP + 2) * 10) / 3, \
  152. BITS_PER_MP_LIMB) + 2)
  153. /* Declare an mpn integer variable that big. */
  154. #define MPN_VAR(name) mp_limb_t name[MPNSIZE]; mp_size_t name##size
  155. /* Copy an mpn integer value. */
  156. #define MPN_ASSIGN(dst, src) \
  157. memcpy (dst, src, (dst##size = src##size) * sizeof (mp_limb_t))
  158. /* Set errno and return an overflowing value with sign specified by
  159. NEGATIVE. */
  160. static FLOAT
  161. overflow_value (int negative)
  162. {
  163. __set_errno (ERANGE);
  164. FLOAT result = math_narrow_eval ((negative ? -MAX_VALUE : MAX_VALUE)
  165. * MAX_VALUE);
  166. return result;
  167. }
  168. /* Set errno and return an underflowing value with sign specified by
  169. NEGATIVE. */
  170. static FLOAT
  171. underflow_value (int negative)
  172. {
  173. __set_errno (ERANGE);
  174. FLOAT result = math_narrow_eval ((negative ? -MIN_VALUE : MIN_VALUE)
  175. * MIN_VALUE);
  176. return result;
  177. }
  178. /* Return a floating point number of the needed type according to the given
  179. multi-precision number after possible rounding. */
  180. static FLOAT
  181. round_and_return (mp_limb_t *retval, intmax_t exponent, int negative,
  182. mp_limb_t round_limb, mp_size_t round_bit, int more_bits)
  183. {
  184. int mode = get_rounding_mode ();
  185. if (exponent < MIN_EXP - 1)
  186. {
  187. if (exponent < MIN_EXP - 1 - MANT_DIG)
  188. return underflow_value (negative);
  189. mp_size_t shift = MIN_EXP - 1 - exponent;
  190. bool is_tiny = true;
  191. more_bits |= (round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0;
  192. if (shift == MANT_DIG)
  193. /* This is a special case to handle the very seldom case where
  194. the mantissa will be empty after the shift. */
  195. {
  196. int i;
  197. round_limb = retval[RETURN_LIMB_SIZE - 1];
  198. round_bit = (MANT_DIG - 1) % BITS_PER_MP_LIMB;
  199. for (i = 0; i < RETURN_LIMB_SIZE - 1; ++i)
  200. more_bits |= retval[i] != 0;
  201. MPN_ZERO (retval, RETURN_LIMB_SIZE);
  202. }
  203. else if (shift >= BITS_PER_MP_LIMB)
  204. {
  205. int i;
  206. round_limb = retval[(shift - 1) / BITS_PER_MP_LIMB];
  207. round_bit = (shift - 1) % BITS_PER_MP_LIMB;
  208. for (i = 0; i < (shift - 1) / BITS_PER_MP_LIMB; ++i)
  209. more_bits |= retval[i] != 0;
  210. more_bits |= ((round_limb & ((((mp_limb_t) 1) << round_bit) - 1))
  211. != 0);
  212. /* __mpn_rshift requires 0 < shift < BITS_PER_MP_LIMB. */
  213. if ((shift % BITS_PER_MP_LIMB) != 0)
  214. (void) __mpn_rshift (retval, &retval[shift / BITS_PER_MP_LIMB],
  215. RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB),
  216. shift % BITS_PER_MP_LIMB);
  217. else
  218. for (i = 0; i < RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB); i++)
  219. retval[i] = retval[i + (shift / BITS_PER_MP_LIMB)];
  220. MPN_ZERO (&retval[RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB)],
  221. shift / BITS_PER_MP_LIMB);
  222. }
  223. else if (shift > 0)
  224. {
  225. if (TININESS_AFTER_ROUNDING && shift == 1)
  226. {
  227. /* Whether the result counts as tiny depends on whether,
  228. after rounding to the normal precision, it still has
  229. a subnormal exponent. */
  230. mp_limb_t retval_normal[RETURN_LIMB_SIZE];
  231. if (round_away (negative,
  232. (retval[0] & 1) != 0,
  233. (round_limb
  234. & (((mp_limb_t) 1) << round_bit)) != 0,
  235. (more_bits
  236. || ((round_limb
  237. & ((((mp_limb_t) 1) << round_bit) - 1))
  238. != 0)),
  239. mode))
  240. {
  241. mp_limb_t cy = __mpn_add_1 (retval_normal, retval,
  242. RETURN_LIMB_SIZE, 1);
  243. if (((MANT_DIG % BITS_PER_MP_LIMB) == 0 && cy) ||
  244. ((MANT_DIG % BITS_PER_MP_LIMB) != 0 &&
  245. ((retval_normal[RETURN_LIMB_SIZE - 1]
  246. & (((mp_limb_t) 1) << (MANT_DIG % BITS_PER_MP_LIMB)))
  247. != 0)))
  248. is_tiny = false;
  249. }
  250. }
  251. round_limb = retval[0];
  252. round_bit = shift - 1;
  253. (void) __mpn_rshift (retval, retval, RETURN_LIMB_SIZE, shift);
  254. }
  255. /* This is a hook for the m68k long double format, where the
  256. exponent bias is the same for normalized and denormalized
  257. numbers. */
  258. #ifndef DENORM_EXP
  259. # define DENORM_EXP (MIN_EXP - 2)
  260. #endif
  261. exponent = DENORM_EXP;
  262. if (is_tiny
  263. && ((round_limb & (((mp_limb_t) 1) << round_bit)) != 0
  264. || more_bits
  265. || (round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0))
  266. {
  267. __set_errno (ERANGE);
  268. FLOAT force_underflow = MIN_VALUE * MIN_VALUE;
  269. math_force_eval (force_underflow);
  270. }
  271. }
  272. if (exponent >= MAX_EXP)
  273. goto overflow;
  274. bool half_bit = (round_limb & (((mp_limb_t) 1) << round_bit)) != 0;
  275. bool more_bits_nonzero
  276. = (more_bits
  277. || (round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0);
  278. if (round_away (negative,
  279. (retval[0] & 1) != 0,
  280. half_bit,
  281. more_bits_nonzero,
  282. mode))
  283. {
  284. mp_limb_t cy = __mpn_add_1 (retval, retval, RETURN_LIMB_SIZE, 1);
  285. if (((MANT_DIG % BITS_PER_MP_LIMB) == 0 && cy) ||
  286. ((MANT_DIG % BITS_PER_MP_LIMB) != 0 &&
  287. (retval[RETURN_LIMB_SIZE - 1]
  288. & (((mp_limb_t) 1) << (MANT_DIG % BITS_PER_MP_LIMB))) != 0))
  289. {
  290. ++exponent;
  291. (void) __mpn_rshift (retval, retval, RETURN_LIMB_SIZE, 1);
  292. retval[RETURN_LIMB_SIZE - 1]
  293. |= ((mp_limb_t) 1) << ((MANT_DIG - 1) % BITS_PER_MP_LIMB);
  294. }
  295. else if (exponent == DENORM_EXP
  296. && (retval[RETURN_LIMB_SIZE - 1]
  297. & (((mp_limb_t) 1) << ((MANT_DIG - 1) % BITS_PER_MP_LIMB)))
  298. != 0)
  299. /* The number was denormalized but now normalized. */
  300. exponent = MIN_EXP - 1;
  301. }
  302. if (exponent >= MAX_EXP)
  303. overflow:
  304. return overflow_value (negative);
  305. if (half_bit || more_bits_nonzero)
  306. {
  307. FLOAT force_inexact = (FLOAT) 1 + MIN_VALUE;
  308. math_force_eval (force_inexact);
  309. }
  310. return MPN2FLOAT (retval, exponent, negative);
  311. }
  312. /* Read a multi-precision integer starting at STR with exactly DIGCNT digits
  313. into N. Return the size of the number limbs in NSIZE at the first
  314. character od the string that is not part of the integer as the function
  315. value. If the EXPONENT is small enough to be taken as an additional
  316. factor for the resulting number (see code) multiply by it. */
  317. static const STRING_TYPE *
  318. str_to_mpn (const STRING_TYPE *str, int digcnt, mp_limb_t *n, mp_size_t *nsize,
  319. intmax_t *exponent
  320. #ifndef USE_WIDE_CHAR
  321. , const char *decimal, size_t decimal_len, const char *thousands
  322. #endif
  323. )
  324. {
  325. /* Number of digits for actual limb. */
  326. int cnt = 0;
  327. mp_limb_t low = 0;
  328. mp_limb_t start;
  329. *nsize = 0;
  330. assert (digcnt > 0);
  331. do
  332. {
  333. if (cnt == MAX_DIG_PER_LIMB)
  334. {
  335. if (*nsize == 0)
  336. {
  337. n[0] = low;
  338. *nsize = 1;
  339. }
  340. else
  341. {
  342. mp_limb_t cy;
  343. cy = __mpn_mul_1 (n, n, *nsize, MAX_FAC_PER_LIMB);
  344. cy += __mpn_add_1 (n, n, *nsize, low);
  345. if (cy != 0)
  346. {
  347. assert (*nsize < MPNSIZE);
  348. n[*nsize] = cy;
  349. ++(*nsize);
  350. }
  351. }
  352. cnt = 0;
  353. low = 0;
  354. }
  355. /* There might be thousands separators or radix characters in
  356. the string. But these all can be ignored because we know the
  357. format of the number is correct and we have an exact number
  358. of characters to read. */
  359. #ifdef USE_WIDE_CHAR
  360. if (*str < L'0' || *str > L'9')
  361. ++str;
  362. #else
  363. if (*str < '0' || *str > '9')
  364. {
  365. int inner = 0;
  366. if (thousands != NULL && *str == *thousands
  367. && ({ for (inner = 1; thousands[inner] != '\0'; ++inner)
  368. if (thousands[inner] != str[inner])
  369. break;
  370. thousands[inner] == '\0'; }))
  371. str += inner;
  372. else
  373. str += decimal_len;
  374. }
  375. #endif
  376. low = low * 10 + *str++ - L_('0');
  377. ++cnt;
  378. }
  379. while (--digcnt > 0);
  380. if (*exponent > 0 && *exponent <= MAX_DIG_PER_LIMB - cnt)
  381. {
  382. low *= _tens_in_limb[*exponent];
  383. start = _tens_in_limb[cnt + *exponent];
  384. *exponent = 0;
  385. }
  386. else
  387. start = _tens_in_limb[cnt];
  388. if (*nsize == 0)
  389. {
  390. n[0] = low;
  391. *nsize = 1;
  392. }
  393. else
  394. {
  395. mp_limb_t cy;
  396. cy = __mpn_mul_1 (n, n, *nsize, start);
  397. cy += __mpn_add_1 (n, n, *nsize, low);
  398. if (cy != 0)
  399. {
  400. assert (*nsize < MPNSIZE);
  401. n[(*nsize)++] = cy;
  402. }
  403. }
  404. return str;
  405. }
  406. /* Shift {PTR, SIZE} COUNT bits to the left, and fill the vacated bits
  407. with the COUNT most significant bits of LIMB.
  408. Implemented as a macro, so that __builtin_constant_p works even at -O0.
  409. Tege doesn't like this macro so I have to write it here myself. :)
  410. --drepper */
  411. #define __mpn_lshift_1(ptr, size, count, limb) \
  412. do \
  413. { \
  414. mp_limb_t *__ptr = (ptr); \
  415. if (__builtin_constant_p (count) && count == BITS_PER_MP_LIMB) \
  416. { \
  417. mp_size_t i; \
  418. for (i = (size) - 1; i > 0; --i) \
  419. __ptr[i] = __ptr[i - 1]; \
  420. __ptr[0] = (limb); \
  421. } \
  422. else \
  423. { \
  424. /* We assume count > 0 && count < BITS_PER_MP_LIMB here. */ \
  425. unsigned int __count = (count); \
  426. (void) __mpn_lshift (__ptr, __ptr, size, __count); \
  427. __ptr[0] |= (limb) >> (BITS_PER_MP_LIMB - __count); \
  428. } \
  429. } \
  430. while (0)
  431. #define INTERNAL(x) INTERNAL1(x)
  432. #define INTERNAL1(x) __##x##_internal
  433. #ifndef ____STRTOF_INTERNAL
  434. # define ____STRTOF_INTERNAL INTERNAL (__STRTOF)
  435. #endif
  436. /* This file defines a function to check for correct grouping. */
  437. #include "grouping.h"
  438. /* Return a floating point number with the value of the given string NPTR.
  439. Set *ENDPTR to the character after the last used one. If the number is
  440. smaller than the smallest representable number, set `errno' to ERANGE and
  441. return 0.0. If the number is too big to be represented, set `errno' to
  442. ERANGE and return HUGE_VAL with the appropriate sign. */
  443. FLOAT
  444. ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group,
  445. locale_t loc)
  446. {
  447. int negative; /* The sign of the number. */
  448. MPN_VAR (num); /* MP representation of the number. */
  449. intmax_t exponent; /* Exponent of the number. */
  450. /* Numbers starting `0X' or `0x' have to be processed with base 16. */
  451. int base = 10;
  452. /* When we have to compute fractional digits we form a fraction with a
  453. second multi-precision number (and we sometimes need a second for
  454. temporary results). */
  455. MPN_VAR (den);
  456. /* Representation for the return value. */
  457. mp_limb_t retval[RETURN_LIMB_SIZE];
  458. /* Number of bits currently in result value. */
  459. int bits;
  460. /* Running pointer after the last character processed in the string. */
  461. const STRING_TYPE *cp, *tp;
  462. /* Start of significant part of the number. */
  463. const STRING_TYPE *startp, *start_of_digits;
  464. /* Points at the character following the integer and fractional digits. */
  465. const STRING_TYPE *expp;
  466. /* Total number of digit and number of digits in integer part. */
  467. size_t dig_no, int_no, lead_zero;
  468. /* Contains the last character read. */
  469. CHAR_TYPE c;
  470. /* We should get wint_t from <stddef.h>, but not all GCC versions define it
  471. there. So define it ourselves if it remains undefined. */
  472. #ifndef _WINT_T
  473. typedef unsigned int wint_t;
  474. #endif
  475. /* The radix character of the current locale. */
  476. #ifdef USE_WIDE_CHAR
  477. wchar_t decimal;
  478. #else
  479. const char *decimal;
  480. size_t decimal_len;
  481. #endif
  482. /* The thousands character of the current locale. */
  483. #ifdef USE_WIDE_CHAR
  484. wchar_t thousands = L'\0';
  485. #else
  486. const char *thousands = NULL;
  487. #endif
  488. /* The numeric grouping specification of the current locale,
  489. in the format described in <locale.h>. */
  490. const char *grouping;
  491. /* Used in several places. */
  492. int cnt;
  493. struct __locale_data *current = loc->__locales[LC_NUMERIC];
  494. if (__glibc_unlikely (group))
  495. {
  496. grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
  497. if (*grouping <= 0 || *grouping == CHAR_MAX)
  498. grouping = NULL;
  499. else
  500. {
  501. /* Figure out the thousands separator character. */
  502. #ifdef USE_WIDE_CHAR
  503. thousands = _NL_CURRENT_WORD (LC_NUMERIC,
  504. _NL_NUMERIC_THOUSANDS_SEP_WC);
  505. if (thousands == L'\0')
  506. grouping = NULL;
  507. #else
  508. thousands = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
  509. if (*thousands == '\0')
  510. {
  511. thousands = NULL;
  512. grouping = NULL;
  513. }
  514. #endif
  515. }
  516. }
  517. else
  518. grouping = NULL;
  519. /* Find the locale's decimal point character. */
  520. #ifdef USE_WIDE_CHAR
  521. decimal = _NL_CURRENT_WORD (LC_NUMERIC, _NL_NUMERIC_DECIMAL_POINT_WC);
  522. assert (decimal != L'\0');
  523. # define decimal_len 1
  524. #else
  525. decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
  526. decimal_len = strlen (decimal);
  527. assert (decimal_len > 0);
  528. #endif
  529. /* Prepare number representation. */
  530. exponent = 0;
  531. negative = 0;
  532. bits = 0;
  533. /* Parse string to get maximal legal prefix. We need the number of
  534. characters of the integer part, the fractional part and the exponent. */
  535. cp = nptr - 1;
  536. /* Ignore leading white space. */
  537. do
  538. c = *++cp;
  539. while (ISSPACE (c));
  540. /* Get sign of the result. */
  541. if (c == L_('-'))
  542. {
  543. negative = 1;
  544. c = *++cp;
  545. }
  546. else if (c == L_('+'))
  547. c = *++cp;
  548. /* Return 0.0 if no legal string is found.
  549. No character is used even if a sign was found. */
  550. #ifdef USE_WIDE_CHAR
  551. if (c == (wint_t) decimal
  552. && (wint_t) cp[1] >= L'0' && (wint_t) cp[1] <= L'9')
  553. {
  554. /* We accept it. This funny construct is here only to indent
  555. the code correctly. */
  556. }
  557. #else
  558. for (cnt = 0; decimal[cnt] != '\0'; ++cnt)
  559. if (cp[cnt] != decimal[cnt])
  560. break;
  561. if (decimal[cnt] == '\0' && cp[cnt] >= '0' && cp[cnt] <= '9')
  562. {
  563. /* We accept it. This funny construct is here only to indent
  564. the code correctly. */
  565. }
  566. #endif
  567. else if (c < L_('0') || c > L_('9'))
  568. {
  569. /* Check for `INF' or `INFINITY'. */
  570. CHAR_TYPE lowc = TOLOWER_C (c);
  571. if (lowc == L_('i') && STRNCASECMP (cp, L_("inf"), 3) == 0)
  572. {
  573. /* Return +/- infinity. */
  574. if (endptr != NULL)
  575. *endptr = (STRING_TYPE *)
  576. (cp + (STRNCASECMP (cp + 3, L_("inity"), 5) == 0
  577. ? 8 : 3));
  578. return negative ? -FLOAT_HUGE_VAL : FLOAT_HUGE_VAL;
  579. }
  580. if (lowc == L_('n') && STRNCASECMP (cp, L_("nan"), 3) == 0)
  581. {
  582. /* Return NaN. */
  583. FLOAT retval = NAN;
  584. cp += 3;
  585. /* Match `(n-char-sequence-digit)'. */
  586. if (*cp == L_('('))
  587. {
  588. const STRING_TYPE *startp = cp;
  589. STRING_TYPE *endp;
  590. retval = STRTOF_NAN (cp + 1, &endp, L_(')'));
  591. if (*endp == L_(')'))
  592. /* Consume the closing parenthesis. */
  593. cp = endp + 1;
  594. else
  595. /* Only match the NAN part. */
  596. cp = startp;
  597. }
  598. if (endptr != NULL)
  599. *endptr = (STRING_TYPE *) cp;
  600. return negative ? -retval : retval;
  601. }
  602. /* It is really a text we do not recognize. */
  603. RETURN (0.0, nptr);
  604. }
  605. /* First look whether we are faced with a hexadecimal number. */
  606. if (c == L_('0') && TOLOWER (cp[1]) == L_('x'))
  607. {
  608. /* Okay, it is a hexa-decimal number. Remember this and skip
  609. the characters. BTW: hexadecimal numbers must not be
  610. grouped. */
  611. base = 16;
  612. cp += 2;
  613. c = *cp;
  614. grouping = NULL;
  615. }
  616. /* Record the start of the digits, in case we will check their grouping. */
  617. start_of_digits = startp = cp;
  618. /* Ignore leading zeroes. This helps us to avoid useless computations. */
  619. #ifdef USE_WIDE_CHAR
  620. while (c == L'0' || ((wint_t) thousands != L'\0' && c == (wint_t) thousands))
  621. c = *++cp;
  622. #else
  623. if (__glibc_likely (thousands == NULL))
  624. while (c == '0')
  625. c = *++cp;
  626. else
  627. {
  628. /* We also have the multibyte thousands string. */
  629. while (1)
  630. {
  631. if (c != '0')
  632. {
  633. for (cnt = 0; thousands[cnt] != '\0'; ++cnt)
  634. if (thousands[cnt] != cp[cnt])
  635. break;
  636. if (thousands[cnt] != '\0')
  637. break;
  638. cp += cnt - 1;
  639. }
  640. c = *++cp;
  641. }
  642. }
  643. #endif
  644. /* If no other digit but a '0' is found the result is 0.0.
  645. Return current read pointer. */
  646. CHAR_TYPE lowc = TOLOWER (c);
  647. if (!((c >= L_('0') && c <= L_('9'))
  648. || (base == 16 && lowc >= L_('a') && lowc <= L_('f'))
  649. || (
  650. #ifdef USE_WIDE_CHAR
  651. c == (wint_t) decimal
  652. #else
  653. ({ for (cnt = 0; decimal[cnt] != '\0'; ++cnt)
  654. if (decimal[cnt] != cp[cnt])
  655. break;
  656. decimal[cnt] == '\0'; })
  657. #endif
  658. /* '0x.' alone is not a valid hexadecimal number.
  659. '.' alone is not valid either, but that has been checked
  660. already earlier. */
  661. && (base != 16
  662. || cp != start_of_digits
  663. || (cp[decimal_len] >= L_('0') && cp[decimal_len] <= L_('9'))
  664. || ({ CHAR_TYPE lo = TOLOWER (cp[decimal_len]);
  665. lo >= L_('a') && lo <= L_('f'); })))
  666. || (base == 16 && (cp != start_of_digits
  667. && lowc == L_('p')))
  668. || (base != 16 && lowc == L_('e'))))
  669. {
  670. #ifdef USE_WIDE_CHAR
  671. tp = __correctly_grouped_prefixwc (start_of_digits, cp, thousands,
  672. grouping);
  673. #else
  674. tp = __correctly_grouped_prefixmb (start_of_digits, cp, thousands,
  675. grouping);
  676. #endif
  677. /* If TP is at the start of the digits, there was no correctly
  678. grouped prefix of the string; so no number found. */
  679. RETURN (negative ? -0.0 : 0.0,
  680. tp == start_of_digits ? (base == 16 ? cp - 1 : nptr) : tp);
  681. }
  682. /* Remember first significant digit and read following characters until the
  683. decimal point, exponent character or any non-FP number character. */
  684. startp = cp;
  685. dig_no = 0;
  686. while (1)
  687. {
  688. if ((c >= L_('0') && c <= L_('9'))
  689. || (base == 16
  690. && ({ CHAR_TYPE lo = TOLOWER (c);
  691. lo >= L_('a') && lo <= L_('f'); })))
  692. ++dig_no;
  693. else
  694. {
  695. #ifdef USE_WIDE_CHAR
  696. if (__builtin_expect ((wint_t) thousands == L'\0', 1)
  697. || c != (wint_t) thousands)
  698. /* Not a digit or separator: end of the integer part. */
  699. break;
  700. #else
  701. if (__glibc_likely (thousands == NULL))
  702. break;
  703. else
  704. {
  705. for (cnt = 0; thousands[cnt] != '\0'; ++cnt)
  706. if (thousands[cnt] != cp[cnt])
  707. break;
  708. if (thousands[cnt] != '\0')
  709. break;
  710. cp += cnt - 1;
  711. }
  712. #endif
  713. }
  714. c = *++cp;
  715. }
  716. if (__builtin_expect (grouping != NULL, 0) && cp > start_of_digits)
  717. {
  718. /* Check the grouping of the digits. */
  719. #ifdef USE_WIDE_CHAR
  720. tp = __correctly_grouped_prefixwc (start_of_digits, cp, thousands,
  721. grouping);
  722. #else
  723. tp = __correctly_grouped_prefixmb (start_of_digits, cp, thousands,
  724. grouping);
  725. #endif
  726. if (cp != tp)
  727. {
  728. /* Less than the entire string was correctly grouped. */
  729. if (tp == start_of_digits)
  730. /* No valid group of numbers at all: no valid number. */
  731. RETURN (0.0, nptr);
  732. if (tp < startp)
  733. /* The number is validly grouped, but consists
  734. only of zeroes. The whole value is zero. */
  735. RETURN (negative ? -0.0 : 0.0, tp);
  736. /* Recompute DIG_NO so we won't read more digits than
  737. are properly grouped. */
  738. cp = tp;
  739. dig_no = 0;
  740. for (tp = startp; tp < cp; ++tp)
  741. if (*tp >= L_('0') && *tp <= L_('9'))
  742. ++dig_no;
  743. int_no = dig_no;
  744. lead_zero = 0;
  745. goto number_parsed;
  746. }
  747. }
  748. /* We have the number of digits in the integer part. Whether these
  749. are all or any is really a fractional digit will be decided
  750. later. */
  751. int_no = dig_no;
  752. lead_zero = int_no == 0 ? (size_t) -1 : 0;
  753. /* Read the fractional digits. A special case are the 'american
  754. style' numbers like `16.' i.e. with decimal point but without
  755. trailing digits. */
  756. if (
  757. #ifdef USE_WIDE_CHAR
  758. c == (wint_t) decimal
  759. #else
  760. ({ for (cnt = 0; decimal[cnt] != '\0'; ++cnt)
  761. if (decimal[cnt] != cp[cnt])
  762. break;
  763. decimal[cnt] == '\0'; })
  764. #endif
  765. )
  766. {
  767. cp += decimal_len;
  768. c = *cp;
  769. while ((c >= L_('0') && c <= L_('9')) ||
  770. (base == 16 && ({ CHAR_TYPE lo = TOLOWER (c);
  771. lo >= L_('a') && lo <= L_('f'); })))
  772. {
  773. if (c != L_('0') && lead_zero == (size_t) -1)
  774. lead_zero = dig_no - int_no;
  775. ++dig_no;
  776. c = *++cp;
  777. }
  778. }
  779. assert (dig_no <= (uintmax_t) INTMAX_MAX);
  780. /* Remember start of exponent (if any). */
  781. expp = cp;
  782. /* Read exponent. */
  783. lowc = TOLOWER (c);
  784. if ((base == 16 && lowc == L_('p'))
  785. || (base != 16 && lowc == L_('e')))
  786. {
  787. int exp_negative = 0;
  788. c = *++cp;
  789. if (c == L_('-'))
  790. {
  791. exp_negative = 1;
  792. c = *++cp;
  793. }
  794. else if (c == L_('+'))
  795. c = *++cp;
  796. if (c >= L_('0') && c <= L_('9'))
  797. {
  798. intmax_t exp_limit;
  799. /* Get the exponent limit. */
  800. if (base == 16)
  801. {
  802. if (exp_negative)
  803. {
  804. assert (int_no <= (uintmax_t) (INTMAX_MAX
  805. + MIN_EXP - MANT_DIG) / 4);
  806. exp_limit = -MIN_EXP + MANT_DIG + 4 * (intmax_t) int_no;
  807. }
  808. else
  809. {
  810. if (int_no)
  811. {
  812. assert (lead_zero == 0
  813. && int_no <= (uintmax_t) INTMAX_MAX / 4);
  814. exp_limit = MAX_EXP - 4 * (intmax_t) int_no + 3;
  815. }
  816. else if (lead_zero == (size_t) -1)
  817. {
  818. /* The number is zero and this limit is
  819. arbitrary. */
  820. exp_limit = MAX_EXP + 3;
  821. }
  822. else
  823. {
  824. assert (lead_zero
  825. <= (uintmax_t) (INTMAX_MAX - MAX_EXP - 3) / 4);
  826. exp_limit = (MAX_EXP
  827. + 4 * (intmax_t) lead_zero
  828. + 3);
  829. }
  830. }
  831. }
  832. else
  833. {
  834. if (exp_negative)
  835. {
  836. assert (int_no
  837. <= (uintmax_t) (INTMAX_MAX + MIN_10_EXP - MANT_DIG));
  838. exp_limit = -MIN_10_EXP + MANT_DIG + (intmax_t) int_no;
  839. }
  840. else
  841. {
  842. if (int_no)
  843. {
  844. assert (lead_zero == 0
  845. && int_no <= (uintmax_t) INTMAX_MAX);
  846. exp_limit = MAX_10_EXP - (intmax_t) int_no + 1;
  847. }
  848. else if (lead_zero == (size_t) -1)
  849. {
  850. /* The number is zero and this limit is
  851. arbitrary. */
  852. exp_limit = MAX_10_EXP + 1;
  853. }
  854. else
  855. {
  856. assert (lead_zero
  857. <= (uintmax_t) (INTMAX_MAX - MAX_10_EXP - 1));
  858. exp_limit = MAX_10_EXP + (intmax_t) lead_zero + 1;
  859. }
  860. }
  861. }
  862. if (exp_limit < 0)
  863. exp_limit = 0;
  864. do
  865. {
  866. if (__builtin_expect ((exponent > exp_limit / 10
  867. || (exponent == exp_limit / 10
  868. && c - L_('0') > exp_limit % 10)), 0))
  869. /* The exponent is too large/small to represent a valid
  870. number. */
  871. {
  872. FLOAT result;
  873. /* We have to take care for special situation: a joker
  874. might have written "0.0e100000" which is in fact
  875. zero. */
  876. if (lead_zero == (size_t) -1)
  877. result = negative ? -0.0 : 0.0;
  878. else
  879. {
  880. /* Overflow or underflow. */
  881. result = (exp_negative
  882. ? underflow_value (negative)
  883. : overflow_value (negative));
  884. }
  885. /* Accept all following digits as part of the exponent. */
  886. do
  887. ++cp;
  888. while (*cp >= L_('0') && *cp <= L_('9'));
  889. RETURN (result, cp);
  890. /* NOTREACHED */
  891. }
  892. exponent *= 10;
  893. exponent += c - L_('0');
  894. c = *++cp;
  895. }
  896. while (c >= L_('0') && c <= L_('9'));
  897. if (exp_negative)
  898. exponent = -exponent;
  899. }
  900. else
  901. cp = expp;
  902. }
  903. /* We don't want to have to work with trailing zeroes after the radix. */
  904. if (dig_no > int_no)
  905. {
  906. while (expp[-1] == L_('0'))
  907. {
  908. --expp;
  909. --dig_no;
  910. }
  911. assert (dig_no >= int_no);
  912. }
  913. if (dig_no == int_no && dig_no > 0 && exponent < 0)
  914. do
  915. {
  916. while (! (base == 16 ? ISXDIGIT (expp[-1]) : ISDIGIT (expp[-1])))
  917. --expp;
  918. if (expp[-1] != L_('0'))
  919. break;
  920. --expp;
  921. --dig_no;
  922. --int_no;
  923. exponent += base == 16 ? 4 : 1;
  924. }
  925. while (dig_no > 0 && exponent < 0);
  926. number_parsed:
  927. /* The whole string is parsed. Store the address of the next character. */
  928. if (endptr)
  929. *endptr = (STRING_TYPE *) cp;
  930. if (dig_no == 0)
  931. return negative ? -0.0 : 0.0;
  932. if (lead_zero)
  933. {
  934. /* Find the decimal point */
  935. #ifdef USE_WIDE_CHAR
  936. while (*startp != decimal)
  937. ++startp;
  938. #else
  939. while (1)
  940. {
  941. if (*startp == decimal[0])
  942. {
  943. for (cnt = 1; decimal[cnt] != '\0'; ++cnt)
  944. if (decimal[cnt] != startp[cnt])
  945. break;
  946. if (decimal[cnt] == '\0')
  947. break;
  948. }
  949. ++startp;
  950. }
  951. #endif
  952. startp += lead_zero + decimal_len;
  953. assert (lead_zero <= (base == 16
  954. ? (uintmax_t) INTMAX_MAX / 4
  955. : (uintmax_t) INTMAX_MAX));
  956. assert (lead_zero <= (base == 16
  957. ? ((uintmax_t) exponent
  958. - (uintmax_t) INTMAX_MIN) / 4
  959. : ((uintmax_t) exponent - (uintmax_t) INTMAX_MIN)));
  960. exponent -= base == 16 ? 4 * (intmax_t) lead_zero : (intmax_t) lead_zero;
  961. dig_no -= lead_zero;
  962. }
  963. /* If the BASE is 16 we can use a simpler algorithm. */
  964. if (base == 16)
  965. {
  966. static const int nbits[16] = { 0, 1, 2, 2, 3, 3, 3, 3,
  967. 4, 4, 4, 4, 4, 4, 4, 4 };
  968. int idx = (MANT_DIG - 1) / BITS_PER_MP_LIMB;
  969. int pos = (MANT_DIG - 1) % BITS_PER_MP_LIMB;
  970. mp_limb_t val;
  971. while (!ISXDIGIT (*startp))
  972. ++startp;
  973. while (*startp == L_('0'))
  974. ++startp;
  975. if (ISDIGIT (*startp))
  976. val = *startp++ - L_('0');
  977. else
  978. val = 10 + TOLOWER (*startp++) - L_('a');
  979. bits = nbits[val];
  980. /* We cannot have a leading zero. */
  981. assert (bits != 0);
  982. if (pos + 1 >= 4 || pos + 1 >= bits)
  983. {
  984. /* We don't have to care for wrapping. This is the normal
  985. case so we add the first clause in the `if' expression as
  986. an optimization. It is a compile-time constant and so does
  987. not cost anything. */
  988. retval[idx] = val << (pos - bits + 1);
  989. pos -= bits;
  990. }
  991. else
  992. {
  993. retval[idx--] = val >> (bits - pos - 1);
  994. retval[idx] = val << (BITS_PER_MP_LIMB - (bits - pos - 1));
  995. pos = BITS_PER_MP_LIMB - 1 - (bits - pos - 1);
  996. }
  997. /* Adjust the exponent for the bits we are shifting in. */
  998. assert (int_no <= (uintmax_t) (exponent < 0
  999. ? (INTMAX_MAX - bits + 1) / 4
  1000. : (INTMAX_MAX - exponent - bits + 1) / 4));
  1001. exponent += bits - 1 + ((intmax_t) int_no - 1) * 4;
  1002. while (--dig_no > 0 && idx >= 0)
  1003. {
  1004. if (!ISXDIGIT (*startp))
  1005. startp += decimal_len;
  1006. if (ISDIGIT (*startp))
  1007. val = *startp++ - L_('0');
  1008. else
  1009. val = 10 + TOLOWER (*startp++) - L_('a');
  1010. if (pos + 1 >= 4)
  1011. {
  1012. retval[idx] |= val << (pos - 4 + 1);
  1013. pos -= 4;
  1014. }
  1015. else
  1016. {
  1017. retval[idx--] |= val >> (4 - pos - 1);
  1018. val <<= BITS_PER_MP_LIMB - (4 - pos - 1);
  1019. if (idx < 0)
  1020. {
  1021. int rest_nonzero = 0;
  1022. while (--dig_no > 0)
  1023. {
  1024. if (*startp != L_('0'))
  1025. {
  1026. rest_nonzero = 1;
  1027. break;
  1028. }
  1029. startp++;
  1030. }
  1031. return round_and_return (retval, exponent, negative, val,
  1032. BITS_PER_MP_LIMB - 1, rest_nonzero);
  1033. }
  1034. retval[idx] = val;
  1035. pos = BITS_PER_MP_LIMB - 1 - (4 - pos - 1);
  1036. }
  1037. }
  1038. /* We ran out of digits. */
  1039. MPN_ZERO (retval, idx);
  1040. return round_and_return (retval, exponent, negative, 0, 0, 0);
  1041. }
  1042. /* Now we have the number of digits in total and the integer digits as well
  1043. as the exponent and its sign. We can decide whether the read digits are
  1044. really integer digits or belong to the fractional part; i.e. we normalize
  1045. 123e-2 to 1.23. */
  1046. {
  1047. intmax_t incr = (exponent < 0
  1048. ? MAX (-(intmax_t) int_no, exponent)
  1049. : MIN ((intmax_t) dig_no - (intmax_t) int_no, exponent));
  1050. int_no += incr;
  1051. exponent -= incr;
  1052. }
  1053. if (__glibc_unlikely (exponent > MAX_10_EXP + 1 - (intmax_t) int_no))
  1054. return overflow_value (negative);
  1055. /* 10^(MIN_10_EXP-1) is not normal. Thus, 10^(MIN_10_EXP-1) /
  1056. 2^MANT_DIG is below half the least subnormal, so anything with a
  1057. base-10 exponent less than the base-10 exponent (which is
  1058. MIN_10_EXP - 1 - ceil(MANT_DIG*log10(2))) of that value
  1059. underflows. DIG is floor((MANT_DIG-1)log10(2)), so an exponent
  1060. below MIN_10_EXP - (DIG + 3) underflows. But EXPONENT is
  1061. actually an exponent multiplied only by a fractional part, not an
  1062. integer part, so an exponent below MIN_10_EXP - (DIG + 2)
  1063. underflows. */
  1064. if (__glibc_unlikely (exponent < MIN_10_EXP - (DIG + 2)))
  1065. return underflow_value (negative);
  1066. if (int_no > 0)
  1067. {
  1068. /* Read the integer part as a multi-precision number to NUM. */
  1069. startp = str_to_mpn (startp, int_no, num, &numsize, &exponent
  1070. #ifndef USE_WIDE_CHAR
  1071. , decimal, decimal_len, thousands
  1072. #endif
  1073. );
  1074. if (exponent > 0)
  1075. {
  1076. /* We now multiply the gained number by the given power of ten. */
  1077. mp_limb_t *psrc = num;
  1078. mp_limb_t *pdest = den;
  1079. int expbit = 1;
  1080. const struct mp_power *ttab = &_fpioconst_pow10[0];
  1081. do
  1082. {
  1083. if ((exponent & expbit) != 0)
  1084. {
  1085. size_t size = ttab->arraysize - _FPIO_CONST_OFFSET;
  1086. mp_limb_t cy;
  1087. exponent ^= expbit;
  1088. /* FIXME: not the whole multiplication has to be
  1089. done. If we have the needed number of bits we
  1090. only need the information whether more non-zero
  1091. bits follow. */
  1092. if (numsize >= ttab->arraysize - _FPIO_CONST_OFFSET)
  1093. cy = __mpn_mul (pdest, psrc, numsize,
  1094. &__tens[ttab->arrayoff
  1095. + _FPIO_CONST_OFFSET],
  1096. size);
  1097. else
  1098. cy = __mpn_mul (pdest, &__tens[ttab->arrayoff
  1099. + _FPIO_CONST_OFFSET],
  1100. size, psrc, numsize);
  1101. numsize += size;
  1102. if (cy == 0)
  1103. --numsize;
  1104. (void) SWAP (psrc, pdest);
  1105. }
  1106. expbit <<= 1;
  1107. ++ttab;
  1108. }
  1109. while (exponent != 0);
  1110. if (psrc == den)
  1111. memcpy (num, den, numsize * sizeof (mp_limb_t));
  1112. }
  1113. /* Determine how many bits of the result we already have. */
  1114. count_leading_zeros (bits, num[numsize - 1]);
  1115. bits = numsize * BITS_PER_MP_LIMB - bits;
  1116. /* Now we know the exponent of the number in base two.
  1117. Check it against the maximum possible exponent. */
  1118. if (__glibc_unlikely (bits > MAX_EXP))
  1119. return overflow_value (negative);
  1120. /* We have already the first BITS bits of the result. Together with
  1121. the information whether more non-zero bits follow this is enough
  1122. to determine the result. */
  1123. if (bits > MANT_DIG)
  1124. {
  1125. int i;
  1126. const mp_size_t least_idx = (bits - MANT_DIG) / BITS_PER_MP_LIMB;
  1127. const mp_size_t least_bit = (bits - MANT_DIG) % BITS_PER_MP_LIMB;
  1128. const mp_size_t round_idx = least_bit == 0 ? least_idx - 1
  1129. : least_idx;
  1130. const mp_size_t round_bit = least_bit == 0 ? BITS_PER_MP_LIMB - 1
  1131. : least_bit - 1;
  1132. if (least_bit == 0)
  1133. memcpy (retval, &num[least_idx],
  1134. RETURN_LIMB_SIZE * sizeof (mp_limb_t));
  1135. else
  1136. {
  1137. for (i = least_idx; i < numsize - 1; ++i)
  1138. retval[i - least_idx] = (num[i] >> least_bit)
  1139. | (num[i + 1]
  1140. << (BITS_PER_MP_LIMB - least_bit));
  1141. if (i - least_idx < RETURN_LIMB_SIZE)
  1142. retval[RETURN_LIMB_SIZE - 1] = num[i] >> least_bit;
  1143. }
  1144. /* Check whether any limb beside the ones in RETVAL are non-zero. */
  1145. for (i = 0; num[i] == 0; ++i)
  1146. ;
  1147. return round_and_return (retval, bits - 1, negative,
  1148. num[round_idx], round_bit,
  1149. int_no < dig_no || i < round_idx);
  1150. /* NOTREACHED */
  1151. }
  1152. else if (dig_no == int_no)
  1153. {
  1154. const mp_size_t target_bit = (MANT_DIG - 1) % BITS_PER_MP_LIMB;
  1155. const mp_size_t is_bit = (bits - 1) % BITS_PER_MP_LIMB;
  1156. if (target_bit == is_bit)
  1157. {
  1158. memcpy (&retval[RETURN_LIMB_SIZE - numsize], num,
  1159. numsize * sizeof (mp_limb_t));
  1160. /* FIXME: the following loop can be avoided if we assume a
  1161. maximal MANT_DIG value. */
  1162. MPN_ZERO (retval, RETURN_LIMB_SIZE - numsize);
  1163. }
  1164. else if (target_bit > is_bit)
  1165. {
  1166. (void) __mpn_lshift (&retval[RETURN_LIMB_SIZE - numsize],
  1167. num, numsize, target_bit - is_bit);
  1168. /* FIXME: the following loop can be avoided if we assume a
  1169. maximal MANT_DIG value. */
  1170. MPN_ZERO (retval, RETURN_LIMB_SIZE - numsize);
  1171. }
  1172. else
  1173. {
  1174. mp_limb_t cy;
  1175. assert (numsize < RETURN_LIMB_SIZE);
  1176. cy = __mpn_rshift (&retval[RETURN_LIMB_SIZE - numsize],
  1177. num, numsize, is_bit - target_bit);
  1178. retval[RETURN_LIMB_SIZE - numsize - 1] = cy;
  1179. /* FIXME: the following loop can be avoided if we assume a
  1180. maximal MANT_DIG value. */
  1181. MPN_ZERO (retval, RETURN_LIMB_SIZE - numsize - 1);
  1182. }
  1183. return round_and_return (retval, bits - 1, negative, 0, 0, 0);
  1184. /* NOTREACHED */
  1185. }
  1186. /* Store the bits we already have. */
  1187. memcpy (retval, num, numsize * sizeof (mp_limb_t));
  1188. #if RETURN_LIMB_SIZE > 1
  1189. if (numsize < RETURN_LIMB_SIZE)
  1190. # if RETURN_LIMB_SIZE == 2
  1191. retval[numsize] = 0;
  1192. # else
  1193. MPN_ZERO (retval + numsize, RETURN_LIMB_SIZE - numsize);
  1194. # endif
  1195. #endif
  1196. }
  1197. /* We have to compute at least some of the fractional digits. */
  1198. {
  1199. /* We construct a fraction and the result of the division gives us
  1200. the needed digits. The denominator is 1.0 multiplied by the
  1201. exponent of the lowest digit; i.e. 0.123 gives 123 / 1000 and
  1202. 123e-6 gives 123 / 1000000. */
  1203. int expbit;
  1204. int neg_exp;
  1205. int more_bits;
  1206. int need_frac_digits;
  1207. mp_limb_t cy;
  1208. mp_limb_t *psrc = den;
  1209. mp_limb_t *pdest = num;
  1210. const struct mp_power *ttab = &_fpioconst_pow10[0];
  1211. assert (dig_no > int_no
  1212. && exponent <= 0
  1213. && exponent >= MIN_10_EXP - (DIG + 2));
  1214. /* We need to compute MANT_DIG - BITS fractional bits that lie
  1215. within the mantissa of the result, the following bit for
  1216. rounding, and to know whether any subsequent bit is 0.
  1217. Computing a bit with value 2^-n means looking at n digits after
  1218. the decimal point. */
  1219. if (bits > 0)
  1220. {
  1221. /* The bits required are those immediately after the point. */
  1222. assert (int_no > 0 && exponent == 0);
  1223. need_frac_digits = 1 + MANT_DIG - bits;
  1224. }
  1225. else
  1226. {
  1227. /* The number is in the form .123eEXPONENT. */
  1228. assert (int_no == 0 && *startp != L_('0'));
  1229. /* The number is at least 10^(EXPONENT-1), and 10^3 <
  1230. 2^10. */
  1231. int neg_exp_2 = ((1 - exponent) * 10) / 3 + 1;
  1232. /* The number is at least 2^-NEG_EXP_2. We need up to
  1233. MANT_DIG bits following that bit. */
  1234. need_frac_digits = neg_exp_2 + MANT_DIG;
  1235. /* However, we never need bits beyond 1/4 ulp of the smallest
  1236. representable value. (That 1/4 ulp bit is only needed to
  1237. determine tinyness on machines where tinyness is determined
  1238. after rounding.) */
  1239. if (need_frac_digits > MANT_DIG - MIN_EXP + 2)
  1240. need_frac_digits = MANT_DIG - MIN_EXP + 2;
  1241. /* At this point, NEED_FRAC_DIGITS is the total number of
  1242. digits needed after the point, but some of those may be
  1243. leading 0s. */
  1244. need_frac_digits += exponent;
  1245. /* Any cases underflowing enough that none of the fractional
  1246. digits are needed should have been caught earlier (such
  1247. cases are on the order of 10^-n or smaller where 2^-n is
  1248. the least subnormal). */
  1249. assert (need_frac_digits > 0);
  1250. }
  1251. if (need_frac_digits > (intmax_t) dig_no - (intmax_t) int_no)
  1252. need_frac_digits = (intmax_t) dig_no - (intmax_t) int_no;
  1253. if ((intmax_t) dig_no > (intmax_t) int_no + need_frac_digits)
  1254. {
  1255. dig_no = int_no + need_frac_digits;
  1256. more_bits = 1;
  1257. }
  1258. else
  1259. more_bits = 0;
  1260. neg_exp = (intmax_t) dig_no - (intmax_t) int_no - exponent;
  1261. /* Construct the denominator. */
  1262. densize = 0;
  1263. expbit = 1;
  1264. do
  1265. {
  1266. if ((neg_exp & expbit) != 0)
  1267. {
  1268. mp_limb_t cy;
  1269. neg_exp ^= expbit;
  1270. if (densize == 0)
  1271. {
  1272. densize = ttab->arraysize - _FPIO_CONST_OFFSET;
  1273. memcpy (psrc, &__tens[ttab->arrayoff + _FPIO_CONST_OFFSET],
  1274. densize * sizeof (mp_limb_t));
  1275. }
  1276. else
  1277. {
  1278. cy = __mpn_mul (pdest, &__tens[ttab->arrayoff
  1279. + _FPIO_CONST_OFFSET],
  1280. ttab->arraysize - _FPIO_CONST_OFFSET,
  1281. psrc, densize);
  1282. densize += ttab->arraysize - _FPIO_CONST_OFFSET;
  1283. if (cy == 0)
  1284. --densize;
  1285. (void) SWAP (psrc, pdest);
  1286. }
  1287. }
  1288. expbit <<= 1;
  1289. ++ttab;
  1290. }
  1291. while (neg_exp != 0);
  1292. if (psrc == num)
  1293. memcpy (den, num, densize * sizeof (mp_limb_t));
  1294. /* Read the fractional digits from the string. */
  1295. (void) str_to_mpn (startp, dig_no - int_no, num, &numsize, &exponent
  1296. #ifndef USE_WIDE_CHAR
  1297. , decimal, decimal_len, thousands
  1298. #endif
  1299. );
  1300. /* We now have to shift both numbers so that the highest bit in the
  1301. denominator is set. In the same process we copy the numerator to
  1302. a high place in the array so that the division constructs the wanted
  1303. digits. This is done by a "quasi fix point" number representation.
  1304. num: ddddddddddd . 0000000000000000000000
  1305. |--- m ---|
  1306. den: ddddddddddd n >= m
  1307. |--- n ---|
  1308. */
  1309. count_leading_zeros (cnt, den[densize - 1]);
  1310. if (cnt > 0)
  1311. {
  1312. /* Don't call `mpn_shift' with a count of zero since the specification
  1313. does not allow this. */
  1314. (void) __mpn_lshift (den, den, densize, cnt);
  1315. cy = __mpn_lshift (num, num, numsize, cnt);
  1316. if (cy != 0)
  1317. num[numsize++] = cy;
  1318. }
  1319. /* Now we are ready for the division. But it is not necessary to
  1320. do a full multi-precision division because we only need a small
  1321. number of bits for the result. So we do not use __mpn_divmod
  1322. here but instead do the division here by hand and stop whenever
  1323. the needed number of bits is reached. The code itself comes
  1324. from the GNU MP Library by Torbj\"orn Granlund. */
  1325. exponent = bits;
  1326. switch (densize)
  1327. {
  1328. case 1:
  1329. {
  1330. mp_limb_t d, n, quot;
  1331. int used = 0;
  1332. n = num[0];
  1333. d = den[0];
  1334. assert (numsize == 1 && n < d);
  1335. do
  1336. {
  1337. udiv_qrnnd (quot, n, n, 0, d);
  1338. #define got_limb \
  1339. if (bits == 0) \
  1340. { \
  1341. int cnt; \
  1342. if (quot == 0) \
  1343. cnt = BITS_PER_MP_LIMB; \
  1344. else \
  1345. count_leading_zeros (cnt, quot); \
  1346. exponent -= cnt; \
  1347. if (BITS_PER_MP_LIMB - cnt > MANT_DIG) \
  1348. { \
  1349. used = MANT_DIG + cnt; \
  1350. retval[0] = quot >> (BITS_PER_MP_LIMB - used); \
  1351. bits = MANT_DIG + 1; \
  1352. } \
  1353. else \
  1354. { \
  1355. /* Note that we only clear the second element. */ \
  1356. /* The conditional is determined at compile time. */ \
  1357. if (RETURN_LIMB_SIZE > 1) \
  1358. retval[1] = 0; \
  1359. retval[0] = quot; \
  1360. bits = -cnt; \
  1361. } \
  1362. } \
  1363. else if (bits + BITS_PER_MP_LIMB <= MANT_DIG) \
  1364. __mpn_lshift_1 (retval, RETURN_LIMB_SIZE, BITS_PER_MP_LIMB, \
  1365. quot); \
  1366. else \
  1367. { \
  1368. used = MANT_DIG - bits; \
  1369. if (used > 0) \
  1370. __mpn_lshift_1 (retval, RETURN_LIMB_SIZE, used, quot); \
  1371. } \
  1372. bits += BITS_PER_MP_LIMB
  1373. got_limb;
  1374. }
  1375. while (bits <= MANT_DIG);
  1376. return round_and_return (retval, exponent - 1, negative,
  1377. quot, BITS_PER_MP_LIMB - 1 - used,
  1378. more_bits || n != 0);
  1379. }
  1380. case 2:
  1381. {
  1382. mp_limb_t d0, d1, n0, n1;
  1383. mp_limb_t quot = 0;
  1384. int used = 0;
  1385. d0 = den[0];
  1386. d1 = den[1];
  1387. if (numsize < densize)
  1388. {
  1389. if (num[0] >= d1)
  1390. {
  1391. /* The numerator of the number occupies fewer bits than
  1392. the denominator but the one limb is bigger than the
  1393. high limb of the numerator. */
  1394. n1 = 0;
  1395. n0 = num[0];
  1396. }
  1397. else
  1398. {
  1399. if (bits <= 0)
  1400. exponent -= BITS_PER_MP_LIMB;
  1401. else
  1402. {
  1403. if (bits + BITS_PER_MP_LIMB <= MANT_DIG)
  1404. __mpn_lshift_1 (retval, RETURN_LIMB_SIZE,
  1405. BITS_PER_MP_LIMB, 0);
  1406. else
  1407. {
  1408. used = MANT_DIG - bits;
  1409. if (used > 0)
  1410. __mpn_lshift_1 (retval, RETURN_LIMB_SIZE, used, 0);
  1411. }
  1412. bits += BITS_PER_MP_LIMB;
  1413. }
  1414. n1 = num[0];
  1415. n0 = 0;
  1416. }
  1417. }
  1418. else
  1419. {
  1420. n1 = num[1];
  1421. n0 = num[0];
  1422. }
  1423. while (bits <= MANT_DIG)
  1424. {
  1425. mp_limb_t r;
  1426. if (n1 == d1)
  1427. {
  1428. /* QUOT should be either 111..111 or 111..110. We need
  1429. special treatment of this rare case as normal division
  1430. would give overflow. */
  1431. quot = ~(mp_limb_t) 0;
  1432. r = n0 + d1;
  1433. if (r < d1) /* Carry in the addition? */
  1434. {
  1435. add_ssaaaa (n1, n0, r - d0, 0, 0, d0);
  1436. goto have_quot;
  1437. }
  1438. n1 = d0 - (d0 != 0);
  1439. n0 = -d0;
  1440. }
  1441. else
  1442. {
  1443. udiv_qrnnd (quot, r, n1, n0, d1);
  1444. umul_ppmm (n1, n0, d0, quot);
  1445. }
  1446. q_test:
  1447. if (n1 > r || (n1 == r && n0 > 0))
  1448. {
  1449. /* The estimated QUOT was too large. */
  1450. --quot;
  1451. sub_ddmmss (n1, n0, n1, n0, 0, d0);
  1452. r += d1;
  1453. if (r >= d1) /* If not carry, test QUOT again. */
  1454. goto q_test;
  1455. }
  1456. sub_ddmmss (n1, n0, r, 0, n1, n0);
  1457. have_quot:
  1458. got_limb;
  1459. }
  1460. return round_and_return (retval, exponent - 1, negative,
  1461. quot, BITS_PER_MP_LIMB - 1 - used,
  1462. more_bits || n1 != 0 || n0 != 0);
  1463. }
  1464. default:
  1465. {
  1466. int i;
  1467. mp_limb_t cy, dX, d1, n0, n1;
  1468. mp_limb_t quot = 0;
  1469. int used = 0;
  1470. dX = den[densize - 1];
  1471. d1 = den[densize - 2];
  1472. /* The division does not work if the upper limb of the two-limb
  1473. numerator is greater than the denominator. */
  1474. if (__mpn_cmp (num, &den[densize - numsize], numsize) > 0)
  1475. num[numsize++] = 0;
  1476. if (numsize < densize)
  1477. {
  1478. mp_size_t empty = densize - numsize;
  1479. int i;
  1480. if (bits <= 0)
  1481. exponent -= empty * BITS_PER_MP_LIMB;
  1482. else
  1483. {
  1484. if (bits + empty * BITS_PER_MP_LIMB <= MANT_DIG)
  1485. {
  1486. /* We make a difference here because the compiler
  1487. cannot optimize the `else' case that good and
  1488. this reflects all currently used FLOAT types
  1489. and GMP implementations. */
  1490. #if RETURN_LIMB_SIZE <= 2
  1491. assert (empty == 1);
  1492. __mpn_lshift_1 (retval, RETURN_LIMB_SIZE,
  1493. BITS_PER_MP_LIMB, 0);
  1494. #else
  1495. for (i = RETURN_LIMB_SIZE - 1; i >= empty; --i)
  1496. retval[i] = retval[i - empty];
  1497. while (i >= 0)
  1498. retval[i--] = 0;
  1499. #endif
  1500. }
  1501. else
  1502. {
  1503. used = MANT_DIG - bits;
  1504. if (used >= BITS_PER_MP_LIMB)
  1505. {
  1506. int i;
  1507. (void) __mpn_lshift (&retval[used
  1508. / BITS_PER_MP_LIMB],
  1509. retval,
  1510. (RETURN_LIMB_SIZE
  1511. - used / BITS_PER_MP_LIMB),
  1512. used % BITS_PER_MP_LIMB);
  1513. for (i = used / BITS_PER_MP_LIMB - 1; i >= 0; --i)
  1514. retval[i] = 0;
  1515. }
  1516. else if (used > 0)
  1517. __mpn_lshift_1 (retval, RETURN_LIMB_SIZE, used, 0);
  1518. }
  1519. bits += empty * BITS_PER_MP_LIMB;
  1520. }
  1521. for (i = numsize; i > 0; --i)
  1522. num[i + empty] = num[i - 1];
  1523. MPN_ZERO (num, empty + 1);
  1524. }
  1525. else
  1526. {
  1527. int i;
  1528. assert (numsize == densize);
  1529. for (i = numsize; i > 0; --i)
  1530. num[i] = num[i - 1];
  1531. num[0] = 0;
  1532. }
  1533. den[densize] = 0;
  1534. n0 = num[densize];
  1535. while (bits <= MANT_DIG)
  1536. {
  1537. if (n0 == dX)
  1538. /* This might over-estimate QUOT, but it's probably not
  1539. worth the extra code here to find out. */
  1540. quot = ~(mp_limb_t) 0;
  1541. else
  1542. {
  1543. mp_limb_t r;
  1544. udiv_qrnnd (quot, r, n0, num[densize - 1], dX);
  1545. umul_ppmm (n1, n0, d1, quot);
  1546. while (n1 > r || (n1 == r && n0 > num[densize - 2]))
  1547. {
  1548. --quot;
  1549. r += dX;
  1550. if (r < dX) /* I.e. "carry in previous addition?" */
  1551. break;
  1552. n1 -= n0 < d1;
  1553. n0 -= d1;
  1554. }
  1555. }
  1556. /* Possible optimization: We already have (q * n0) and (1 * n1)
  1557. after the calculation of QUOT. Taking advantage of this, we
  1558. could make this loop make two iterations less. */
  1559. cy = __mpn_submul_1 (num, den, densize + 1, quot);
  1560. if (num[densize] != cy)
  1561. {
  1562. cy = __mpn_add_n (num, num, den, densize);
  1563. assert (cy != 0);
  1564. --quot;
  1565. }
  1566. n0 = num[densize] = num[densize - 1];
  1567. for (i = densize - 1; i > 0; --i)
  1568. num[i] = num[i - 1];
  1569. num[0] = 0;
  1570. got_limb;
  1571. }
  1572. for (i = densize; i >= 0 && num[i] == 0; --i)
  1573. ;
  1574. return round_and_return (retval, exponent - 1, negative,
  1575. quot, BITS_PER_MP_LIMB - 1 - used,
  1576. more_bits || i >= 0);
  1577. }
  1578. }
  1579. }
  1580. /* NOTREACHED */
  1581. }
  1582. #if defined _LIBC && !defined USE_WIDE_CHAR
  1583. libc_hidden_def (____STRTOF_INTERNAL)
  1584. #endif
  1585. /* External user entry point. */
  1586. FLOAT
  1587. #ifdef weak_function
  1588. weak_function
  1589. #endif
  1590. __STRTOF (const STRING_TYPE *nptr, STRING_TYPE **endptr, locale_t loc)
  1591. {
  1592. return ____STRTOF_INTERNAL (nptr, endptr, 0, loc);
  1593. }
  1594. #if defined _LIBC
  1595. libc_hidden_def (__STRTOF)
  1596. libc_hidden_ver (__STRTOF, STRTOF)
  1597. #endif
  1598. weak_alias (__STRTOF, STRTOF)
  1599. #ifdef LONG_DOUBLE_COMPAT
  1600. # if LONG_DOUBLE_COMPAT(libc, GLIBC_2_1)
  1601. # ifdef USE_WIDE_CHAR
  1602. compat_symbol (libc, __wcstod_l, __wcstold_l, GLIBC_2_1);
  1603. # else
  1604. compat_symbol (libc, __strtod_l, __strtold_l, GLIBC_2_1);
  1605. # endif
  1606. # endif
  1607. # if LONG_DOUBLE_COMPAT(libc, GLIBC_2_3)
  1608. # ifdef USE_WIDE_CHAR
  1609. compat_symbol (libc, wcstod_l, wcstold_l, GLIBC_2_3);
  1610. # else
  1611. compat_symbol (libc, strtod_l, strtold_l, GLIBC_2_3);
  1612. # endif
  1613. # endif
  1614. #endif
  1615. #if BUILD_DOUBLE
  1616. # if __HAVE_FLOAT64 && !__HAVE_DISTINCT_FLOAT64
  1617. # undef strtof64_l
  1618. # undef wcstof64_l
  1619. # ifdef USE_WIDE_CHAR
  1620. weak_alias (wcstod_l, wcstof64_l)
  1621. # else
  1622. weak_alias (strtod_l, strtof64_l)
  1623. # endif
  1624. # endif
  1625. # if __HAVE_FLOAT32X && !__HAVE_DISTINCT_FLOAT32X
  1626. # undef strtof32x_l
  1627. # undef wcstof32x_l
  1628. # ifdef USE_WIDE_CHAR
  1629. weak_alias (wcstod_l, wcstof32x_l)
  1630. # else
  1631. weak_alias (strtod_l, strtof32x_l)
  1632. # endif
  1633. # endif
  1634. #endif