1<html lang="en"> 2<head> 3<title>strtod - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib"> 9<link rel="prev" href="rand48.html#rand48" title="rand48"> 10<link rel="next" href="strtol.html#strtol" title="strtol"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="strtod"></a> 29<p> 30Next: <a rel="next" accesskey="n" href="strtol.html#strtol">strtol</a>, 31Previous: <a rel="previous" accesskey="p" href="rand48.html#rand48">rand48</a>, 32Up: <a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a> 33<hr> 34</div> 35 36<h3 class="section">2.34 <code>strtod</code>, <code>strtof</code>—string to double or float</h3> 37 38<p><a name="index-strtod-79"></a><a name="index-g_t_005fstrtod_005fr-80"></a><a name="index-strtof-81"></a><strong>Synopsis</strong> 39<pre class="example"> #include <stdlib.h> 40 double strtod(const char *<var>str</var>, char **<var>tail</var>); 41 float strtof(const char *<var>str</var>, char **<var>tail</var>); 42 43 double _strtod_r(void *<var>reent</var>, 44 const char *<var>str</var>, char **<var>tail</var>); 45 46</pre> 47 <p><strong>Description</strong><br> 48The function <code>strtod</code> parses the character string <var>str</var>, 49producing a substring which can be converted to a double 50value. The substring converted is the longest initial 51subsequence of <var>str</var>, beginning with the first 52non-whitespace character, that has one of these formats: 53<pre class="smallexample"> [+|-]<var>digits</var>[.[<var>digits</var>]][(e|E)[+|-]<var>digits</var>] 54 [+|-].<var>digits</var>[(e|E)[+|-]<var>digits</var>] 55 [+|-](i|I)(n|N)(f|F)[(i|I)(n|N)(i|I)(t|T)(y|Y)] 56 [+|-](n|N)(a|A)(n|N)[<(>[<var>hexdigits</var>]<)>] 57 [+|-]0(x|X)<var>hexdigits</var>[.[<var>hexdigits</var>]][(p|P)[+|-]<var>digits</var>] 58 [+|-]0(x|X).<var>hexdigits</var>[(p|P)[+|-]<var>digits</var>] 59</pre> 60 <p>The substring contains no characters if <var>str</var> is empty, consists 61entirely of whitespace, or if the first non-whitespace 62character is something other than <code>+</code>, <code>-</code>, <code>.</code>, or a 63digit, and cannot be parsed as infinity or NaN. If the platform 64does not support NaN, then NaN is treated as an empty substring. 65If the substring is empty, no conversion is done, and 66the value of <var>str</var> is stored in <code>*</code><var>tail</var>. Otherwise, 67the substring is converted, and a pointer to the final string 68(which will contain at least the terminating null character of 69<var>str</var>) is stored in <code>*</code><var>tail</var>. If you want no 70assignment to <code>*</code><var>tail</var>, pass a null pointer as <var>tail</var>. 71<code>strtof</code> is identical to <code>strtod</code> except for its return type. 72 73 <p>This implementation returns the nearest machine number to the 74input decimal string. Ties are broken by using the IEEE 75round-even rule. However, <code>strtof</code> is currently subject to 76double rounding errors. 77 78 <p>The alternate function <code>_strtod_r</code> is a reentrant version. 79The extra argument <var>reent</var> is a pointer to a reentrancy structure. 80 81 <p><br> 82<strong>Returns</strong><br> 83<code>strtod</code> returns the converted substring value, if any. If 84no conversion could be performed, 0 is returned. If the 85correct value is out of the range of representable values, 86plus or minus <code>HUGE_VAL</code> is returned, and <code>ERANGE</code> is 87stored in errno. If the correct value would cause underflow, 0 88is returned and <code>ERANGE</code> is stored in errno. 89 90 <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>, 91<code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>. 92 93 <p><br> 94 95 </body></html> 96 97