strtod.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*
  2. FUNCTION
  3. <<strtod>>, <<strtodf>>---string to double or float
  4. INDEX
  5. strtod
  6. INDEX
  7. _strtod_r
  8. INDEX
  9. strtodf
  10. ANSI_SYNOPSIS
  11. #include <stdlib.h>
  12. double strtod(const char *<[str]>, char **<[tail]>);
  13. float strtodf(const char *<[str]>, char **<[tail]>);
  14. double _strtod_r(void *<[reent]>,
  15. const char *<[str]>, char **<[tail]>);
  16. TRAD_SYNOPSIS
  17. #include <stdlib.h>
  18. double strtod(<[str]>,<[tail]>)
  19. char *<[str]>;
  20. char **<[tail]>;
  21. float strtodf(<[str]>,<[tail]>)
  22. char *<[str]>;
  23. char **<[tail]>;
  24. double _strtod_r(<[reent]>,<[str]>,<[tail]>)
  25. char *<[reent]>;
  26. char *<[str]>;
  27. char **<[tail]>;
  28. DESCRIPTION
  29. The function <<strtod>> parses the character string <[str]>,
  30. producing a substring which can be converted to a double
  31. value. The substring converted is the longest initial
  32. subsequence of <[str]>, beginning with the first
  33. non-whitespace character, that has the format:
  34. .[+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>]
  35. The substring contains no characters if <[str]> is empty, consists
  36. entirely of whitespace, or if the first non-whitespace
  37. character is something other than <<+>>, <<->>, <<.>>, or a
  38. digit. If the substring is empty, no conversion is done, and
  39. the value of <[str]> is stored in <<*<[tail]>>>. Otherwise,
  40. the substring is converted, and a pointer to the final string
  41. (which will contain at least the terminating null character of
  42. <[str]>) is stored in <<*<[tail]>>>. If you want no
  43. assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>.
  44. <<strtodf>> is identical to <<strtod>> except for its return type.
  45. This implementation returns the nearest machine number to the
  46. input decimal string. Ties are broken by using the IEEE
  47. round-even rule.
  48. The alternate function <<_strtod_r>> is a reentrant version.
  49. The extra argument <[reent]> is a pointer to a reentrancy structure.
  50. RETURNS
  51. <<strtod>> returns the converted substring value, if any. If
  52. no conversion could be performed, 0 is returned. If the
  53. correct value is out of the range of representable values,
  54. plus or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is
  55. stored in errno. If the correct value would cause underflow, 0
  56. is returned and <<ERANGE>> is stored in errno.
  57. Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
  58. <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
  59. */
  60. /****************************************************************
  61. *
  62. * The author of this software is David M. Gay.
  63. *
  64. * Copyright (c) 1991 by AT&T.
  65. *
  66. * Permission to use, copy, modify, and distribute this software for any
  67. * purpose without fee is hereby granted, provided that this entire notice
  68. * is included in all copies of any software which is or includes a copy
  69. * or modification of this software and in all copies of the supporting
  70. * documentation for such software.
  71. *
  72. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
  73. * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
  74. * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
  75. * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  76. *
  77. ***************************************************************/
  78. /* Please send bug reports to
  79. David M. Gay
  80. AT&T Bell Laboratories, Room 2C-463
  81. 600 Mountain Avenue
  82. Murray Hill, NJ 07974-2070
  83. U.S.A.
  84. dmg@research.att.com or research!dmg
  85. */
  86. #include <string.h>
  87. #include <float.h>
  88. #include <errno.h>
  89. #include "mprec.h"
  90. double
  91. _DEFUN (_strtod_r, (ptr, s00, se),
  92. struct _Jv_reent *ptr _AND
  93. _CONST char *s00 _AND
  94. char **se)
  95. {
  96. int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, e1, esign, i, j,
  97. k, nd, nd0, nf, nz, nz0, sign;
  98. int digits = 0; /* Number of digits found in fraction part. */
  99. long e;
  100. _CONST char *s, *s0, *s1;
  101. double aadj, aadj1, adj;
  102. long L;
  103. unsigned long y, z;
  104. union double_union rv, rv0;
  105. _Jv_Bigint *bb = NULL, *bb1, *bd = NULL, *bd0, *bs = NULL, *delta = NULL;
  106. sign = nz0 = nz = 0;
  107. rv.d = 0.;
  108. for (s = s00;; s++)
  109. switch (*s)
  110. {
  111. case '-':
  112. sign = 1;
  113. /* no break */
  114. case '+':
  115. if (*++s)
  116. goto break2;
  117. /* no break */
  118. case 0:
  119. s = s00;
  120. goto ret;
  121. case '\t':
  122. case '\n':
  123. case '\v':
  124. case '\f':
  125. case '\r':
  126. case ' ':
  127. continue;
  128. default:
  129. goto break2;
  130. }
  131. break2:
  132. if (*s == '0')
  133. {
  134. digits++;
  135. nz0 = 1;
  136. while (*++s == '0')
  137. digits++;
  138. if (!*s)
  139. goto ret;
  140. }
  141. s0 = s;
  142. y = z = 0;
  143. for (nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
  144. {
  145. digits++;
  146. if (nd < 9)
  147. y = 10 * y + c - '0';
  148. else if (nd < 16)
  149. z = 10 * z + c - '0';
  150. }
  151. nd0 = nd;
  152. if (c == '.')
  153. {
  154. c = *++s;
  155. if (!nd)
  156. {
  157. for (; c == '0'; c = *++s)
  158. {
  159. digits++;
  160. nz++;
  161. }
  162. if (c > '0' && c <= '9')
  163. {
  164. digits++;
  165. s0 = s;
  166. nf += nz;
  167. nz = 0;
  168. goto have_dig;
  169. }
  170. goto dig_done;
  171. }
  172. for (; c >= '0' && c <= '9'; c = *++s)
  173. {
  174. digits++;
  175. have_dig:
  176. nz++;
  177. if (c -= '0')
  178. {
  179. nf += nz;
  180. for (i = 1; i < nz; i++)
  181. if (nd++ < 9)
  182. y *= 10;
  183. else if (nd <= DBL_DIG + 1)
  184. z *= 10;
  185. if (nd++ < 9)
  186. y = 10 * y + c;
  187. else if (nd <= DBL_DIG + 1)
  188. z = 10 * z + c;
  189. nz = 0;
  190. }
  191. }
  192. }
  193. dig_done:
  194. e = 0;
  195. if (c == 'e' || c == 'E')
  196. {
  197. if (!nd && !nz && !nz0)
  198. {
  199. s = s00;
  200. goto ret;
  201. }
  202. s00 = s;
  203. esign = 0;
  204. switch (c = *++s)
  205. {
  206. case '-':
  207. esign = 1;
  208. case '+':
  209. c = *++s;
  210. }
  211. if (c >= '0' && c <= '9')
  212. {
  213. while (c == '0')
  214. c = *++s;
  215. if (c > '0' && c <= '9')
  216. {
  217. e = c - '0';
  218. s1 = s;
  219. while ((c = *++s) >= '0' && c <= '9')
  220. e = 10 * e + c - '0';
  221. if (s - s1 > 8)
  222. /* Avoid confusion from exponents
  223. * so large that e might overflow.
  224. */
  225. e = 9999999L;
  226. if (esign)
  227. e = -e;
  228. }
  229. }
  230. else
  231. {
  232. /* No exponent after an 'E' : that's an error. */
  233. ptr->_errno = EINVAL;
  234. e = 0;
  235. s = s00;
  236. goto ret;
  237. }
  238. }
  239. if (!nd)
  240. {
  241. if (!nz && !nz0)
  242. s = s00;
  243. goto ret;
  244. }
  245. e1 = e -= nf;
  246. /* Now we have nd0 digits, starting at s0, followed by a
  247. * decimal point, followed by nd-nd0 digits. The number we're
  248. * after is the integer represented by those digits times
  249. * 10**e */
  250. if (!nd0)
  251. nd0 = nd;
  252. k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
  253. rv.d = y;
  254. if (k > 9)
  255. rv.d = tens[k - 9] * rv.d + z;
  256. bd0 = 0;
  257. if (nd <= DBL_DIG
  258. #ifndef RND_PRODQUOT
  259. && FLT_ROUNDS == 1
  260. #endif
  261. )
  262. {
  263. if (!e)
  264. goto ret;
  265. if (e > 0)
  266. {
  267. if (e <= Ten_pmax)
  268. {
  269. #ifdef VAX
  270. goto vax_ovfl_check;
  271. #else
  272. /* rv.d = */ rounded_product (rv.d, tens[e]);
  273. goto ret;
  274. #endif
  275. }
  276. i = DBL_DIG - nd;
  277. if (e <= Ten_pmax + i)
  278. {
  279. /* A fancier test would sometimes let us do
  280. * this for larger i values.
  281. */
  282. e -= i;
  283. rv.d *= tens[i];
  284. #ifdef VAX
  285. /* VAX exponent range is so narrow we must
  286. * worry about overflow here...
  287. */
  288. vax_ovfl_check:
  289. word0 (rv) -= P * Exp_msk1;
  290. /* rv.d = */ rounded_product (rv.d, tens[e]);
  291. if ((word0 (rv) & Exp_mask)
  292. > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P))
  293. goto ovfl;
  294. word0 (rv) += P * Exp_msk1;
  295. #else
  296. /* rv.d = */ rounded_product (rv.d, tens[e]);
  297. #endif
  298. goto ret;
  299. }
  300. }
  301. #ifndef Inaccurate_Divide
  302. else if (e >= -Ten_pmax)
  303. {
  304. /* rv.d = */ rounded_quotient (rv.d, tens[-e]);
  305. goto ret;
  306. }
  307. #endif
  308. }
  309. e1 += nd - k;
  310. /* Get starting approximation = rv.d * 10**e1 */
  311. if (e1 > 0)
  312. {
  313. if ((i = e1 & 15))
  314. rv.d *= tens[i];
  315. if (e1 &= ~15)
  316. {
  317. if (e1 > DBL_MAX_10_EXP)
  318. {
  319. ovfl:
  320. ptr->_errno = ERANGE;
  321. /* Force result to IEEE infinity. */
  322. word0 (rv) = Exp_mask;
  323. word1 (rv) = 0;
  324. if (bd0)
  325. goto retfree;
  326. goto ret;
  327. }
  328. if (e1 >>= 4)
  329. {
  330. for (j = 0; e1 > 1; j++, e1 >>= 1)
  331. if (e1 & 1)
  332. rv.d *= bigtens[j];
  333. /* The last multiplication could overflow. */
  334. word0 (rv) -= P * Exp_msk1;
  335. rv.d *= bigtens[j];
  336. if ((z = word0 (rv) & Exp_mask)
  337. > Exp_msk1 * (DBL_MAX_EXP + Bias - P))
  338. goto ovfl;
  339. if (z > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P))
  340. {
  341. /* set to largest number */
  342. /* (Can't trust DBL_MAX) */
  343. word0 (rv) = Big0;
  344. #ifndef _DOUBLE_IS_32BITS
  345. word1 (rv) = Big1;
  346. #endif
  347. }
  348. else
  349. word0 (rv) += P * Exp_msk1;
  350. }
  351. }
  352. }
  353. else if (e1 < 0)
  354. {
  355. e1 = -e1;
  356. if ((i = e1 & 15))
  357. rv.d /= tens[i];
  358. if (e1 &= ~15)
  359. {
  360. e1 >>= 4;
  361. if (e1 >= 1 << n_bigtens)
  362. goto undfl;
  363. for (j = 0; e1 > 1; j++, e1 >>= 1)
  364. if (e1 & 1)
  365. rv.d *= tinytens[j];
  366. /* The last multiplication could underflow. */
  367. rv0.d = rv.d;
  368. rv.d *= tinytens[j];
  369. if (!rv.d)
  370. {
  371. rv.d = 2. * rv0.d;
  372. rv.d *= tinytens[j];
  373. if (!rv.d)
  374. {
  375. undfl:
  376. rv.d = 0.;
  377. ptr->_errno = ERANGE;
  378. if (bd0)
  379. goto retfree;
  380. goto ret;
  381. }
  382. #ifndef _DOUBLE_IS_32BITS
  383. word0 (rv) = Tiny0;
  384. word1 (rv) = Tiny1;
  385. #else
  386. word0 (rv) = Tiny1;
  387. #endif
  388. /* The refinement below will clean
  389. * this approximation up.
  390. */
  391. }
  392. }
  393. }
  394. /* Now the hard part -- adjusting rv to the correct value.*/
  395. /* Put digits into bd: true value = bd * 10^e */
  396. bd0 = s2b (ptr, s0, nd0, nd, y);
  397. for (;;)
  398. {
  399. bd = Balloc (ptr, bd0->_k);
  400. Bcopy (bd, bd0);
  401. bb = d2b (ptr, rv.d, &bbe, &bbbits); /* rv.d = bb * 2^bbe */
  402. bs = i2b (ptr, 1);
  403. if (e >= 0)
  404. {
  405. bb2 = bb5 = 0;
  406. bd2 = bd5 = e;
  407. }
  408. else
  409. {
  410. bb2 = bb5 = -e;
  411. bd2 = bd5 = 0;
  412. }
  413. if (bbe >= 0)
  414. bb2 += bbe;
  415. else
  416. bd2 -= bbe;
  417. bs2 = bb2;
  418. #ifdef Sudden_Underflow
  419. #ifdef IBM
  420. j = 1 + 4 * P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
  421. #else
  422. j = P + 1 - bbbits;
  423. #endif
  424. #else
  425. i = bbe + bbbits - 1; /* logb(rv.d) */
  426. if (i < Emin) /* denormal */
  427. j = bbe + (P - Emin);
  428. else
  429. j = P + 1 - bbbits;
  430. #endif
  431. bb2 += j;
  432. bd2 += j;
  433. i = bb2 < bd2 ? bb2 : bd2;
  434. if (i > bs2)
  435. i = bs2;
  436. if (i > 0)
  437. {
  438. bb2 -= i;
  439. bd2 -= i;
  440. bs2 -= i;
  441. }
  442. if (bb5 > 0)
  443. {
  444. bs = pow5mult (ptr, bs, bb5);
  445. bb1 = mult (ptr, bs, bb);
  446. Bfree (ptr, bb);
  447. bb = bb1;
  448. }
  449. if (bb2 > 0)
  450. bb = lshift (ptr, bb, bb2);
  451. if (bd5 > 0)
  452. bd = pow5mult (ptr, bd, bd5);
  453. if (bd2 > 0)
  454. bd = lshift (ptr, bd, bd2);
  455. if (bs2 > 0)
  456. bs = lshift (ptr, bs, bs2);
  457. delta = diff (ptr, bb, bd);
  458. dsign = delta->_sign;
  459. delta->_sign = 0;
  460. i = cmp (delta, bs);
  461. if (i < 0)
  462. {
  463. /* Error is less than half an ulp -- check for
  464. * special case of mantissa a power of two.
  465. */
  466. if (dsign || word1 (rv) || word0 (rv) & Bndry_mask)
  467. break;
  468. delta = lshift (ptr, delta, Log2P);
  469. if (cmp (delta, bs) > 0)
  470. goto drop_down;
  471. break;
  472. }
  473. if (i == 0)
  474. {
  475. /* exactly half-way between */
  476. if (dsign)
  477. {
  478. if ((word0 (rv) & Bndry_mask1) == Bndry_mask1
  479. && word1 (rv) == 0xffffffff)
  480. {
  481. /*boundary case -- increment exponent*/
  482. word0 (rv) = (word0 (rv) & Exp_mask)
  483. + Exp_msk1
  484. #ifdef IBM
  485. | Exp_msk1 >> 4
  486. #endif
  487. ;
  488. #ifndef _DOUBLE_IS_32BITS
  489. word1 (rv) = 0;
  490. #endif
  491. break;
  492. }
  493. }
  494. else if (!(word0 (rv) & Bndry_mask) && !word1 (rv))
  495. {
  496. drop_down:
  497. /* boundary case -- decrement exponent */
  498. #ifdef Sudden_Underflow
  499. L = word0 (rv) & Exp_mask;
  500. #ifdef IBM
  501. if (L < Exp_msk1)
  502. #else
  503. if (L <= Exp_msk1)
  504. #endif
  505. goto undfl;
  506. L -= Exp_msk1;
  507. #else
  508. L = (word0 (rv) & Exp_mask) - Exp_msk1;
  509. #endif
  510. word0 (rv) = L | Bndry_mask1;
  511. #ifndef _DOUBLE_IS_32BITS
  512. word1 (rv) = 0xffffffff;
  513. #endif
  514. #ifdef IBM
  515. goto cont;
  516. #else
  517. break;
  518. #endif
  519. }
  520. #ifndef ROUND_BIASED
  521. if (!(word1 (rv) & LSB))
  522. break;
  523. #endif
  524. if (dsign)
  525. rv.d += ulp (rv.d);
  526. #ifndef ROUND_BIASED
  527. else
  528. {
  529. rv.d -= ulp (rv.d);
  530. #ifndef Sudden_Underflow
  531. if (!rv.d)
  532. goto undfl;
  533. #endif
  534. }
  535. #endif
  536. break;
  537. }
  538. if ((aadj = ratio (delta, bs)) <= 2.)
  539. {
  540. if (dsign)
  541. aadj = aadj1 = 1.;
  542. else if (word1 (rv) || word0 (rv) & Bndry_mask)
  543. {
  544. #ifndef Sudden_Underflow
  545. if (word1 (rv) == Tiny1 && !word0 (rv))
  546. goto undfl;
  547. #endif
  548. aadj = 1.;
  549. aadj1 = -1.;
  550. }
  551. else
  552. {
  553. /* special case -- power of FLT_RADIX to be */
  554. /* rounded down... */
  555. if (aadj < 2. / FLT_RADIX)
  556. aadj = 1. / FLT_RADIX;
  557. else
  558. aadj *= 0.5;
  559. aadj1 = -aadj;
  560. }
  561. }
  562. else
  563. {
  564. aadj *= 0.5;
  565. aadj1 = dsign ? aadj : -aadj;
  566. #ifdef Check_FLT_ROUNDS
  567. switch (FLT_ROUNDS)
  568. {
  569. case 2: /* towards +infinity */
  570. aadj1 -= 0.5;
  571. break;
  572. case 0: /* towards 0 */
  573. case 3: /* towards -infinity */
  574. aadj1 += 0.5;
  575. }
  576. #else
  577. if (FLT_ROUNDS == 0)
  578. aadj1 += 0.5;
  579. #endif
  580. }
  581. y = word0 (rv) & Exp_mask;
  582. /* Check for overflow */
  583. if (y == Exp_msk1 * (DBL_MAX_EXP + Bias - 1))
  584. {
  585. rv0.d = rv.d;
  586. word0 (rv) -= P * Exp_msk1;
  587. adj = aadj1 * ulp (rv.d);
  588. rv.d += adj;
  589. if ((word0 (rv) & Exp_mask) >=
  590. Exp_msk1 * (DBL_MAX_EXP + Bias - P))
  591. {
  592. if (word0 (rv0) == Big0 && word1 (rv0) == Big1)
  593. goto ovfl;
  594. #ifdef _DOUBLE_IS_32BITS
  595. word0 (rv) = Big1;
  596. #else
  597. word0 (rv) = Big0;
  598. word1 (rv) = Big1;
  599. #endif
  600. goto cont;
  601. }
  602. else
  603. word0 (rv) += P * Exp_msk1;
  604. }
  605. else
  606. {
  607. #ifdef Sudden_Underflow
  608. if ((word0 (rv) & Exp_mask) <= P * Exp_msk1)
  609. {
  610. rv0.d = rv.d;
  611. word0 (rv) += P * Exp_msk1;
  612. adj = aadj1 * ulp (rv.d);
  613. rv.d += adj;
  614. #ifdef IBM
  615. if ((word0 (rv) & Exp_mask) < P * Exp_msk1)
  616. #else
  617. if ((word0 (rv) & Exp_mask) <= P * Exp_msk1)
  618. #endif
  619. {
  620. if (word0 (rv0) == Tiny0
  621. && word1 (rv0) == Tiny1)
  622. goto undfl;
  623. word0 (rv) = Tiny0;
  624. word1 (rv) = Tiny1;
  625. goto cont;
  626. }
  627. else
  628. word0 (rv) -= P * Exp_msk1;
  629. }
  630. else
  631. {
  632. adj = aadj1 * ulp (rv.d);
  633. rv.d += adj;
  634. }
  635. #else
  636. /* Compute adj so that the IEEE rounding rules will
  637. * correctly round rv.d + adj in some half-way cases.
  638. * If rv.d * ulp(rv.d) is denormalized (i.e.,
  639. * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
  640. * trouble from bits lost to denormalization;
  641. * example: 1.2e-307 .
  642. */
  643. if (y <= (P - 1) * Exp_msk1 && aadj >= 1.)
  644. {
  645. aadj1 = (double) (int) (aadj + 0.5);
  646. if (!dsign)
  647. aadj1 = -aadj1;
  648. }
  649. adj = aadj1 * ulp (rv.d);
  650. rv.d += adj;
  651. #endif
  652. }
  653. z = word0 (rv) & Exp_mask;
  654. if (y == z)
  655. {
  656. /* Can we stop now? */
  657. L = aadj;
  658. aadj -= L;
  659. /* The tolerances below are conservative. */
  660. if (dsign || word1 (rv) || word0 (rv) & Bndry_mask)
  661. {
  662. if (aadj < .4999999 || aadj > .5000001)
  663. break;
  664. }
  665. else if (aadj < .4999999 / FLT_RADIX)
  666. break;
  667. }
  668. cont:
  669. Bfree (ptr, bb);
  670. Bfree (ptr, bd);
  671. Bfree (ptr, bs);
  672. Bfree (ptr, delta);
  673. }
  674. retfree:
  675. Bfree (ptr, bb);
  676. Bfree (ptr, bd);
  677. Bfree (ptr, bs);
  678. Bfree (ptr, bd0);
  679. Bfree (ptr, delta);
  680. ret:
  681. if (se)
  682. *se = (char *) s;
  683. if (digits == 0)
  684. ptr->_errno = EINVAL;
  685. return sign ? -rv.d : rv.d;
  686. }