newlib-cygwin/newlib/libc/stdlib/atof.c

73 lines
2.0 KiB
C
Raw Normal View History

2000-02-18 03:39:52 +08:00
/*
FUNCTION
<<atof>>, <<atoff>>---string to double or float
INDEX
atof
INDEX
atoff
ANSI_SYNOPSIS
#include <stdlib.h>
double atof(const char *<[s]>);
float atoff(const char *<[s]>);
TRAD_SYNOPSIS
#include <stdlib.h>
double atof(<[s]>)
char *<[s]>;
float atoff(<[s]>)
char *<[s]>;
DESCRIPTION
<<atof>> converts the initial portion of a string to a <<double>>.
<<atoff>> converts the initial portion of a string to a <<float>>.
The functions parse the character string <[s]>,
2003-10-20 Bob Wilson <bob.wilson@acm.org> * libc/locale/locale.c: Use double quotes in code. * libc/locale/locale.tex: Likewise. * libc/libc.texinfo: Hyphenate "floating-point". * libc/machine/necv70/necv70.tex: Likewise. * libc/stdio/sprintf.c: Likewise. * libc/stdio/sscanf.c: Likewise. * libc/stdlib/atof.c: Likewise. * libc/stdlib/ldtoa.c: Fix comment typo. * libc/stdlib/div.c: Use @ifnottex instead of @ifinfo. * libc/stdlib/ldiv.c: Likewise. * libm/common/s_expm1.c: Likewise. * libm/common/s_ilogb.c: Hyphenate "floating-point". Use "nonzero". * libm/common/s_infinity: Hyphenate "double- and single-precision". * libm/common/s_nan.c: Likewise. Also correct the FUNCTION summary. * libm/common/s_nextafter.c: Fix typo. Hyphenate "double-precision" and "floating-point". * libm/common/s_scalbn.c: Correct the FUNCTION summary. * libm/math/e_pow.c: Fix comment typo. * libm/math/math.tex: Hyphenate "single-precision" and "floating-point". * libm/math/s_asinh.c: Use @ifnottex instead of @ifinfo. * libm/math/s_atan.c: Likewise. * libm/math/s_frexp.c: Likewise. Also use "nonzero". * libm/math/s_isnan.c: Hyphenate "single-precision" and "floating-point". Use "nonzero". * libm/math/s_ldexp.c: Use @ifnottex instead of @ifinfo. * libm/math/w_acos.c: Likewise. * libm/math/w_acosh.c: Likewise. * libm/math/w_asin.c: Likewise. * libm/math/w_atan2.c: Likewise. * libm/math/w_atanh.c: Likewise. * libm/math/w_cosh.c: Likewise. * libm/math/w_exp.c: Likewise. * libm/math/w_exp2.c: Likewise. Add missing @end and missing @tex version of 2^x in the description. * libm/math/w_fmod.c: Use @ifnottex instead of @ifinfo. * libm/math/w_gamma.c: Likewise. * libm/math/w_hypot.c: Likewise. * libm/math/w_j0.c: Likewise. * libm/math/w_sinh.c: Likewise. * libm/math/w_pow.c: Replace "exp1.0nt" with "exponent". * libm/mathfp/mathfp.tex: Hyphenate "single-precision" and "floating-point". * libm/mathfp/e_acosh.c: Use @ifnottex instead of @ifinfo. * libm/mathfp/e_atanh.c: Likewise. * libm/mathfp/e_hypot.c: Likewise. * libm/mathfp/er_lgamma.c: Likewise. * libm/mathfp/s_acos.c: Likewise. * libm/mathfp/s_asine.c: Likewise. * libm/mathfp/s_asinh.c: Likewise. * libm/mathfp/s_atan.c: Likewise. * libm/mathfp/s_atan2.c: Likewise. * libm/mathfp/s_atangent.c: Likewise. * libm/mathfp/s_cosh.c: Likewise. * libm/mathfp/s_exp.c: Likewise. * libm/mathfp/s_fmod.c: Likewise. * libm/mathfp/s_frexp.c: Likewise. Also use "nonzero". * libm/mathfp/s_isnan.c: Hyphenate "single-precision" and "floating-point". Use "nonzero". * libm/math/s_pow.c: Replace "exp1.0nt" with "exponent". * libm/mathfp/s_ldexp.c: Use @ifnottex instead of @ifinfo. * libm/mathfp/s_sineh.c: Likewise. * libm/mathfp/w_jn.c: Likewise.
2003-10-21 02:46:38 +08:00
locating a substring which can be converted to a floating-point
2000-02-18 03:39:52 +08:00
value. The substring must match the format:
. [+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>]
The substring converted is the longest initial
fragment of <[s]> that has the expected format, beginning with
the first non-whitespace character. The substring
is empty if <<str>> is empty, consists entirely
of whitespace, or if the first non-whitespace character is
something other than <<+>>, <<->>, <<.>>, or a digit.
<<atof(<[s]>)>> is implemented as <<strtod(<[s]>, NULL)>>.
<<atoff(<[s]>)>> is implemented as <<strtof(<[s]>, NULL)>>.
2000-02-18 03:39:52 +08:00
RETURNS
<<atof>> returns the converted substring value, if any, as a
<<double>>; or <<0.0>>, if no conversion could be performed.
If the correct value is out of the range of representable values, plus
or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is stored in
<<errno>>.
If the correct value would cause underflow, <<0.0>> is returned
and <<ERANGE>> is stored in <<errno>>.
<<atoff>> obeys the same rules as <<atof>>, except that it
returns a <<float>>.
PORTABILITY
<<atof>> is ANSI C. <<atof>>, <<atoi>>, and <<atol>> are subsumed by <<strod>>
and <<strol>>, but are used extensively in existing code. These functions are
less reliable, but may be faster if the argument is verified to be in a valid
range.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <stdlib.h>
#include <_ansi.h>
double
_DEFUN (atof, (s),
_CONST char *s)
{
return strtod (s, NULL);
}