2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (c) 1990, 1991 The Regents of the University of California.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This code is derived from software contributed to Berkeley by
|
|
|
|
.\" the American National Standards Committee X3, on Information
|
|
|
|
.\" Processing Systems.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" @(#)strtod.3 5.3 (Berkeley) 6/29/91
|
|
|
|
.\"
|
|
|
|
.\" Modified Sun Aug 21 17:16:22 1994 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.\" Modified Sat May 04 19:34:31 MET DST 1996 by Michael Haardt
|
|
|
|
.\" (michael@cantor.informatik.rwth-aachen.de)
|
2006-06-03 01:26:30 +00:00
|
|
|
.\" Added strof, strtold, aeb, 2001-06-07
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
_exit.2, brk.2, capget.2, chdir.2, chmod.2, chown.2, chroot.2, getdtablesize.2, gethostname.2, getpagesize.2, getsid.2, killpg.2, mknod.2, mknodat.2, poll.2, posix_fadvise.2, pread.2, readlink.2, setpgid.2, setreuid.2, sigaltstack.2, stat.2, symlink.2, sync.2, truncate.2, vfork.2, wait.2, wait4.2, a64l.3, abs.3, acos.3, acosh.3, asin.3, asinh.3, atan.3, atan2.3, atoi.3, cbrt.3, ceil.3, copysign.3, cosh.3, dirfd.3, div.3, ecvt.3, erf.3, erfc.3, exp.3, exp2.3, fabs.3, fdim.3, ffs.3, floor.3, fma.3, fmax.3, fmin.3, fmod.3, fpclassify.3, frexp.3, ftw.3, fwide.3, gcvt.3, getcwd.3, getdate.3, getgrent.3, gethostid.3, getpass.3, getpwent.3, getsubopt.3, getw.3, hypot.3, ilogb.3, index.3, isalpha.3, isgreater.3, iswblank.3, j0.3, ldexp.3, lockf.3, log.3, log10.3, log1p.3, logb.3, lrint.3, lround.3, mkstemp.3, mktemp.3, modf.3, mq_receive.3, mq_send.3, nan.3, nextafter.3, posix_fallocate.3, posix_memalign.3, printf.3, qecvt.3, random.3, realpath.3, remainder.3, remquo.3, rint.3, round.3, scalb.3, scalbln.3, scanf.3, siginterrupt.3, signbit.3, sigset.3, sinh.3, sqrt.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strfry.3, strpbrk.3, strsep.3, strspn.3, strstr.3, strtod.3, strtok.3, strtol.3, strtoul.3, strxfrm.3, tanh.3, tgamma.3, trunc.3, ttyslot.3, ualarm.3, usleep.3, wprintf.3, armscii-8.7, cp1251.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-3.7, iso_8859-5.7, iso_8859-6.7, iso_8859-8.7, koi8-u.7: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-19 17:19:13 +00:00
|
|
|
.TH STRTOD 3 2010-09-20 "Linux" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
2008-07-23 02:57:20 +00:00
|
|
|
strtod, strtof, strtold \- convert ASCII string to floating-point number
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <stdlib.h>
|
|
|
|
.sp
|
|
|
|
.BI "double strtod(const char *" nptr ", char **" endptr );
|
|
|
|
.br
|
|
|
|
.BI "float strtof(const char *" nptr ", char **" endptr );
|
|
|
|
.br
|
|
|
|
.BI "long double strtold(const char *" nptr ", char **" endptr );
|
2007-07-08 12:11:40 +00:00
|
|
|
.sp
|
|
|
|
.in -4n
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
|
|
.BR feature_test_macros (7)):
|
|
|
|
.in
|
2010-09-18 16:32:42 +00:00
|
|
|
.ad l
|
2007-07-08 12:11:40 +00:00
|
|
|
.sp
|
|
|
|
.BR strtof (),
|
|
|
|
.BR strtold ():
|
2010-09-18 16:32:42 +00:00
|
|
|
.RS 4
|
2010-09-18 16:37:36 +00:00
|
|
|
_XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE ||
|
|
|
|
_POSIX_C_SOURCE\ >=\ 200112L;
|
2010-09-18 16:32:42 +00:00
|
|
|
.br
|
|
|
|
or
|
2007-07-08 12:11:40 +00:00
|
|
|
.I cc\ -std=c99
|
2010-09-18 16:32:42 +00:00
|
|
|
.RE
|
|
|
|
.ad l
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR strtod (),
|
|
|
|
.BR strtof (),
|
2004-11-03 13:51:07 +00:00
|
|
|
and
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR strtold ()
|
2004-11-03 13:51:07 +00:00
|
|
|
functions convert the initial portion of the string pointed to by
|
|
|
|
.I nptr
|
|
|
|
to
|
2006-02-09 20:24:53 +00:00
|
|
|
.IR double ,
|
|
|
|
.IR float ,
|
2004-11-03 13:51:07 +00:00
|
|
|
and
|
2007-04-12 22:42:49 +00:00
|
|
|
.I long double
|
2004-11-03 13:51:07 +00:00
|
|
|
representation, respectively.
|
|
|
|
|
|
|
|
The expected form of the (initial portion of the) string is
|
2007-05-12 09:06:04 +00:00
|
|
|
optional leading white space as recognized by
|
|
|
|
.BR isspace (3),
|
2008-06-09 15:49:35 +00:00
|
|
|
an optional plus (\(aq+\(aq) or minus sign (\(aq\-\(aq) and then either
|
2004-11-03 13:51:07 +00:00
|
|
|
(i) a decimal number, or (ii) a hexadecimal number,
|
|
|
|
or (iii) an infinity, or (iv) a NAN (not-a-number).
|
|
|
|
.LP
|
|
|
|
A
|
|
|
|
.I "decimal number"
|
mbind.2, rename.2, sched_setscheduler.2, set_mempolicy.2, syslog.2, argz_add.3, dlopen.3, scanf.3, strtod.3, strtok.3, tcgetpgrp.3, hd.4, cpuset.7, regex.7, ld.so.8: Global fix: s/non-empty/nonempty/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:41:47 +00:00
|
|
|
consists of a nonempty sequence of decimal digits
|
2007-12-26 11:17:23 +00:00
|
|
|
possibly containing a radix character (decimal point, locale-dependent,
|
2008-06-09 15:49:35 +00:00
|
|
|
usually \(aq.\(aq), optionally followed by a decimal exponent.
|
|
|
|
A decimal exponent consists of an \(aqE\(aq or \(aqe\(aq, followed by an
|
mbind.2, rename.2, sched_setscheduler.2, set_mempolicy.2, syslog.2, argz_add.3, dlopen.3, scanf.3, strtod.3, strtok.3, tcgetpgrp.3, hd.4, cpuset.7, regex.7, ld.so.8: Global fix: s/non-empty/nonempty/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:41:47 +00:00
|
|
|
optional plus or minus sign, followed by a nonempty sequence of
|
2004-11-03 13:51:07 +00:00
|
|
|
decimal digits, and indicates multiplication by a power of 10.
|
|
|
|
.LP
|
|
|
|
A
|
|
|
|
.I "hexadecimal number"
|
mbind.2, rename.2, sched_setscheduler.2, set_mempolicy.2, syslog.2, argz_add.3, dlopen.3, scanf.3, strtod.3, strtok.3, tcgetpgrp.3, hd.4, cpuset.7, regex.7, ld.so.8: Global fix: s/non-empty/nonempty/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:41:47 +00:00
|
|
|
consists of a "0x" or "0X" followed by a nonempty sequence of
|
2004-11-03 13:51:07 +00:00
|
|
|
hexadecimal digits possibly containing a radix character,
|
2007-04-12 22:42:49 +00:00
|
|
|
optionally followed by a binary exponent.
|
|
|
|
A binary exponent
|
2008-06-09 15:49:35 +00:00
|
|
|
consists of a \(aqP\(aq or \(aqp\(aq, followed by an optional
|
mbind.2, rename.2, sched_setscheduler.2, set_mempolicy.2, syslog.2, argz_add.3, dlopen.3, scanf.3, strtod.3, strtok.3, tcgetpgrp.3, hd.4, cpuset.7, regex.7, ld.so.8: Global fix: s/non-empty/nonempty/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:41:47 +00:00
|
|
|
plus or minus sign, followed by a nonempty sequence of
|
2004-11-03 13:51:07 +00:00
|
|
|
decimal digits, and indicates multiplication by a power of 2.
|
|
|
|
At least one of radix character and binary exponent must be present.
|
|
|
|
.LP
|
|
|
|
An
|
|
|
|
.I infinity
|
2007-12-16 14:08:46 +00:00
|
|
|
is either "INF" or "INFINITY", disregarding case.
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
|
|
|
A
|
|
|
|
.I NAN
|
2008-06-09 15:49:35 +00:00
|
|
|
is "NAN" (disregarding case) optionally followed by \(aq(\(aq,
|
|
|
|
a sequence of characters, followed by \(aq)\(aq.
|
2004-11-03 13:51:07 +00:00
|
|
|
The character string specifies in an implementation-dependent
|
|
|
|
way the type of NAN.
|
2008-07-18 10:03:46 +00:00
|
|
|
.\" From glibc 2.8's stdlib/strtod_l.c:
|
|
|
|
.\" We expect it to be a number which is put in the
|
|
|
|
.\" mantissa of the number.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "RETURN VALUE"
|
|
|
|
These functions return the converted value, if any.
|
|
|
|
|
|
|
|
If
|
|
|
|
.I endptr
|
2005-11-02 13:55:25 +00:00
|
|
|
is not NULL,
|
2004-11-03 13:51:07 +00:00
|
|
|
a pointer to the character after the last character used in the conversion
|
|
|
|
is stored in the location referenced by
|
|
|
|
.IR endptr .
|
|
|
|
|
|
|
|
If no conversion is performed, zero is returned and the value of
|
|
|
|
.I nptr
|
|
|
|
is stored in the location referenced by
|
|
|
|
.IR endptr .
|
|
|
|
|
|
|
|
If the correct value would cause overflow, plus or minus
|
|
|
|
.B HUGE_VAL
|
|
|
|
.RB ( HUGE_VALF ,
|
|
|
|
.BR HUGE_VALL )
|
|
|
|
is returned (according to the sign of the value), and
|
|
|
|
.B ERANGE
|
|
|
|
is stored in
|
|
|
|
.IR errno .
|
|
|
|
If the correct value would cause underflow, zero is
|
|
|
|
returned and
|
|
|
|
.B ERANGE
|
2007-04-12 22:42:49 +00:00
|
|
|
is stored in
|
2004-11-03 13:51:07 +00:00
|
|
|
.IR errno .
|
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.B ERANGE
|
|
|
|
Overflow or underflow occurred.
|
|
|
|
.SH "CONFORMING TO"
|
2006-08-03 13:57:30 +00:00
|
|
|
C89 describes
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR strtod (),
|
2004-11-03 13:51:07 +00:00
|
|
|
C99
|
|
|
|
describes the other two functions.
|
2006-04-19 00:58:37 +00:00
|
|
|
.SH NOTES
|
2007-04-12 22:42:49 +00:00
|
|
|
Since
|
|
|
|
0 can legitimately be returned
|
2006-04-19 00:58:37 +00:00
|
|
|
on both success and failure, the calling program should set
|
|
|
|
.I errno
|
2007-04-12 22:42:49 +00:00
|
|
|
to 0 before the call,
|
2006-04-19 00:58:37 +00:00
|
|
|
and then determine if an error occurred by checking whether
|
|
|
|
.I errno
|
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
|
|
|
has a nonzero value after the call.
|
2006-04-19 01:33:09 +00:00
|
|
|
.SH EXAMPLE
|
|
|
|
See the example on the
|
|
|
|
.BR strtol (3)
|
2007-04-12 22:42:49 +00:00
|
|
|
manual page;
|
2006-04-19 01:33:09 +00:00
|
|
|
the use of the functions described in this manual page is similar.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR atof (3),
|
|
|
|
.BR atoi (3),
|
|
|
|
.BR atol (3),
|
|
|
|
.BR strtol (3),
|
2007-07-08 12:11:40 +00:00
|
|
|
.BR strtoul (3)
|