Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>strtod (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="strtod (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="strtod (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Stdlib.html#Stdlib" rel="up" title="Stdlib">
  16. <link href="strtol.html#strtol" rel="next" title="strtol">
  17. <link href="rpmatch.html#rpmatch" rel="prev" title="rpmatch">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="strtod"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="strtol.html#strtol" accesskey="n" rel="next">strtol</a>, Previous: <a href="rpmatch.html#rpmatch" accesskey="p" rel="prev">rpmatch</a>, Up: <a href="Stdlib.html#Stdlib" accesskey="u" rel="up">Stdlib</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="strtod_002c-strtof_002c-strtold_002c-strtod_005fl_002c-strtof_005fl_002c-strtold_005fl_002d_002d_002dstring-to-double-or-float"></a>
  54. <h3 class="section">2.37 <code>strtod</code>, <code>strtof</code>, <code>strtold</code>, <code>strtod_l</code>, <code>strtof_l</code>, <code>strtold_l</code>&mdash;string to double or float</h3>
  55. <a name="index-strtod"></a>
  56. <a name="index-strtof"></a>
  57. <a name="index-strtold"></a>
  58. <a name="index-strtod_005fl"></a>
  59. <a name="index-strtof_005fl"></a>
  60. <a name="index-strtold_005fl"></a>
  61. <a name="index-_005fstrtod_005fr"></a>
  62. <p><strong>Synopsis</strong>
  63. </p><div class="example">
  64. <pre class="example">#include &lt;stdlib.h&gt;
  65. double strtod(const char *restrict <var>str</var>, char **restrict <var>tail</var>);
  66. float strtof(const char *restrict <var>str</var>, char **restrict <var>tail</var>);
  67. long double strtold(const char *restrict <var>str</var>,
  68. char **restrict <var>tail</var>);
  69. #include &lt;stdlib.h&gt;
  70. double strtod_l(const char *restrict <var>str</var>, char **restrict <var>tail</var>,
  71. locale_t <var>locale</var>);
  72. float strtof_l(const char *restrict <var>str</var>, char **restrict <var>tail</var>,
  73. locale_t <var>locale</var>);
  74. long double strtold_l(const char *restrict <var>str</var>,
  75. char **restrict <var>tail</var>,
  76. locale_t <var>locale</var>);
  77. double _strtod_r(void *<var>reent</var>,
  78. const char *restrict <var>str</var>, char **restrict <var>tail</var>);
  79. </pre></div>
  80. <p><strong>Description</strong><br>
  81. <code>strtod</code>, <code>strtof</code>, <code>strtold</code> parse the character string
  82. <var>str</var>, producing a substring which can be converted to a double,
  83. float, or long double value, respectively. The substring converted
  84. is the longest initial subsequence of <var>str</var>, beginning with the
  85. first non-whitespace character, that has one of these formats:
  86. </p><div class="smallexample">
  87. <pre class="smallexample">[+|-]<var>digits</var>[.[<var>digits</var>]][(e|E)[+|-]<var>digits</var>]
  88. [+|-].<var>digits</var>[(e|E)[+|-]<var>digits</var>]
  89. [+|-](i|I)(n|N)(f|F)[(i|I)(n|N)(i|I)(t|T)(y|Y)]
  90. [+|-](n|N)(a|A)(n|N)[&lt;(&gt;[<var>hexdigits</var>]&lt;)&gt;]
  91. [+|-]0(x|X)<var>hexdigits</var>[.[<var>hexdigits</var>]][(p|P)[+|-]<var>digits</var>]
  92. [+|-]0(x|X).<var>hexdigits</var>[(p|P)[+|-]<var>digits</var>]
  93. </pre></div>
  94. <p>The substring contains no characters if <var>str</var> is empty, consists
  95. entirely of whitespace, or if the first non-whitespace
  96. character is something other than <code>+</code>, <code>-</code>, <code>.</code>, or a
  97. digit, and cannot be parsed as infinity or NaN. If the platform
  98. does not support NaN, then NaN is treated as an empty substring.
  99. If the substring is empty, no conversion is done, and
  100. the value of <var>str</var> is stored in <code>*<var>tail</var></code>. Otherwise,
  101. the substring is converted, and a pointer to the final string
  102. (which will contain at least the terminating null character of
  103. <var>str</var>) is stored in <code>*<var>tail</var></code>. If you want no
  104. assignment to <code>*<var>tail</var></code>, pass a null pointer as <var>tail</var>.
  105. </p>
  106. <p>This implementation returns the nearest machine number to the
  107. input decimal string. Ties are broken by using the IEEE
  108. round-even rule. However, <code>strtof</code> is currently subject to
  109. double rounding errors.
  110. </p>
  111. <p><code>strtod_l</code>, <code>strtof_l</code>, <code>strtold_l</code> are like <code>strtod</code>,
  112. <code>strtof</code>, <code>strtold</code> but perform the conversion based on the
  113. locale specified by the locale object locale. If <var>locale</var> is
  114. LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is
  115. undefined.
  116. </p>
  117. <p>The alternate function <code>_strtod_r</code> is a reentrant version.
  118. The extra argument <var>reent</var> is a pointer to a reentrancy structure.
  119. </p>
  120. <br>
  121. <p><strong>Returns</strong><br>
  122. These functions return the converted substring value, if any. If
  123. no conversion could be performed, 0 is returned. If the correct
  124. value is out of the range of representable values, plus or minus
  125. <code>HUGE_VAL</code> (<code>HUGE_VALF</code>, <code>HUGE_VALL</code>) is returned, and
  126. <code>ERANGE</code> is stored in errno. If the correct value would cause
  127. underflow, 0 is returned and <code>ERANGE</code> is stored in errno.
  128. </p>
  129. <br>
  130. <p><strong>Portability</strong><br>
  131. <code>strtod</code> is ANSI.
  132. <code>strtof</code>, <code>strtold</code> are C99.
  133. <code>strtod_l</code>, <code>strtof_l</code>, <code>strtold_l</code> are GNU extensions.
  134. </p>
  135. <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
  136. <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
  137. </p>
  138. <br>
  139. <hr>
  140. <div class="header">
  141. <p>
  142. Next: <a href="strtol.html#strtol" accesskey="n" rel="next">strtol</a>, Previous: <a href="rpmatch.html#rpmatch" accesskey="p" rel="prev">rpmatch</a>, Up: <a href="Stdlib.html#Stdlib" accesskey="u" rel="up">Stdlib</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  143. </div>
  144. </body>
  145. </html>