1*2fe8fb19SBen Gras.\" $NetBSD: strtod.3,v 1.20 2007/10/24 13:42:10 reed Exp $ 2*2fe8fb19SBen Gras.\" 3*2fe8fb19SBen Gras.\" Copyright (c) 1990, 1991, 1993 4*2fe8fb19SBen Gras.\" The Regents of the University of California. All rights reserved. 5*2fe8fb19SBen Gras.\" 6*2fe8fb19SBen Gras.\" This code is derived from software contributed to Berkeley by 7*2fe8fb19SBen Gras.\" the American National Standards Committee X3, on Information 8*2fe8fb19SBen Gras.\" Processing Systems. 9*2fe8fb19SBen Gras.\" 10*2fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 11*2fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 12*2fe8fb19SBen Gras.\" are met: 13*2fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 14*2fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 15*2fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 16*2fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 17*2fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 18*2fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors 19*2fe8fb19SBen Gras.\" may be used to endorse or promote products derived from this software 20*2fe8fb19SBen Gras.\" without specific prior written permission. 21*2fe8fb19SBen Gras.\" 22*2fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*2fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*2fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*2fe8fb19SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*2fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*2fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*2fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*2fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*2fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*2fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*2fe8fb19SBen Gras.\" SUCH DAMAGE. 33*2fe8fb19SBen Gras.\" 34*2fe8fb19SBen Gras.\" from: @(#)strtod.3 8.1 (Berkeley) 6/4/93 35*2fe8fb19SBen Gras.\" 36*2fe8fb19SBen Gras.Dd March 12, 2006 37*2fe8fb19SBen Gras.Dt STRTOD 3 38*2fe8fb19SBen Gras.Os 39*2fe8fb19SBen Gras.Sh NAME 40*2fe8fb19SBen Gras.Nm strtod , 41*2fe8fb19SBen Gras.Nm strtof , 42*2fe8fb19SBen Gras.Nm strtold 43*2fe8fb19SBen Gras.Nd convert 44*2fe8fb19SBen Gras.Tn ASCII 45*2fe8fb19SBen Grasstring to double, float, or long double 46*2fe8fb19SBen Gras.Sh LIBRARY 47*2fe8fb19SBen Gras.Lb libc 48*2fe8fb19SBen Gras.Sh SYNOPSIS 49*2fe8fb19SBen Gras.In stdlib.h 50*2fe8fb19SBen Gras.Ft double 51*2fe8fb19SBen Gras.Fn strtod "const char * restrict nptr" "char ** restrict endptr" 52*2fe8fb19SBen Gras.Ft float 53*2fe8fb19SBen Gras.Fn strtof "const char * restrict nptr" "char ** restrict endptr" 54*2fe8fb19SBen Gras.Ft long double 55*2fe8fb19SBen Gras.Fn strtold "const char * restrict nptr" "char ** restrict endptr" 56*2fe8fb19SBen Gras.Sh DESCRIPTION 57*2fe8fb19SBen GrasThe 58*2fe8fb19SBen Gras.Fn strtod 59*2fe8fb19SBen Grasfunction converts the initial portion of the string 60*2fe8fb19SBen Graspointed to by 61*2fe8fb19SBen Gras.Fa nptr 62*2fe8fb19SBen Grasto 63*2fe8fb19SBen Gras.Em double 64*2fe8fb19SBen Grasrepresentation. 65*2fe8fb19SBen Gras.Pp 66*2fe8fb19SBen GrasThe 67*2fe8fb19SBen Gras.Fn strtof 68*2fe8fb19SBen Grasfunction converts the initial portion of the string 69*2fe8fb19SBen Graspointed to by 70*2fe8fb19SBen Gras.Fa nptr 71*2fe8fb19SBen Grasto 72*2fe8fb19SBen Gras.Em float 73*2fe8fb19SBen Grasrepresentation. 74*2fe8fb19SBen Gras.Pp 75*2fe8fb19SBen GrasThe 76*2fe8fb19SBen Gras.Fn strtold 77*2fe8fb19SBen Grasfunction converts the initial portion of the string 78*2fe8fb19SBen Graspointed to by 79*2fe8fb19SBen Gras.Fa nptr 80*2fe8fb19SBen Grasto 81*2fe8fb19SBen Gras.Em long double 82*2fe8fb19SBen Grasrepresentation. 83*2fe8fb19SBen Gras.Pp 84*2fe8fb19SBen GrasThe expected form of the string is an optional plus 85*2fe8fb19SBen Gras.Pq Sq + 86*2fe8fb19SBen Grasor minus sign 87*2fe8fb19SBen Gras.Pq Sq \- 88*2fe8fb19SBen Grasfollowed by one of the following: 89*2fe8fb19SBen Gras.Bl -dash 90*2fe8fb19SBen Gras.It 91*2fe8fb19SBen Grasa sequence of digits optionally containing 92*2fe8fb19SBen Grasa decimal-point character, optionally followed by an exponent. 93*2fe8fb19SBen GrasAn exponent consists of an 94*2fe8fb19SBen Gras.Sq E 95*2fe8fb19SBen Grasor 96*2fe8fb19SBen Gras.Sq e , 97*2fe8fb19SBen Grasfollowed by an optional plus 98*2fe8fb19SBen Grasor minus sign, followed by a sequence of digits. 99*2fe8fb19SBen Gras.It 100*2fe8fb19SBen Grasone of 101*2fe8fb19SBen Gras.Li INF 102*2fe8fb19SBen Grasor 103*2fe8fb19SBen Gras.Li INFINITY , 104*2fe8fb19SBen Grasignoring case. 105*2fe8fb19SBen Gras.It 106*2fe8fb19SBen Grasone of 107*2fe8fb19SBen Gras.Li NAN 108*2fe8fb19SBen Grasor 109*2fe8fb19SBen Gras.Li NAN(n-char-sequence-opt) , 110*2fe8fb19SBen Grasignoring case. 111*2fe8fb19SBen GrasThis implementation currently does not interpret such a sequence. 112*2fe8fb19SBen Gras.El 113*2fe8fb19SBen Gras.Pp 114*2fe8fb19SBen GrasLeading white-space characters in the string (as defined by the 115*2fe8fb19SBen Gras.Xr isspace 3 116*2fe8fb19SBen Grasfunction) are skipped. 117*2fe8fb19SBen Gras.Sh RETURN VALUES 118*2fe8fb19SBen GrasThe 119*2fe8fb19SBen Gras.Fn strtod , 120*2fe8fb19SBen Gras.Fn strtof , 121*2fe8fb19SBen Grasand 122*2fe8fb19SBen Gras.Fn strtold 123*2fe8fb19SBen Grasfunctions return the converted value, if any. 124*2fe8fb19SBen Gras.Pp 125*2fe8fb19SBen GrasA character sequence 126*2fe8fb19SBen Gras.Li INF 127*2fe8fb19SBen Grasor 128*2fe8fb19SBen Gras.Li INFINITY 129*2fe8fb19SBen Grasis converted to \*(If, 130*2fe8fb19SBen Grasif supported, else to the largest finite floating-point number representable 131*2fe8fb19SBen Grason the machine (i.e., 132*2fe8fb19SBen Gras.Tn VAX ) . 133*2fe8fb19SBen Gras.Pp 134*2fe8fb19SBen GrasA character sequence 135*2fe8fb19SBen Gras.Li NAN 136*2fe8fb19SBen Grasor 137*2fe8fb19SBen Gras.Li NAN(n-char-sequence-opt) 138*2fe8fb19SBen Grasis converted to a quiet \*(Na, if supported, else remains unrecognized (i.e., 139*2fe8fb19SBen Gras.Tn VAX ) . 140*2fe8fb19SBen Gras.Pp 141*2fe8fb19SBen GrasIf 142*2fe8fb19SBen Gras.Fa endptr 143*2fe8fb19SBen Grasis not 144*2fe8fb19SBen Gras.Dv NULL , 145*2fe8fb19SBen Grasa pointer to the character after the last character used 146*2fe8fb19SBen Grasin the conversion is stored in the location referenced by 147*2fe8fb19SBen Gras.Fa endptr . 148*2fe8fb19SBen Gras.Pp 149*2fe8fb19SBen GrasIf no conversion is performed, zero is returned and the value of 150*2fe8fb19SBen Gras.Fa nptr 151*2fe8fb19SBen Grasis stored in the location referenced by 152*2fe8fb19SBen Gras.Fa endptr . 153*2fe8fb19SBen Gras.Pp 154*2fe8fb19SBen GrasIf the correct value would cause overflow, plus or minus 155*2fe8fb19SBen Gras.Dv HUGE_VAL , 156*2fe8fb19SBen Gras.Dv HUGE_VALF , 157*2fe8fb19SBen Grasor 158*2fe8fb19SBen Gras.Dv HUGE_VALL 159*2fe8fb19SBen Grasis returned (according to the return type and sign of the value), and 160*2fe8fb19SBen Gras.Dv ERANGE 161*2fe8fb19SBen Grasis stored in 162*2fe8fb19SBen Gras.Va errno . 163*2fe8fb19SBen GrasIf the correct value would cause underflow, zero is 164*2fe8fb19SBen Grasreturned and 165*2fe8fb19SBen Gras.Dv ERANGE 166*2fe8fb19SBen Grasis stored in 167*2fe8fb19SBen Gras.Va errno . 168*2fe8fb19SBen Gras.Sh ERRORS 169*2fe8fb19SBen Gras.Bl -tag -width Er 170*2fe8fb19SBen Gras.It Bq Er ERANGE 171*2fe8fb19SBen GrasOverflow or underflow occurred. 172*2fe8fb19SBen Gras.El 173*2fe8fb19SBen Gras.Sh SEE ALSO 174*2fe8fb19SBen Gras.Xr atof 3 , 175*2fe8fb19SBen Gras.Xr atoi 3 , 176*2fe8fb19SBen Gras.Xr atol 3 , 177*2fe8fb19SBen Gras.Xr math 3 , 178*2fe8fb19SBen Gras.Xr strtol 3 , 179*2fe8fb19SBen Gras.Xr strtoul 3 180*2fe8fb19SBen Gras.Sh STANDARDS 181*2fe8fb19SBen GrasThe 182*2fe8fb19SBen Gras.Fn strtod 183*2fe8fb19SBen Grasfunction 184*2fe8fb19SBen Grasconforms to 185*2fe8fb19SBen Gras.St -ansiC . 186*2fe8fb19SBen GrasThe 187*2fe8fb19SBen Gras.Fn strtof 188*2fe8fb19SBen Grasand 189*2fe8fb19SBen Gras.Fn strtold 190*2fe8fb19SBen Grasfunctions conform to 191*2fe8fb19SBen Gras.St -isoC-99 . 192*2fe8fb19SBen Gras.Sh HISTORY 193*2fe8fb19SBen GrasThe 194*2fe8fb19SBen Gras.Fn strtof 195*2fe8fb19SBen Grasand 196*2fe8fb19SBen Gras.Fn strtold 197*2fe8fb19SBen Grasfunctions appeared in 198*2fe8fb19SBen Gras.Nx 4.0 . 199