xref: /original-bsd/lib/libc/stdlib/strtod.3 (revision 4092c5cc)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  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.\" %sccs.include.redist.man%
9.\"
10.\"     @(#)strtod.3	8.1 (Berkeley) 06/04/93
11.\"
12.Dd
13.Dt STRTOD 3
14.Os
15.Sh NAME
16.Nm strtod
17.Nd convert
18.Tn ASCII
19string to double
20.Sh SYNOPSIS
21.Fd #include <stdlib.h>
22.Ft double
23.Fn strtod "const char *nptr" "char **endptr"
24.Sh DESCRIPTION
25The
26.Fn strtod
27function converts the initial portion of the string
28pointed to by
29.Fa nptr
30to
31.Em double
32representation.
33.Pp
34The expected form of the string is an optional plus (``+'') or minus
35sign (``\-'') followed by a sequence of digits optionally containing
36a decimal-point character, optionally followed by an exponent.
37An exponent consists of an ``E'' or ``e'', followed by an optional plus
38or minus sign, followed by a sequence of digits.
39.Pp
40Leading white-space characters in the string (as defined by the
41.Xr isspace 3
42function) are skipped.
43.Sh RETURN VALUES
44The
45.Fn strtod
46function returns the converted value, if any.
47.Pp
48If
49.Fa endptr
50is not
51.Dv NULL ,
52a pointer to the character after the last character used
53in the conversion is stored in the location referenced by
54.Fa endptr .
55.Pp
56If no conversion is performed, zero is returned and the value of
57.Fa nptr
58is stored in the location referenced by
59.Fa endptr .
60.Pp
61If the correct value would cause overflow, plus or minus
62.Dv HUGE_VAL
63is returned (according to the sign of the value), and
64.Dv ERANGE
65is stored in
66.Va errno .
67If the correct value would cause underflow, zero is
68returned and
69.Dv ERANGE
70is stored in
71.Va errno .
72.Sh ERRORS
73.Bl -tag -width [ERANGE]
74.It Bq Er ERANGE
75Overflow or underflow occurred.
76.Sh SEE ALSO
77.Xr atof 3 ,
78.Xr atoi 3 ,
79.Xr atol 3 ,
80.Xr strtol 3 ,
81.Xr strtoul 3
82.Sh STANDARDS
83The
84.Fn strtod
85function
86conforms to
87.St -ansiC .
88.Sh AUTHORS
89The author of this software is David M. Gay.
90.Pp
91Copyright (c) 1991 by AT&T.
92.Pp
93Permission to use, copy, modify, and distribute this software for any
94purpose without fee is hereby granted, provided that this entire notice
95is included in all copies of any software which is or includes a copy
96or modification of this software and in all copies of the supporting
97documentation for such software.
98.Pp
99THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
100WARRANTY.  IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
101REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
102OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
103.Pp
104Contact your vendor for a free copy of the source code to
105.Fn strtod
106and accompanying functions.
107