_strtod.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * Copyright (C) 2000-2005 Manuel Novoa III
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. /* Notes:
  7. *
  8. * The primary objective of this implementation was minimal size and
  9. * portablility, while providing robustness and resonable accuracy.
  10. *
  11. * This implementation depends on IEEE floating point behavior and expects
  12. * to be able to generate +/- infinity as a result.
  13. *
  14. * There are a number of compile-time options below.
  15. */
  16. /* July 27, 2003
  17. *
  18. * General cleanup and some minor size optimizations.
  19. * Change implementation to support __strtofpmax() rather than strtod().
  20. * Now all the strto{floating pt}() funcs are implemented in terms of
  21. * of the internal __strtofpmax() function.
  22. * Support "nan", "inf", and "infinity" strings (case-insensitive).
  23. * Support hexadecimal floating point notation.
  24. * Support wchar variants.
  25. * Support xlocale variants.
  26. *
  27. * TODO:
  28. *
  29. * Consider accumulating blocks of digits in longs to save floating pt mults.
  30. * This would likely be much better on anything that only supported floats
  31. * where DECIMAL_DIG == 9. Actually, if floats have FLT_MAX_10_EXP == 38,
  32. * we could calculate almost all the exponent multipliers (p_base) in
  33. * long arithmetic as well.
  34. */
  35. /**********************************************************************/
  36. /* OPTIONS */
  37. /**********************************************************************/
  38. /* Defined if we want to recognize "nan", "inf", and "infinity". (C99) */
  39. #define _STRTOD_NAN_INF_STRINGS 1
  40. /* Defined if we want support hexadecimal floating point notation. (C99) */
  41. /* Note! Now controlled by uClibc configuration. See below. */
  42. #define _STRTOD_HEXADECIMAL_FLOATS 1
  43. /* Defined if we want to scale with a O(log2(exp)) multiplications.
  44. * This is generally a good thing to do unless you are really tight
  45. * on space and do not expect to convert values of large magnitude. */
  46. #define _STRTOD_LOG_SCALING 1
  47. /* WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!!
  48. *
  49. * Clearing any of the options below this point is not advised (or tested).
  50. *
  51. * WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! */
  52. /* Defined if we want strtod to set errno appropriately. */
  53. /* NOTE: Implies all options below. */
  54. #define _STRTOD_ERRNO 1
  55. /* Defined if we want support for the endptr arg. */
  56. /* Implied by _STRTOD_ERRNO. */
  57. #define _STRTOD_ENDPTR 1
  58. /* Defined if we want to prevent overflow in accumulating the exponent. */
  59. /* Implied by _STRTOD_ERRNO. */
  60. #define _STRTOD_RESTRICT_EXP 1
  61. /* Defined if we want to process mantissa digits more intelligently. */
  62. /* Implied by _STRTOD_ERRNO. */
  63. #define _STRTOD_RESTRICT_DIGITS 1
  64. /* Defined if we want to skip scaling 0 for the exponent. */
  65. /* Implied by _STRTOD_ERRNO. */
  66. #define _STRTOD_ZERO_CHECK 1
  67. /**********************************************************************/
  68. /* Don't change anything that follows. */
  69. /**********************************************************************/
  70. #ifdef _STRTOD_ERRNO
  71. #undef _STRTOD_ENDPTR
  72. #undef _STRTOD_RESTRICT_EXP
  73. #undef _STRTOD_RESTRICT_DIGITS
  74. #undef _STRTOD_ZERO_CHECK
  75. #define _STRTOD_ENDPTR 1
  76. #define _STRTOD_RESTRICT_EXP 1
  77. #define _STRTOD_RESTRICT_DIGITS 1
  78. #define _STRTOD_ZERO_CHECK 1
  79. #endif
  80. /**********************************************************************/
  81. #define _ISOC99_SOURCE 1
  82. #include <stdlib.h>
  83. #include <string.h>
  84. #include <ctype.h>
  85. #include <errno.h>
  86. #include <limits.h>
  87. #include <float.h>
  88. #include <bits/uClibc_fpmax.h>
  89. #include <locale.h>
  90. #ifdef __UCLIBC_HAS_WCHAR__
  91. #include <wchar.h>
  92. #include <wctype.h>
  93. #include <bits/uClibc_uwchar.h>
  94. libc_hidden_proto(iswspace)
  95. #endif
  96. #ifdef __UCLIBC_HAS_XLOCALE__
  97. #include <xlocale.h>
  98. libc_hidden_proto(iswspace_l)
  99. #endif /* __UCLIBC_HAS_XLOCALE__ */
  100. /* Handle _STRTOD_HEXADECIMAL_FLOATS via uClibc config now. */
  101. #undef _STRTOD_HEXADECIMAL_FLOATS
  102. #ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
  103. #define _STRTOD_HEXADECIMAL_FLOATS 1
  104. #endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
  105. /**********************************************************************/
  106. #undef _STRTOD_FPMAX
  107. #if FPMAX_TYPE == 3
  108. #define NEED_STRTOLD_WRAPPER
  109. #define NEED_STRTOD_WRAPPER
  110. #define NEED_STRTOF_WRAPPER
  111. #elif FPMAX_TYPE == 2
  112. #define NEED_STRTOD_WRAPPER
  113. #define NEED_STRTOF_WRAPPER
  114. #elif FPMAX_TYPE == 1
  115. #define NEED_STRTOF_WRAPPER
  116. #else
  117. #error unknown FPMAX_TYPE!
  118. #endif
  119. extern void __fp_range_check(__fpmax_t y, __fpmax_t x) attribute_hidden;
  120. /**********************************************************************/
  121. #ifdef _STRTOD_RESTRICT_DIGITS
  122. #define EXP_DENORM_ADJUST DECIMAL_DIG
  123. #define MAX_ALLOWED_EXP (DECIMAL_DIG + EXP_DENORM_ADJUST - FPMAX_MIN_10_EXP)
  124. #if MAX_ALLOWED_EXP > INT_MAX
  125. #error size assumption violated for MAX_ALLOWED_EXP
  126. #endif
  127. #else
  128. /* We want some excess if we're not restricting mantissa digits. */
  129. #define MAX_ALLOWED_EXP ((20 - FPMAX_MIN_10_EXP) * 2)
  130. #endif
  131. #if defined(_STRTOD_RESTRICT_DIGITS) || defined(_STRTOD_ENDPTR) || defined(_STRTOD_HEXADECIMAL_FLOATS)
  132. #undef _STRTOD_NEED_NUM_DIGITS
  133. #define _STRTOD_NEED_NUM_DIGITS 1
  134. #endif
  135. /**********************************************************************/
  136. #if defined(L___strtofpmax) || defined(L___strtofpmax_l) || defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
  137. #ifdef __UCLIBC_HAS_XLOCALE__
  138. /* libc_hidden_proto(__ctype_b_loc) */
  139. #elif defined __UCLIBC_HAS_CTYPE_TABLES__
  140. /* libc_hidden_proto(__ctype_b) */
  141. /* libc_hidden_proto(__ctype_tolower) */
  142. #endif
  143. #if defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
  144. #define __strtofpmax __wcstofpmax
  145. #define __strtofpmax_l __wcstofpmax_l
  146. #define Wchar wchar_t
  147. #ifdef __UCLIBC_DO_XLOCALE
  148. #define ISSPACE(C) iswspace_l((C), locale_arg)
  149. #else
  150. #define ISSPACE(C) iswspace((C))
  151. #endif
  152. #else /* defined(L___wcstofpmax) || defined(L___wcstofpmax_l) */
  153. #define Wchar char
  154. #ifdef __UCLIBC_DO_XLOCALE
  155. #define ISSPACE(C) isspace_l((C), locale_arg)
  156. #else
  157. #define ISSPACE(C) isspace((C))
  158. #endif
  159. #endif /* defined(L___wcstofpmax) || defined(L___wcstofpmax_l) */
  160. #if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
  161. __fpmax_t attribute_hidden __strtofpmax(const Wchar *str, Wchar **endptr, int exponent_power)
  162. {
  163. return __strtofpmax_l(str, endptr, exponent_power, __UCLIBC_CURLOCALE);
  164. }
  165. #else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  166. /* Experimentally off - libc_hidden_proto(memcmp) */
  167. __fpmax_t attribute_hidden __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endptr, int exponent_power
  168. __LOCALE_PARAM )
  169. {
  170. __fpmax_t number;
  171. __fpmax_t p_base = 10; /* Adjusted to 16 in the hex case. */
  172. Wchar *pos0;
  173. #ifdef _STRTOD_ENDPTR
  174. Wchar *pos1;
  175. #endif
  176. Wchar *pos = (Wchar *) str;
  177. int exponent_temp;
  178. int negative; /* A flag for the number, a multiplier for the exponent. */
  179. #ifdef _STRTOD_NEED_NUM_DIGITS
  180. int num_digits;
  181. #endif
  182. #ifdef __UCLIBC_HAS_LOCALE__
  183. #if defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
  184. wchar_t decpt_wc = __LOCALE_PTR->decimal_point_wc;
  185. #else
  186. const char *decpt = __LOCALE_PTR->decimal_point;
  187. int decpt_len = __LOCALE_PTR->decimal_point_len;
  188. #endif
  189. #endif
  190. #ifdef _STRTOD_HEXADECIMAL_FLOATS
  191. Wchar expchar = 'e';
  192. Wchar *poshex = NULL;
  193. __uint16_t is_mask = _ISdigit;
  194. #define EXPCHAR expchar
  195. #define IS_X_DIGIT(C) __isctype((C), is_mask)
  196. #else /* _STRTOD_HEXADECIMAL_FLOATS */
  197. #define EXPCHAR 'e'
  198. #define IS_X_DIGIT(C) isdigit((C))
  199. #endif /* _STRTOD_HEXADECIMAL_FLOATS */
  200. while (ISSPACE(*pos)) { /* Skip leading whitespace. */
  201. ++pos;
  202. }
  203. negative = 0;
  204. switch(*pos) { /* Handle optional sign. */
  205. case '-': negative = 1; /* Fall through to increment position. */
  206. case '+': ++pos;
  207. }
  208. #ifdef _STRTOD_HEXADECIMAL_FLOATS
  209. if ((*pos == '0') && (((pos[1])|0x20) == 'x')) {
  210. poshex = ++pos; /* Save position of 'x' in case no digits */
  211. ++pos; /* and advance past it. */
  212. is_mask = _ISxdigit; /* Used by IS_X_DIGIT. */
  213. expchar = 'p'; /* Adjust exponent char. */
  214. p_base = 16; /* Adjust base multiplier. */
  215. }
  216. #endif
  217. number = 0.;
  218. #ifdef _STRTOD_NEED_NUM_DIGITS
  219. num_digits = -1;
  220. #endif
  221. /* exponent_power = 0; */
  222. pos0 = NULL;
  223. LOOP:
  224. while (IS_X_DIGIT(*pos)) { /* Process string of (hex) digits. */
  225. #ifdef _STRTOD_RESTRICT_DIGITS
  226. if (num_digits < 0) { /* First time through? */
  227. ++num_digits; /* We've now seen a digit. */
  228. }
  229. if (num_digits || (*pos != '0')) { /* Had/have nonzero. */
  230. ++num_digits;
  231. if (num_digits <= DECIMAL_DIG) { /* Is digit significant? */
  232. #ifdef _STRTOD_HEXADECIMAL_FLOATS
  233. number = number * p_base
  234. + (isdigit(*pos)
  235. ? (*pos - '0')
  236. : (((*pos)|0x20) - ('a' - 10)));
  237. #else /* _STRTOD_HEXADECIMAL_FLOATS */
  238. number = number * p_base + (*pos - '0');
  239. #endif /* _STRTOD_HEXADECIMAL_FLOATS */
  240. }
  241. }
  242. #else /* _STRTOD_RESTRICT_DIGITS */
  243. #ifdef _STRTOD_NEED_NUM_DIGITS
  244. ++num_digits;
  245. #endif
  246. #ifdef _STRTOD_HEXADECIMAL_FLOATS
  247. number = number * p_base
  248. + (isdigit(*pos)
  249. ? (*pos - '0')
  250. : (((*pos)|0x20) - ('a' - 10)));
  251. #else /* _STRTOD_HEXADECIMAL_FLOATS */
  252. number = number * p_base + (*pos - '0');
  253. #endif /* _STRTOD_HEXADECIMAL_FLOATS */
  254. #endif /* _STRTOD_RESTRICT_DIGITS */
  255. ++pos;
  256. }
  257. #ifdef __UCLIBC_HAS_LOCALE__
  258. #if defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
  259. if (!pos0 && (*pos == decpt_wc)) { /* First decimal point? */
  260. pos0 = ++pos;
  261. goto LOOP;
  262. }
  263. #else
  264. if (!pos0 && !memcmp(pos, decpt, decpt_len)) { /* First decimal point? */
  265. pos0 = (pos += decpt_len);
  266. goto LOOP;
  267. }
  268. #endif
  269. #else /* __UCLIBC_HAS_LOCALE__ */
  270. if ((*pos == '.') && !pos0) { /* First decimal point? */
  271. pos0 = ++pos; /* Save position of decimal point */
  272. goto LOOP; /* and process rest of digits. */
  273. }
  274. #endif /* __UCLIBC_HAS_LOCALE__ */
  275. #ifdef _STRTOD_NEED_NUM_DIGITS
  276. if (num_digits<0) { /* Must have at least one digit. */
  277. #ifdef _STRTOD_HEXADECIMAL_FLOATS
  278. if (poshex) { /* Back up to '0' in '0x' prefix. */
  279. pos = poshex;
  280. goto DONE;
  281. }
  282. #endif /* _STRTOD_HEXADECIMAL_FLOATS */
  283. #ifdef _STRTOD_NAN_INF_STRINGS
  284. if (!pos0) { /* No decimal point, so check for inf/nan. */
  285. /* Note: nan is the first string so 'number = i/0.;' works. */
  286. static const char nan_inf_str[] = "\05nan\0\012infinity\0\05inf\0";
  287. int i = 0;
  288. #ifdef __UCLIBC_HAS_LOCALE__
  289. /* Avoid tolower problems for INFINITY in the tr_TR locale. (yuk)*/
  290. #undef _tolower
  291. #define _tolower(C) ((C)|0x20)
  292. #endif /* __UCLIBC_HAS_LOCALE__ */
  293. do {
  294. /* Unfortunately, we have no memcasecmp(). */
  295. int j = 0;
  296. while (_tolower(pos[j]) == nan_inf_str[i+1+j]) {
  297. ++j;
  298. if (!nan_inf_str[i+1+j]) {
  299. number = i / 0.;
  300. if (negative) { /* Correct for sign. */
  301. number = -number;
  302. }
  303. pos += nan_inf_str[i] - 2;
  304. goto DONE;
  305. }
  306. }
  307. i += nan_inf_str[i];
  308. } while (nan_inf_str[i]);
  309. }
  310. #endif /* STRTOD_NAN_INF_STRINGS */
  311. #ifdef _STRTOD_ENDPTR
  312. pos = (Wchar *) str;
  313. #endif
  314. goto DONE;
  315. }
  316. #endif /* _STRTOD_NEED_NUM_DIGITS */
  317. #ifdef _STRTOD_RESTRICT_DIGITS
  318. if (num_digits > DECIMAL_DIG) { /* Adjust exponent for skipped digits. */
  319. exponent_power += num_digits - DECIMAL_DIG;
  320. }
  321. #endif
  322. if (pos0) {
  323. exponent_power += pos0 - pos; /* Adjust exponent for decimal point. */
  324. }
  325. #ifdef _STRTOD_HEXADECIMAL_FLOATS
  326. if (poshex) {
  327. exponent_power *= 4; /* Above is 2**4, but below is 2. */
  328. p_base = 2;
  329. }
  330. #endif /* _STRTOD_HEXADECIMAL_FLOATS */
  331. if (negative) { /* Correct for sign. */
  332. number = -number;
  333. }
  334. /* process an exponent string */
  335. if (((*pos)|0x20) == EXPCHAR) {
  336. #ifdef _STRTOD_ENDPTR
  337. pos1 = pos;
  338. #endif
  339. negative = 1;
  340. switch(*++pos) { /* Handle optional sign. */
  341. case '-': negative = -1; /* Fall through to increment pos. */
  342. case '+': ++pos;
  343. }
  344. pos0 = pos;
  345. exponent_temp = 0;
  346. while (isdigit(*pos)) { /* Process string of digits. */
  347. #ifdef _STRTOD_RESTRICT_EXP
  348. if (exponent_temp < MAX_ALLOWED_EXP) { /* Avoid overflow. */
  349. exponent_temp = exponent_temp * 10 + (*pos - '0');
  350. }
  351. #else
  352. exponent_temp = exponent_temp * 10 + (*pos - '0');
  353. #endif
  354. ++pos;
  355. }
  356. #ifdef _STRTOD_ENDPTR
  357. if (pos == pos0) { /* No digits? */
  358. pos = pos1; /* Back up to {e|E}/{p|P}. */
  359. } /* else */
  360. #endif
  361. exponent_power += negative * exponent_temp;
  362. }
  363. #ifdef _STRTOD_ZERO_CHECK
  364. if (number == 0.) {
  365. goto DONE;
  366. }
  367. #endif
  368. /* scale the result */
  369. #ifdef _STRTOD_LOG_SCALING
  370. exponent_temp = exponent_power;
  371. if (exponent_temp < 0) {
  372. exponent_temp = -exponent_temp;
  373. }
  374. while (exponent_temp) {
  375. if (exponent_temp & 1) {
  376. if (exponent_power < 0) {
  377. /* Warning... caluclating a factor for the exponent and
  378. * then dividing could easily be faster. But doing so
  379. * might cause problems when dealing with denormals. */
  380. number /= p_base;
  381. } else {
  382. number *= p_base;
  383. }
  384. }
  385. exponent_temp >>= 1;
  386. p_base *= p_base;
  387. }
  388. #else /* _STRTOD_LOG_SCALING */
  389. while (exponent_power) {
  390. if (exponent_power < 0) {
  391. number /= p_base;
  392. exponent_power++;
  393. } else {
  394. number *= p_base;
  395. exponent_power--;
  396. }
  397. }
  398. #endif /* _STRTOD_LOG_SCALING */
  399. #ifdef _STRTOD_ERRNO
  400. if (__FPMAX_ZERO_OR_INF_CHECK(number)) {
  401. __set_errno(ERANGE);
  402. }
  403. #endif
  404. DONE:
  405. #ifdef _STRTOD_ENDPTR
  406. if (endptr) {
  407. *endptr = pos;
  408. }
  409. #endif
  410. return number;
  411. }
  412. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
  413. #endif
  414. /**********************************************************************/
  415. #ifdef L___fp_range_check
  416. #if defined(NEED_STRTOF_WRAPPER) || defined(NEED_STRTOD_WRAPPER)
  417. void attribute_hidden __fp_range_check(__fpmax_t y, __fpmax_t x)
  418. {
  419. if (__FPMAX_ZERO_OR_INF_CHECK(y) /* y is 0 or +/- infinity */
  420. && (y != 0) /* y is not 0 (could have x>0, y==0 if underflow) */
  421. && !__FPMAX_ZERO_OR_INF_CHECK(x) /* x is not 0 or +/- infinity */
  422. ) {
  423. __set_errno(ERANGE); /* Then x is not in y's range. */
  424. }
  425. }
  426. #endif
  427. #endif
  428. /**********************************************************************/
  429. #if defined(L_strtof) || defined(L_strtof_l) || defined(L_wcstof) || defined(L_wcstof_l)
  430. #if defined(NEED_STRTOF_WRAPPER)
  431. #if defined(L_wcstof) || defined(L_wcstof_l)
  432. #define strtof wcstof
  433. #define strtof_l wcstof_l
  434. #define __strtofpmax __wcstofpmax
  435. #define __strtofpmax_l __wcstofpmax_l
  436. #define Wchar wchar_t
  437. #else
  438. #define Wchar char
  439. #endif
  440. libc_hidden_proto(__XL_NPP(strtof))
  441. float __XL_NPP(strtof)(const Wchar *str, Wchar **endptr __LOCALE_PARAM )
  442. {
  443. #if FPMAX_TYPE == 1
  444. return __XL_NPP(__strtofpmax)(str, endptr, 0 __LOCALE_ARG );
  445. #else
  446. __fpmax_t x;
  447. float y;
  448. x = __XL_NPP(__strtofpmax)(str, endptr, 0 __LOCALE_ARG );
  449. y = (float) x;
  450. __fp_range_check(y, x);
  451. return y;
  452. #endif
  453. }
  454. libc_hidden_def(__XL_NPP(strtof))
  455. #endif
  456. #endif
  457. /**********************************************************************/
  458. #if defined(L_strtod) || defined(L_strtod_l) || defined(L_wcstod) || defined(L_wcstod_l)
  459. #if defined(NEED_STRTOD_WRAPPER)
  460. #if defined(L_wcstod) || defined(L_wcstod_l)
  461. #define strtod wcstod
  462. #define strtod_l wcstod_l
  463. #define __strtofpmax __wcstofpmax
  464. #define __strtofpmax_l __wcstofpmax_l
  465. #define Wchar wchar_t
  466. #else
  467. #define Wchar char
  468. #endif
  469. libc_hidden_proto(__XL_NPP(strtod))
  470. double __XL_NPP(strtod)(const Wchar *__restrict str,
  471. Wchar **__restrict endptr __LOCALE_PARAM )
  472. {
  473. #if FPMAX_TYPE == 2
  474. return __XL_NPP(__strtofpmax)(str, endptr, 0 __LOCALE_ARG );
  475. #else
  476. __fpmax_t x;
  477. double y;
  478. x = __XL_NPP(__strtofpmax)(str, endptr, 0 __LOCALE_ARG );
  479. y = (double) x;
  480. __fp_range_check(y, x);
  481. return y;
  482. #endif
  483. }
  484. libc_hidden_def(__XL_NPP(strtod))
  485. #endif
  486. #endif
  487. /**********************************************************************/
  488. #if defined(L_strtold) || defined(L_strtold_l) || defined(L_wcstold) || defined(L_wcstold_l)
  489. #if defined(NEED_STRTOLD_WRAPPER)
  490. #if defined(L_wcstold) || defined(L_wcstold_l)
  491. #define strtold wcstold
  492. #define strtold_l wcstold_l
  493. #define __strtofpmax __wcstofpmax
  494. #define __strtofpmax_l __wcstofpmax_l
  495. #define Wchar wchar_t
  496. #else
  497. #define Wchar char
  498. #endif
  499. libc_hidden_proto(__XL_NPP(strtold))
  500. long double __XL_NPP(strtold) (const Wchar *str, Wchar **endptr __LOCALE_PARAM )
  501. {
  502. #if FPMAX_TYPE == 3
  503. return __XL_NPP(__strtofpmax)(str, endptr, 0 __LOCALE_ARG );
  504. #else
  505. __fpmax_t x;
  506. long double y;
  507. x = __XL_NPP(__strtofpmax)(str, endptr, 0 __LOCALE_ARG );
  508. y = (long double) x;
  509. __fp_range_check(y, x);
  510. return y;
  511. #endif
  512. }
  513. libc_hidden_def(__XL_NPP(strtold))
  514. #endif
  515. #endif
  516. /**********************************************************************/