Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

123 lines
5.4KB

  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>atof (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="atof (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="atof (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="atoi.html#atoi" rel="next" title="atoi">
  17. <link href="atexit.html#atexit" rel="prev" title="atexit">
  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="atof"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="atoi.html#atoi" accesskey="n" rel="next">atoi</a>, Previous: <a href="atexit.html#atexit" accesskey="p" rel="prev">atexit</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="atof_002c-atoff_002d_002d_002dstring-to-double-or-float"></a>
  54. <h3 class="section">2.7 <code>atof</code>, <code>atoff</code>&mdash;string to double or float</h3>
  55. <a name="index-atof"></a>
  56. <a name="index-atoff"></a>
  57. <p><strong>Synopsis</strong>
  58. </p><div class="example">
  59. <pre class="example">#include &lt;stdlib.h&gt;
  60. double atof(const char *<var>s</var>);
  61. float atoff(const char *<var>s</var>);
  62. </pre></div>
  63. <p><strong>Description</strong><br>
  64. <code>atof</code> converts the initial portion of a string to a <code>double</code>.
  65. <code>atoff</code> converts the initial portion of a string to a <code>float</code>.
  66. </p>
  67. <p>The functions parse the character string <var>s</var>,
  68. locating a substring which can be converted to a floating-point
  69. value. The substring must match the format:
  70. </p><div class="smallexample">
  71. <pre class="smallexample"> [+|-]<var>digits</var>[.][<var>digits</var>][(e|E)[+|-]<var>digits</var>]
  72. </pre></div>
  73. <p>The substring converted is the longest initial
  74. fragment of <var>s</var> that has the expected format, beginning with
  75. the first non-whitespace character. The substring
  76. is empty if <code>str</code> is empty, consists entirely
  77. of whitespace, or if the first non-whitespace character is
  78. something other than <code>+</code>, <code>-</code>, <code>.</code>, or a digit.
  79. </p>
  80. <p><code>atof(<var>s</var>)</code> is implemented as <code>strtod(<var>s</var>, NULL)</code>.
  81. <code>atoff(<var>s</var>)</code> is implemented as <code>strtof(<var>s</var>, NULL)</code>.
  82. </p>
  83. <br>
  84. <p><strong>Returns</strong><br>
  85. <code>atof</code> returns the converted substring value, if any, as a
  86. <code>double</code>; or <code>0.0</code>, if no conversion could be performed.
  87. If the correct value is out of the range of representable values, plus
  88. or minus <code>HUGE_VAL</code> is returned, and <code>ERANGE</code> is stored in
  89. <code>errno</code>.
  90. If the correct value would cause underflow, <code>0.0</code> is returned
  91. and <code>ERANGE</code> is stored in <code>errno</code>.
  92. </p>
  93. <p><code>atoff</code> obeys the same rules as <code>atof</code>, except that it
  94. returns a <code>float</code>.
  95. </p>
  96. <br>
  97. <p><strong>Portability</strong><br>
  98. <code>atof</code> is ANSI C. <code>atof</code>, <code>atoi</code>, and <code>atol</code> are subsumed by <code>strod</code>
  99. and <code>strol</code>, but are used extensively in existing code. These functions are
  100. less reliable, but may be faster if the argument is verified to be in a valid
  101. range.
  102. </p>
  103. <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
  104. <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
  105. </p>
  106. <br>
  107. <hr>
  108. <div class="header">
  109. <p>
  110. Next: <a href="atoi.html#atoi" accesskey="n" rel="next">atoi</a>, Previous: <a href="atexit.html#atexit" accesskey="p" rel="prev">atexit</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>
  111. </div>
  112. </body>
  113. </html>