OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [stdlib/] [wcstod.c] - Diff between revs 207 and 520

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 520
/*
/*
FUNCTION
FUNCTION
        <<wcstod>>, <<wcstof>>---wide char string to double or float
        <<wcstod>>, <<wcstof>>---wide char string to double or float
 
 
INDEX
INDEX
        wcstod
        wcstod
INDEX
INDEX
        _wcstod_r
        _wcstod_r
INDEX
INDEX
        wcstof
        wcstof
INDEX
INDEX
        _wcstof_r
        _wcstof_r
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <stdlib.h>
        #include <stdlib.h>
        double wcstod(const wchar_t *<[str]>, wchar_t **<[tail]>);
        double wcstod(const wchar_t *<[str]>, wchar_t **<[tail]>);
        float wcstof(const wchar_t *<[str]>, wchar_t **<[tail]>);
        float wcstof(const wchar_t *<[str]>, wchar_t **<[tail]>);
 
 
        double _wcstod_r(void *<[reent]>,
        double _wcstod_r(void *<[reent]>,
                         const wchar_t *<[str]>, wchar_t **<[tail]>);
                         const wchar_t *<[str]>, wchar_t **<[tail]>);
        float _wcstof_r(void *<[reent]>,
        float _wcstof_r(void *<[reent]>,
                         const wchar_t *<[str]>, wchar_t **<[tail]>);
                         const wchar_t *<[str]>, wchar_t **<[tail]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <stdlib.h>
        #include <stdlib.h>
        double wcstod(<[str]>,<[tail]>)
        double wcstod(<[str]>,<[tail]>)
        wchar_t *<[str]>;
        wchar_t *<[str]>;
        wchar_t **<[tail]>;
        wchar_t **<[tail]>;
 
 
        float wcstof(<[str]>,<[tail]>)
        float wcstof(<[str]>,<[tail]>)
        wchar_t *<[str]>;
        wchar_t *<[str]>;
        wchar_t **<[tail]>;
        wchar_t **<[tail]>;
 
 
        double _wcstod_r(<[reent]>,<[str]>,<[tail]>)
        double _wcstod_r(<[reent]>,<[str]>,<[tail]>)
        wchar_t *<[reent]>;
        wchar_t *<[reent]>;
        wchar_t *<[str]>;
        wchar_t *<[str]>;
        wchar_t **<[tail]>;
        wchar_t **<[tail]>;
 
 
        float _wcstof_r(<[reent]>,<[str]>,<[tail]>)
        float _wcstof_r(<[reent]>,<[str]>,<[tail]>)
        wchar_t *<[reent]>;
        wchar_t *<[reent]>;
        wchar_t *<[str]>;
        wchar_t *<[str]>;
        wchar_t **<[tail]>;
        wchar_t **<[tail]>;
 
 
DESCRIPTION
DESCRIPTION
        The function <<wcstod>> parses the wide character string <[str]>,
        The function <<wcstod>> parses the wide character string <[str]>,
        producing a substring which can be converted to a double
        producing a substring which can be converted to a double
        value.  The substring converted is the longest initial
        value.  The substring converted is the longest initial
        subsequence of <[str]>, beginning with the first
        subsequence of <[str]>, beginning with the first
        non-whitespace character, that has one of these formats:
        non-whitespace character, that has one of these formats:
        .[+|-]<[digits]>[.[<[digits]>]][(e|E)[+|-]<[digits]>]
        .[+|-]<[digits]>[.[<[digits]>]][(e|E)[+|-]<[digits]>]
        .[+|-].<[digits]>[(e|E)[+|-]<[digits]>]
        .[+|-].<[digits]>[(e|E)[+|-]<[digits]>]
        .[+|-](i|I)(n|N)(f|F)[(i|I)(n|N)(i|I)(t|T)(y|Y)]
        .[+|-](i|I)(n|N)(f|F)[(i|I)(n|N)(i|I)(t|T)(y|Y)]
        .[+|-](n|N)(a|A)(n|N)[<(>[<[hexdigits]>]<)>]
        .[+|-](n|N)(a|A)(n|N)[<(>[<[hexdigits]>]<)>]
        .[+|-]0(x|X)<[hexdigits]>[.[<[hexdigits]>]][(p|P)[+|-]<[digits]>]
        .[+|-]0(x|X)<[hexdigits]>[.[<[hexdigits]>]][(p|P)[+|-]<[digits]>]
        .[+|-]0(x|X).<[hexdigits]>[(p|P)[+|-]<[digits]>]
        .[+|-]0(x|X).<[hexdigits]>[(p|P)[+|-]<[digits]>]
        The substring contains no characters if <[str]> is empty, consists
        The substring contains no characters if <[str]> is empty, consists
        entirely of whitespace, or if the first non-whitespace
        entirely of whitespace, or if the first non-whitespace
        character is something other than <<+>>, <<->>, <<.>>, or a
        character is something other than <<+>>, <<->>, <<.>>, or a
        digit, and cannot be parsed as infinity or NaN. If the platform
        digit, and cannot be parsed as infinity or NaN. If the platform
        does not support NaN, then NaN is treated as an empty substring.
        does not support NaN, then NaN is treated as an empty substring.
        If the substring is empty, no conversion is done, and
        If the substring is empty, no conversion is done, and
        the value of <[str]> is stored in <<*<[tail]>>>.  Otherwise,
        the value of <[str]> is stored in <<*<[tail]>>>.  Otherwise,
        the substring is converted, and a pointer to the final string
        the substring is converted, and a pointer to the final string
        (which will contain at least the terminating null character of
        (which will contain at least the terminating null character of
        <[str]>) is stored in <<*<[tail]>>>.  If you want no
        <[str]>) is stored in <<*<[tail]>>>.  If you want no
        assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>.
        assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>.
        <<wcstof>> is identical to <<wcstod>> except for its return type.
        <<wcstof>> is identical to <<wcstod>> except for its return type.
 
 
        This implementation returns the nearest machine number to the
        This implementation returns the nearest machine number to the
        input decimal string.  Ties are broken by using the IEEE
        input decimal string.  Ties are broken by using the IEEE
        round-even rule.  However, <<wcstof>> is currently subject to
        round-even rule.  However, <<wcstof>> is currently subject to
        double rounding errors.
        double rounding errors.
 
 
        The alternate functions <<_wcstod_r>> and <<_wcstof_r>> are
        The alternate functions <<_wcstod_r>> and <<_wcstof_r>> are
        reentrant versions of <<wcstod>> and <<wcstof>>, respectively.
        reentrant versions of <<wcstod>> and <<wcstof>>, respectively.
        The extra argument <[reent]> is a pointer to a reentrancy structure.
        The extra argument <[reent]> is a pointer to a reentrancy structure.
 
 
RETURNS
RETURNS
        Return the converted substring value, if any.  If
        Return the converted substring value, if any.  If
        no conversion could be performed, 0 is returned.  If the
        no conversion could be performed, 0 is returned.  If the
        correct value is out of the range of representable values,
        correct value is out of the range of representable values,
        plus or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is
        plus or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is
        stored in errno. If the correct value would cause underflow, 0
        stored in errno. If the correct value would cause underflow, 0
        is returned and <<ERANGE>> is stored in errno.
        is returned and <<ERANGE>> is stored in errno.
 
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
*/
 
 
/*-
/*-
 * Copyright (c) 2002 Tim J. Robbins
 * Copyright (c) 2002 Tim J. Robbins
 * All rights reserved.
 * All rights reserved.
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * modification, are permitted provided that the following conditions
 * are met:
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *    documentation and/or other materials provided with the distribution.
 *
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * 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
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * SUCH DAMAGE.
 */
 */
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <errno.h>
#include <errno.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <wchar.h>
#include <wchar.h>
#include <wctype.h>
#include <wctype.h>
#include <locale.h>
#include <locale.h>
#include <math.h>
#include <math.h>
 
 
double
double
_DEFUN (_wcstod_r, (ptr, nptr, endptr),
_DEFUN (_wcstod_r, (ptr, nptr, endptr),
        struct _reent *ptr _AND
        struct _reent *ptr _AND
        _CONST wchar_t *nptr _AND
        _CONST wchar_t *nptr _AND
        wchar_t **endptr)
        wchar_t **endptr)
{
{
        static const mbstate_t initial;
        static const mbstate_t initial;
        mbstate_t mbs;
        mbstate_t mbs;
        double val;
        double val;
        char *buf, *end;
        char *buf, *end;
        const wchar_t *wcp;
        const wchar_t *wcp;
        size_t len;
        size_t len;
 
 
        while (iswspace(*nptr))
        while (iswspace(*nptr))
                nptr++;
                nptr++;
 
 
        /*
        /*
         * Convert the supplied numeric wide char. string to multibyte.
         * Convert the supplied numeric wide char. string to multibyte.
         *
         *
         * We could attempt to find the end of the numeric portion of the
         * We could attempt to find the end of the numeric portion of the
         * wide char. string to avoid converting unneeded characters but
         * wide char. string to avoid converting unneeded characters but
         * choose not to bother; optimising the uncommon case where
         * choose not to bother; optimising the uncommon case where
         * the input string contains a lot of text after the number
         * the input string contains a lot of text after the number
         * duplicates a lot of strtod()'s functionality and slows down the
         * duplicates a lot of strtod()'s functionality and slows down the
         * most common cases.
         * most common cases.
         */
         */
        wcp = nptr;
        wcp = nptr;
        mbs = initial;
        mbs = initial;
        if ((len = _wcsrtombs_r(ptr, NULL, &wcp, 0, &mbs)) == (size_t)-1) {
        if ((len = _wcsrtombs_r(ptr, NULL, &wcp, 0, &mbs)) == (size_t)-1) {
                if (endptr != NULL)
                if (endptr != NULL)
                        *endptr = (wchar_t *)nptr;
                        *endptr = (wchar_t *)nptr;
                return (0.0);
                return (0.0);
        }
        }
        if ((buf = _malloc_r(ptr, len + 1)) == NULL)
        if ((buf = _malloc_r(ptr, len + 1)) == NULL)
                return (0.0);
                return (0.0);
        mbs = initial;
        mbs = initial;
        _wcsrtombs_r(ptr, buf, &wcp, len + 1, &mbs);
        _wcsrtombs_r(ptr, buf, &wcp, len + 1, &mbs);
 
 
        /* Let strtod() do most of the work for us. */
        /* Let strtod() do most of the work for us. */
        val = _strtod_r(ptr, buf, &end);
        val = _strtod_r(ptr, buf, &end);
 
 
        /*
        /*
         * We only know where the number ended in the _multibyte_
         * We only know where the number ended in the _multibyte_
         * representation of the string. If the caller wants to know
         * representation of the string. If the caller wants to know
         * where it ended, count multibyte characters to find the
         * where it ended, count multibyte characters to find the
         * corresponding position in the wide char string.
         * corresponding position in the wide char string.
         */
         */
        if (endptr != NULL) {
        if (endptr != NULL) {
                /* The only valid multibyte char in a float converted by
                /* The only valid multibyte char in a float converted by
                   strtod/wcstod is the radix char.  What we do here is,
                   strtod/wcstod is the radix char.  What we do here is,
                   figure out if the radix char was in the valid leading
                   figure out if the radix char was in the valid leading
                   float sequence in the incoming string.  If so, the
                   float sequence in the incoming string.  If so, the
                   multibyte float string is strlen(radix char) - 1 bytes
                   multibyte float string is strlen(radix char) - 1 bytes
                   longer than the incoming wide char string has characters.
                   longer than the incoming wide char string has characters.
                   To fix endptr, reposition end as if the radix char was
                   To fix endptr, reposition end as if the radix char was
                   just one byte long.  The resulting difference (end - buf)
                   just one byte long.  The resulting difference (end - buf)
                   is then equivalent to the number of valid wide characters
                   is then equivalent to the number of valid wide characters
                   in the input string. */
                   in the input string. */
                len = strlen (_localeconv_r (ptr)->decimal_point);
                len = strlen (_localeconv_r (ptr)->decimal_point);
                if (len > 1) {
                if (len > 1) {
                        char *d = strstr (buf,
                        char *d = strstr (buf,
                                          _localeconv_r (ptr)->decimal_point);
                                          _localeconv_r (ptr)->decimal_point);
                        if (d && d < end)
                        if (d && d < end)
                                end -= len - 1;
                                end -= len - 1;
                }
                }
                *endptr = (wchar_t *)nptr + (end - buf);
                *endptr = (wchar_t *)nptr + (end - buf);
        }
        }
 
 
        _free_r(ptr, buf);
        _free_r(ptr, buf);
 
 
        return (val);
        return (val);
}
}
 
 
float
float
_DEFUN (_wcstof_r, (ptr, nptr, endptr),
_DEFUN (_wcstof_r, (ptr, nptr, endptr),
        struct _reent *ptr _AND
        struct _reent *ptr _AND
        _CONST wchar_t *nptr _AND
        _CONST wchar_t *nptr _AND
        wchar_t **endptr)
        wchar_t **endptr)
{
{
  double retval = _wcstod_r (ptr, nptr, endptr);
  double retval = _wcstod_r (ptr, nptr, endptr);
  if (isnan (retval))
  if (isnan (retval))
    return nanf (NULL);
    return nanf (NULL);
  return (float)retval;
  return (float)retval;
}
}
 
 
#ifndef _REENT_ONLY
#ifndef _REENT_ONLY
 
 
double
double
_DEFUN (wcstod, (nptr, endptr),
_DEFUN (wcstod, (nptr, endptr),
        _CONST wchar_t *nptr _AND wchar_t **endptr)
        _CONST wchar_t *nptr _AND wchar_t **endptr)
{
{
  return _wcstod_r (_REENT, nptr, endptr);
  return _wcstod_r (_REENT, nptr, endptr);
}
}
 
 
float
float
_DEFUN (wcstof, (nptr, endptr),
_DEFUN (wcstof, (nptr, endptr),
        _CONST wchar_t *nptr _AND
        _CONST wchar_t *nptr _AND
        wchar_t **endptr)
        wchar_t **endptr)
{
{
  double retval = _wcstod_r (_REENT, nptr, endptr);
  double retval = _wcstod_r (_REENT, nptr, endptr);
  if (isnan (retval))
  if (isnan (retval))
    return nanf (NULL);
    return nanf (NULL);
  return (float)retval;
  return (float)retval;
}
}
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.