aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/stdlib/strtod.c
AgeCommit message (Collapse)AuthorFilesLines
2022-07-13Add _REENT_ERRNO(ptr)Matt Joyce1-5/+5
Add a _REENT_ERRNO() macro to encapsulate the access to the _errno member of struct reent. This will help to replace the structure member with a thread-local storage object in a follow up patch. Replace uses of __errno_r() with _REENT_ERRNO(). Keep __errno_r() macro for potential users outside of Newlib.
2021-08-23stdlib: conditionalize locale usageCorinna Vinschen1-1/+6
_strtod_l as well as the gethex function both fetch the decimal point from the current LC_NUMERIC locale info. This pulls in _C_numeric_locale unconditionally even on targets not supporting locales at all. Another problem is that strtod.c and gdtoa-gethex.c are ELIX 1, while locale information in general isn't. This leads to potential build breakage on bare metal targets. Fix this by setting the decimal point to "." on all targets not defining __HAVE_LOCALE_INFO__. While at it, const'ify the entire local decimal point info in the affected functions. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-07stdlib: Make strtod/strtof set ERANGE consistently for underflow.Keith Packard1-2/+29
The C standard says that errno may acquire the value ERANGE if the result from strtod underflows. According to IEEE 754, underflow occurs whenever the value cannot be represented in normalized form. Newlib is inconsistent in this, setting errno to ERANGE only if the value underflows to zero, but not for denorm values, and never for hex format floats. This patch attempts to consistently set errno to ERANGE for all 'underflow' conditions, which is to say all values which are not exactly zero and which cannot be represented in normalized form. This matches glibc behavior, as well as the Linux, Mac OS X, OpenBSD, FreeBSD and SunOS strtod man pages. Signed-off-by: Keith Packard <keithp@keithp.com>
2018-09-06stdlib: Use __get_numeric_locale instead of __localeconv_l for decimal_pointKeith Packard1-3/+3
The string/float conversion functions need to get the locale decimal point. Instead of calling __localeconv_l (which copies locale data into lconv form from __get_numeric_locale), use __get_numeric_locale directly. Signed-off-by: Keith Packard <keithp@keithp.com>
2018-08-29Use nanf("") instead of nanf(NULL)Keith Packard1-2/+2
Newer GCC versions require a non-NULL argument to this function for some reason. Signed-off-by: Keith Packard <keithp@keithp.com>
2018-08-16Fix strtof ("-nan") returns positive NaNMasamichi Hosoda1-2/+2
strtof ("-nan") returned positive NaN instead of negative NaN. strtod ("-nan") and strtold ("-nan") return negative NaN. Linux glibc has been fixed that strto{f|d|ld} ("-nan") returns negative NaN. https://sourceware.org/bugzilla/show_bug.cgi?id=23007 This commit makes strtof preserves the negative sign bit when parsing "-nan" like glibc.
2018-08-16Remove unused NaN's integer representation definitionsMasamichi Hosoda1-1/+8
By previous commit, strto{d|ld} ("nan") does not use the definition of NaN. There is no other function that uses the definitions. This commit remove the definitions.
2018-08-16Fix strtod ("nan") and strtold ("nan") returns wrong negative NaNMasamichi Hosoda1-4/+1
The definition of qNaN for x86_64 and i386 was wrong. strto{d|ld} ("nan") returned wrong negative NaN instead of correct positive NaN since it used the wrong definition. On the other hand, strtof ("nan") returns correct positive NaN since it uses nanf ("") instead of the wrong definition. This commit makes strto{d|ld} ("nan") uses {nan|nanl} ("") like strtof ("nan") using. So strto{d|ld} ("nan") returns positive NaN.
2018-04-09strtod: Convert 64 bit double to 64 bit int during computationCorinna Vinschen1-0/+9
The gdtoa implementation uses the type long, defined as Long, in lots of code. For historical reason newlib defines Long as int32_t instead. This works fine, as long as floating point exceptions are not enabled. The conversion to 32 bit int can lead to a FE_INVALID situation. Example: const char *str = "121645100408832000.0"; char *ptr; feenableexcept (FE_INVALID); strtod (str, &ptr); This leads to the following situation in strtod double aadj; Long L; [...] L = (Long)aadj; For instance, on x86_64 the code here is cvttsd2si %xmm0,%eax At this point, aadj is 2529648000.0 in our example. The conversion to 32 bit %eax results in a negative int value, thus the conversion is invalid. With feenableexcept (FE_INVALID), a SIGFPE is raised. Fix this by always using 64 bit ints here if double is not a 32 bit type to avoid this type of FP exceptions. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-01-17ansification: remove _DEFUNYaakov Selkowitz1-10/+5
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _CONSTYaakov Selkowitz1-7/+7
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _ANDYaakov Selkowitz1-8/+8
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-12-01stdlib: remove TRAD_SYNOPSISYaakov Selkowitz1-16/+1
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2016-12-16Remove extraneous float casts in strtod.c.Jeff Johnston1-2/+2
2016-12-152016-12-15 Kyrylo Tkachov <kyrylo.tkachov@arm.com>cygwin-2_6_1-releaseJeff Johnston1-4/+14
* libc/stdlib/strtod.c (strtof_l): Set errno to ERANGE when double to float conversion results in infinity. (strtof): Likewise. * libc/stdlib/wcstod.c (wcstof_l): Likewise. (wcstof): Likewise.
2016-08-15Implement strto[dflu]_l/wcsto[dflu]_lCorinna Vinschen1-25/+85
Implement GNU extensions strtod_l, strtof_l, strtol_l, strtold_l, strtoll_l, strtoul_l, strtoull_l, wcstod_l, wcstof_l, wcstol_l, wcstold_l, wcstoll_l, wcstoul_l, wcstoull_l. Export from Cygwin, fix posix.xml. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-11-20Make match function globally available to stdlib functions.Corinna Vinschen1-21/+0
* libc/stdlib/strtod.c (match): Move from here... * libc/stdlib/gdtoa-hexnan.c (match): ...to here. * libc/stdlib/mprec.h (match): Declare and add __match define. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2014-11-12 * libc/stdlib/strtod.c (sulp): Cast to int32_t to avoid overflow.Corinna Vinschen1-1/+1
* libc/time/gmtime_r.c (DAYS_PER_*_YEARS): Convert to long constants to avoid overflow.
2013-11-182013-11-18 Sahil Patnayakuni <sahilp@oarcorp.com>Joel Sherrill1-8/+8
* libc/include/stdlib.h, libc/stdlib/mbstowcs.c, libc/stdlib/mbstowcs_r.c, libc/stdlib/mbtowc.c, libc/stdlib/mbtowc_r.c, libc/stdlib/strtod.c, libc/stdlib/strtol.c, libc/stdlib/strtold.c, libc/stdlib/strtoll.c, libc/stdlib/strtoll_r.c, libc/stdlib/strtoul.c, libc/stdlib/strtoull.c, libc/stdlib/strtoull_r.c, libc/stdlib/wcstombs.c, libc/stdlib/wcstombs_r.c: Add restrict keyword.
2013-06-10 * libc/stdlib/gdtoa-gethex.c (__hexdig): Constify.Corinna Vinschen1-2/+2
(hexdig_init): Remove. (__hexdig_fun): New function. hexdig_init, added __hexdig_fun (gethex): Call __get_hexdig macro rather than hexdig. * libc/stdlib/gdtoa-hexnan.c (hexnan): Constify fpi argument. Call __get_hexdig macro rather than hexdig. * libc/stdlib/ldtoa.c: Throughout constify functions arguments where required by constifying the following arrays. (ezero): Constify. (eone): Constify. (ermsg): Constify. (etens): Constify. (emtens): Constify. (nan113): Constify. (nan64): Constify. (nan53): Constify. (nan24): Constify. * libc/stdlib/mprec.h (__get_hexdig): Define. (gethex): Constify args in declaration where appropriate. (hexnan): Ditto. (hexdig_init): Remove declaration. (__hexdig_fun): Declare. * libc/stdlib/strtod.c (fpi): Constify. (fpinan): Constify.
2013-04-24 * libc/stdlib/strtod.c: Manual update to latest algorithm from NetBSD.Corinna Vinschen1-38/+117
2012-12-19 * libc/stdlib/strtod.c (_strtod_r): Revert change from 2011-05-16.Corinna Vinschen1-10/+8
2011-05-16 * libc/stdlib/strtod.c (_strtod_r): Fix nf/nd counts to not exceedCorinna Vinschen1-8/+10
DBL_DIG.
2010-12-072010-12-07 Jeff Johnston <jjohnstn@redhat.com>Jeff Johnston1-14/+22
* libc/stdlib/strtod.c(_strtod_r): Fix code to handle case whereby _DOUBLE_IS_32BITS is set and DBL_DIGS is 6 instead of 15.
2009-12-032009-12-03 Craig Howland <howland@LGSInnovations.com>Jeff Johnston1-1/+1
* libc/stdlib/strtod.c: Correct "NO_REENT" to "_REENT_ONLY". * libc/stdlib/wcstod.c: Ditto. * libc/stdlib/dtoastub.c: Ditto.
2009-06-16 * libc/stdio/vfprintf.c (_VFPRINTF_R): Use actual length ofCorinna Vinschen1-8/+3
radix char instead of assuming length 1. * libc/stdlib/gdtoa-gethex.c: Remove use of USE_LOCALE. (gethex): Allow multibyte decimal point. Fix compiler warnings due to different signedness of pointer types. * libc/stdlib/strtod.c: Remove use of USE_LOCALE. (_strtod_r): Allow multibyte decimal point. * libc/stdlib/wcstod.c (_wcstod_r): Evaluate correct wide char endptr position if the decimal point is a multibyte char.
2009-03-26 Revert erroneously checked in files.Corinna Vinschen1-2/+8
2009-03-24 * libc/ctype/iswalpha.c: Handle all wchar_t as unicode onCorinna Vinschen1-8/+2
_MB_CAPABLE systems. * libc/ctype/iswblank.c: Ditto. * libc/ctype/iswcntrl.c: Ditto. * libc/ctype/iswprint.c: Ditto. * libc/ctype/iswpunct.c: Ditto. * libc/ctype/iswspace.c: Ditto. * libc/ctype/jp2uc.c (__jp2uc): On Cygwin, just return c. Explain why. * libc/ctype/towlower.c: Ditto. * libc/ctype/towupper.c: Ditto. * libc/include/sys/config.h: Define _MB_EXTENDED_CHARSETS_ISO and _MB_EXTENDED_CHARSETS_WINDOWS if _MB_EXTENDED_CHARSETS_ALL is defined. Define _MB_EXTENDED_CHARSETS_ALL on Cygwin only for now. * libc/include/sys/reent.h (struct _reent): Mark _current_category and _current_locale as unused. * libc/locale/locale.c: Add new charset support to documentation. Include ../stdio/local.h from here. (lc_ctype_charset): Set to "ASCII" by default. (lc_message_charset): Ditto. (_setlocale_r): Don't set _current_category and _current_locale. (loadlocale): Add Cygwin codepage support. On _MB_CAPABLE systems, set __mbtowc and __wctomb function pointers to function corresponding with current charset. Don't allow non-existant ISO-8859-12 charset. Add support for Windows singlebyte codepages. On Cygwin, add support for GBK, CP949, and BIG5. On Cygwin, call __set_ctype() in case the catorgy is LC_CTYPE. Don't set _current_category and _current_locale. * libc/stdlib/Makefile.am (GENERAL_SOURCES): Add sb_charsets.c. * libc/stdlib/Makefile.in: Regenerate. * libc/stdlib/local.h: Add prototype for __locale_charset. Add prototypes for __mbtowc and __wctomb pointers. Add prototypes for charset-specific _wctomb_r and _mbtowc_r functions. Declare tables and functions from sb_charsets.c. * libc/stdlib/mbtowc_r.c (__mbtowc): Define. Set to __ascii_mbtowc by default. (_mbtowc_r): Just call __mbtowc from here. (__ascii_mbtowc): New function. (__iso_mbtowc): New function. (__cp_mbtowc): New function. (__utf8_mbtowc): New function. (__sjis_mbtowc): New function. Disable on Cygwin. (__eucjp_mbtowc): New function. Disable on Cygwin. (__jis_mbtowc): New function. Disable on Cygwin. * libc/stdlib/sb_charsets.c: New file, adding singlebyte to UTF conversion tables for all ISO and CP charsets. (__iso_8859_index): New function. (__cp_index): New function. * libc/stdlib/wctomb_r.c (__wctomb): Define. Set to __ascii_wctomb by default. (_wctomb_r): Just call __wctomb from here. (__ascii_wctomb): New function. (__utf8_wctomb): New function. (__sjis_wctomb): New function. Disable on Cygwin. (__eucjp_wctomb): New function. Disable on Cygwin. (__jis_wctomb): New function. Disable on Cygwin. (__iso_wctomb): New function. (__cp_wctomb): New function.
2008-11-272008-11-27 Craig Howland <howland@LGSInnovations.com>Jeff Johnston1-0/+1
* libc/argz/argz_add.c: Added #include <argz.h> to get function prototypes. * libc/argz/argz_append.c: Ditto. * libc/argz/argz_count.c: Ditto. * libc/argz/argz_create.c: Ditto. * libc/argz/argz_create_sep.c: Ditto. * libc/argz/argz_delete.c: Ditto. * libc/argz/argz_next.c: Ditto. * libc/argz/argz_stringify.c: Ditto * libc/stdlib/strtod.c: Added #include <stdlib.h> to get function prototypes. * libc/stdlib/wcstoul.c: Added #include <wchar.h> to get function prototypes, corrected traditional usage comment. * libc/include/wchar.h: Added _mbsrtowcs_r() prototype.
2008-06-25 Fix strict-aliasing issues with _strtod_r and Storeinc.Hans-Peter Nilsson1-20/+21
* libc/stdlib/strtod.c (_strtod_r): Change local variables aadj, rv, rv0 from double to type U. Use accessor macros dval, dword0 and dword1 for all accesses except for the ULtod call, where rv.i replaces the pointer cast. * libc/stdlib/mprec.h (U): Rename member L to i for easier re-use of access macros. Tweak comment. Remove #ifdef'd YES_ALIAS code. (dword0, dword1, dval): Define in terms of uncast union member access. Ditto for _DOUBLE_IS_32BITS variants. (Storeinc): Replace aliasing-flawed microoptimized definition with alternative suggested in comment. Remove now stale comment.
2008-02-21Fix strtod("-0x", NULL).Eric Blake1-7/+17
* libc/stdlib/strtod.c (_strtod_r): Fall back to 0 if hex parse fails.
2007-08-312007-08-31 Antony King <antony.king@st.com>Jeff Johnston1-1/+11
* libc/stdlib/mprec.h [_DOUBLE_IS_32BITS}: Define IEEE_Arith bits and redefine associated dword0 macro (rvalue issue). * libc/stdio/vfieeefp.h: Ditto. * libc/stdlib/strtod.c: Add checks for _DOUBLE_IS_32BITS to prevent setting dword1 which is an rvalue only.
2006-07-052006-07-05 Jeff Johnston <jjohnstn@redhat.com>Jeff Johnston1-1/+32
* libc/stdlib/mprec.h [_DOUBLE_IS_32BITS]: Turn off C99 hex floating-point format support. Also redefine dword0 and dword1 macros. * libc/stdlib/strtod.c: Add checks for _DOUBLE_IS_32BITS to prevent setting dword1 which is an rvalue only.
2006-06-222006-06-22 Jeff Johnston <jjohnstn@redhat.com>Jeff Johnston1-606/+991
* libc/stdlib/Makefile.am: Add new gdtoa routines. * libc/stdlib/Makefile.in: Regenerated. * libc/stdlib/gd_qnan.h: New file. * libc/stdlib/gdtoa-gethex.c: Ditto. * libc/stdlib/gdtoa-hexnan.c: Ditto. * libc/stdlib/gdtoa.h: Ditto. * libc/stdlib/mprec.c: Add new helper routines needed by the new gdtoa code. * libc/stdlib/mprec.h: Integrate some defines and prototypes used by gdtoa routines here. * libc/stdlib/strtod.c: Rebased on David M. Gay's gdtoa-strtod.c which adds C99 support such as nan, inf, and hexadecimal input format.
2005-04-01 * libc/stdlib/strtod.c (_strtod_r): Never change s00.Corinna Vinschen1-3/+3
2005-01-062005-01-06 Jeff Johnston <jjohnstn@redhat.com>Jeff Johnston1-4/+27
* libc/stdlib/strtod.c (_strtod_r): Add NaN support. * (strtof): Ditto. * libc/stdio/vfscanf.c (__svfscanf_r): Ditto. * Makefile.am (MATHOBJS_IN_LIBC): Add s_nan and sf_nan functions for use by strtod and strtof. * Makefile.in: Regenerated.
2002-12-062002-12-06 Jeff Johnston <jjohnstn@redhat.com>Jeff Johnston1-7/+7
* libc/include/stdlib.h (strtof): New prototype (from C99). (strtodf): Changed from prototype to macro which redefines to strtof. * libc/stdlib/atof.c: Change documentation to refer to strtof instead of strtodf. * libc/stdlib/atoff.c (atoff): Change to call strtof instead of strtodf. * libc/stdlib/strtod.c (strtodf): Renamed to strtof. (strtof): New function. * libm/test/convert.c (test_strtodf): Renamed to test_strtof which calls strtof.
2001-04-202001-04-20 Jeff Johnston <jjohnstn@redhat.com>Jeff Johnston1-1/+1
* libc/include/stdio.h[!_REENT_ONLY]: Moved various functions together into one list. [!__STRICT_ANSI__]: Moved non-ANSI I/O functions in this list. (vfscanf, vscanf, vsscanf, _vfscanf_r, _vscanf_r, _vsscanf_r): New function prototypes. (_fscanf_r, _sscanf_r): Ditto. * libc/include/stdlib.h: Added _strtod_r prototype. * libc/stdio/Makefile.am: Add new v*scanf functions. * libc/stdio/Makefile.in: Regenerate. * libc/stdio/fscanf.c: Reorganized so HAVE_STDC only affects prototype and code is shared. Added reentrant _fscanf_r which calls __svfscanf_r. * libc/stdio/scanf.c: Changed to call __svfscanf_r. * libc/stdio/sscanf.c: Changed documentation to add reentrant routines. (sscanf): Changed to call __svfscanf_r with _REENT argument. (_sscanf_r): New routine. * libc/stdio/local.h: Removed __svfscanf prototype and replaced it with __svfscanf_r prototype. * libc/stdio/vfscanf.c (vfscanf, _vfscanf_r: New routines. (__svfscanf_r): Reentrant version of __svfscanf which takes reetrancy structure as argument as calls reentrant versions of helper functions (e.g. _strtol_r, _strtoul_r). Also replaced calls to atol and atof to _strtol_r and _strtod_r respectively. * libc/stdio/vfscanf.c: Also changed __svfscanf to call __svfscanf_r. * libc/stdlib/strtod.c (strtod): Changed to call _strtod_r with _REENT argument. * libc/stdio/vscanf.c: New file. * libc/stdio/vsscanf.c: Ditto.
2000-04-17Mon Apr 17 12:46:00 2000 Marek Michalkiewicz <marekm@linux.org.pl>Jeff Johnston1-2/+2
* libc/signal/signal.c (_signal_r) : Removed unused local variable temp. * libc/stdio/findfp.c (std): Added declaration of flags and file. * libc/stdio/mktemp.c (_gettemp, _mkstemp_r, mkstemp): Added int return type. * libc/stdio/putchar.c (putchar): Added return statement. * libc/stdio/refill.c (lflush): Added correct parentheses. * libc/stdio/vfprintf.c (_VFPRINTF_R): Ditto. * libc/stdio/vfscanf.c (__svfscanf): Changed sprintf call which prints long value to use l qualifier. * libc/stdlib/dtoa.c (_dtoa_r): Added parentheses to remove warning messages and initialized local values: ilim, ilim1, and spec_case. * libc/stdlib/ecvtbuf.c (print_e): Removed unused variable dp. * libc/stdlib/mbctype.h (_issjis1, _issjis2): Added parentheses. * libc/stdlib/mprec.c: Ditto. * libc/stdlib/setenv_r.c: Ditto. * libc/stdlib/strtod.c: Ditto. * libc/stdlib/strtol.c: Ditto. * libc/stdlib/strtoul.c: Ditto. * libm/common/sf_expm1.c: Added curly braces to if else clauses. * libm/common/sf_log1p.c: Ditto. * libm/common/sf_scalbn.c: Ditto. * libm/math/ef_log.c: Ditto.
2000-02-17import newlib-2000-02-17 snapshotChristopher Faylor1-0/+731