1.\" Copyright (c) 1990, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the American National Standards Committee X3, on Information 6.\" Processing Systems. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" $OpenBSD: strtod.3,v 1.14 2008/09/13 22:48:45 martynas Exp $ 33.\" 34.Dd $Mdocdate: September 13 2008 $ 35.Dt STRTOD 3 36.Os 37.Sh NAME 38.Nm strtod , 39.Nm strtof , 40.Nm strtold 41.Nd convert 42.Tn ASCII 43string to double, float or long double 44.Sh SYNOPSIS 45.Fd #include <math.h> 46.Fd #include <stdlib.h> 47.Ft double 48.Fn strtod "const char *nptr" "char **endptr" 49.Pp 50.Ft float 51.Fn strtof "const char *nptr" "char **endptr" 52.Pp 53.Ft long double 54.Fn strtold "const char *nptr" "char **endptr" 55.Sh DESCRIPTION 56The 57.Fn strtod 58function converts the initial portion of the string pointed to by 59.Fa nptr 60to 61.Li double 62representation. 63The 64.Fn strtof 65function converts the initial portion of the string pointed to by 66.Fa nptr 67to 68.Li float 69representation. 70The 71.Fn strtold 72function converts the initial portion of the string pointed to by 73.Fa nptr 74to 75.Li long double 76representation. 77.Pp 78The expected form of the string is an optional plus 79.Pq Ql + 80or minus sign 81.Pq Ql - 82followed by a sequence of digits optionally containing 83a decimal-point character, optionally followed by an exponent. 84An exponent consists of an 85.Sq E 86or 87.Sq e , 88followed by an optional plus or minus sign, followed by a sequence of digits. 89.Pp 90Leading whitespace characters in the string (as defined by the 91.Xr isspace 3 92function) are skipped. 93.Sh RETURN VALUES 94The 95.Fn strtod , 96.Fn strtof 97and 98.Fn strtold 99functions return the converted value, if any. 100.Pp 101If 102.Fa endptr 103is not 104.Dv NULL , 105a pointer to the character after the last character used 106in the conversion is stored in the location referenced by 107.Fa endptr . 108.Pp 109If no conversion is performed, zero is returned and the value of 110.Fa nptr 111is stored in the location referenced by 112.Fa endptr . 113.Pp 114If the correct value would cause overflow, plus or minus 115.Dv HUGE_VAL 116is returned (according to the sign of the value), and 117.Er ERANGE 118is stored in 119.Va errno . 120If the correct value would cause underflow, zero is returned and 121.Er ERANGE 122is stored in 123.Va errno . 124.Sh ERRORS 125.Bl -tag -width Er 126.It Bq Er ERANGE 127Overflow or underflow occurred. 128.El 129.Sh SEE ALSO 130.Xr atof 3 , 131.Xr atoi 3 , 132.Xr atol 3 , 133.Xr strtol 3 , 134.Xr strtoul 3 135.Sh STANDARDS 136The 137.Fn strtod 138function conforms to 139.St -ansiC-89 . 140The 141.Fn strtof 142and 143.Fn strtold 144functions conform to 145.St -ansiC-99 . 146