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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [stdlib/] [strtod.c] - Diff between revs 1325 and 1765

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

Rev 1325 Rev 1765
/*  Copyright (C) 2000, 2003     Manuel Novoa III
/*  Copyright (C) 2000, 2003     Manuel Novoa III
 *
 *
 *  This library is free software; you can redistribute it and/or
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *  version 2 of the License, or (at your option) any later version.
 *
 *
 *  This library is distributed in the hope that it will be useful,
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *  Library General Public License for more details.
 *
 *
 *  You should have received a copy of the GNU Library General Public
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 */
 
 
 
 
/* Notes:
/* Notes:
 *
 *
 * The primary objective of this implementation was minimal size and
 * The primary objective of this implementation was minimal size and
 * portablility, while providing robustness and resonable accuracy.
 * portablility, while providing robustness and resonable accuracy.
 *
 *
 * This implementation depends on IEEE floating point behavior and expects
 * This implementation depends on IEEE floating point behavior and expects
 * to be able to generate +/- infinity as a result.
 * to be able to generate +/- infinity as a result.
 *
 *
 * There are a number of compile-time options below.
 * There are a number of compile-time options below.
 */
 */
 
 
/* July 27, 2003
/* July 27, 2003
 *
 *
 * General cleanup and some minor size optimizations.
 * General cleanup and some minor size optimizations.
 * Change implementation to support __strtofpmax() rather than strtod().
 * Change implementation to support __strtofpmax() rather than strtod().
 *   Now all the strto{floating pt}() funcs are implemented in terms of
 *   Now all the strto{floating pt}() funcs are implemented in terms of
 *   of the internal __strtofpmax() function.
 *   of the internal __strtofpmax() function.
 * Support "nan", "inf", and "infinity" strings (case-insensitive).
 * Support "nan", "inf", and "infinity" strings (case-insensitive).
 * Support hexadecimal floating point notation.
 * Support hexadecimal floating point notation.
 * Support wchar variants.
 * Support wchar variants.
 * Support xlocale variants.
 * Support xlocale variants.
 *
 *
 * TODO:
 * TODO:
 *
 *
 * Consider accumulating blocks of digits in longs to save floating pt mults.
 * Consider accumulating blocks of digits in longs to save floating pt mults.
 *   This would likely be much better on anything that only supported floats
 *   This would likely be much better on anything that only supported floats
 *   where DECIMAL_DIG == 9.  Actually, if floats have FLT_MAX_10_EXP == 38,
 *   where DECIMAL_DIG == 9.  Actually, if floats have FLT_MAX_10_EXP == 38,
 *   we could calculate almost all the exponent multipliers (p_base) in
 *   we could calculate almost all the exponent multipliers (p_base) in
 *   long arithmetic as well.
 *   long arithmetic as well.
 */
 */
 
 
/**********************************************************************/
/**********************************************************************/
/*                                                      OPTIONS                                                                   */
/*                                                      OPTIONS                                                                   */
/**********************************************************************/
/**********************************************************************/
 
 
/* Defined if we want to recognize "nan", "inf", and "infinity". (C99) */
/* Defined if we want to recognize "nan", "inf", and "infinity". (C99) */
#define _STRTOD_NAN_INF_STRINGS  1
#define _STRTOD_NAN_INF_STRINGS  1
 
 
/* Defined if we want support hexadecimal floating point notation. (C99) */
/* Defined if we want support hexadecimal floating point notation. (C99) */
/* Note!  Now controlled by uClibc configuration.  See below. */
/* Note!  Now controlled by uClibc configuration.  See below. */
#define _STRTOD_HEXADECIMAL_FLOATS 1
#define _STRTOD_HEXADECIMAL_FLOATS 1
 
 
/* Defined if we want to scale with a O(log2(exp)) multiplications.
/* Defined if we want to scale with a O(log2(exp)) multiplications.
 * This is generally a good thing to do unless you are really tight
 * This is generally a good thing to do unless you are really tight
 * on space and do not expect to convert values of large magnitude. */
 * on space and do not expect to convert values of large magnitude. */
 
 
#define _STRTOD_LOG_SCALING       1
#define _STRTOD_LOG_SCALING       1
 
 
/* WARNING!!!   WARNING!!!   WARNING!!!   WARNING!!!   WARNING!!!
/* WARNING!!!   WARNING!!!   WARNING!!!   WARNING!!!   WARNING!!!
 *
 *
 * Clearing any of the options below this point is not advised (or tested).
 * Clearing any of the options below this point is not advised (or tested).
 *
 *
 * WARNING!!!   WARNING!!!   WARNING!!!   WARNING!!!   WARNING!!! */
 * WARNING!!!   WARNING!!!   WARNING!!!   WARNING!!!   WARNING!!! */
 
 
/* Defined if we want strtod to set errno appropriately. */
/* Defined if we want strtod to set errno appropriately. */
/* NOTE: Implies all options below. */
/* NOTE: Implies all options below. */
#define _STRTOD_ERRNO                   1
#define _STRTOD_ERRNO                   1
 
 
/* Defined if we want support for the endptr arg. */
/* Defined if we want support for the endptr arg. */
/* Implied by _STRTOD_ERRNO. */
/* Implied by _STRTOD_ERRNO. */
#define _STRTOD_ENDPTR             1
#define _STRTOD_ENDPTR             1
 
 
/* Defined if we want to prevent overflow in accumulating the exponent. */
/* Defined if we want to prevent overflow in accumulating the exponent. */
/* Implied by _STRTOD_ERRNO. */
/* Implied by _STRTOD_ERRNO. */
#define _STRTOD_RESTRICT_EXP     1
#define _STRTOD_RESTRICT_EXP     1
 
 
/* Defined if we want to process mantissa digits more intelligently. */
/* Defined if we want to process mantissa digits more intelligently. */
/* Implied by _STRTOD_ERRNO. */
/* Implied by _STRTOD_ERRNO. */
#define _STRTOD_RESTRICT_DIGITS  1
#define _STRTOD_RESTRICT_DIGITS  1
 
 
/* Defined if we want to skip scaling 0 for the exponent. */
/* Defined if we want to skip scaling 0 for the exponent. */
/* Implied by _STRTOD_ERRNO. */
/* Implied by _STRTOD_ERRNO. */
#define _STRTOD_ZERO_CHECK         1
#define _STRTOD_ZERO_CHECK         1
 
 
/**********************************************************************/
/**********************************************************************/
/* Don't change anything that follows.                                                                     */
/* Don't change anything that follows.                                                                     */
/**********************************************************************/
/**********************************************************************/
 
 
#ifdef _STRTOD_ERRNO
#ifdef _STRTOD_ERRNO
#undef _STRTOD_ENDPTR
#undef _STRTOD_ENDPTR
#undef _STRTOD_RESTRICT_EXP
#undef _STRTOD_RESTRICT_EXP
#undef _STRTOD_RESTRICT_DIGITS
#undef _STRTOD_RESTRICT_DIGITS
#undef _STRTOD_ZERO_CHECK
#undef _STRTOD_ZERO_CHECK
#define _STRTOD_ENDPTR             1
#define _STRTOD_ENDPTR             1
#define _STRTOD_RESTRICT_EXP     1
#define _STRTOD_RESTRICT_EXP     1
#define _STRTOD_RESTRICT_DIGITS  1
#define _STRTOD_RESTRICT_DIGITS  1
#define _STRTOD_ZERO_CHECK         1
#define _STRTOD_ZERO_CHECK         1
#endif
#endif
 
 
/**********************************************************************/
/**********************************************************************/
 
 
#define _ISOC99_SOURCE 1
#define _ISOC99_SOURCE 1
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
#include <ctype.h>
#include <errno.h>
#include <errno.h>
#include <limits.h>
#include <limits.h>
#include <float.h>
#include <float.h>
#include <bits/uClibc_fpmax.h>
#include <bits/uClibc_fpmax.h>
 
 
#include <locale.h>
#include <locale.h>
 
 
#ifdef __UCLIBC_HAS_WCHAR__
#ifdef __UCLIBC_HAS_WCHAR__
 
 
#include <wchar.h>
#include <wchar.h>
#include <wctype.h>
#include <wctype.h>
#include <bits/uClibc_uwchar.h>
#include <bits/uClibc_uwchar.h>
 
 
#endif
#endif
 
 
#ifdef __UCLIBC_HAS_XLOCALE__
#ifdef __UCLIBC_HAS_XLOCALE__
#include <xlocale.h>
#include <xlocale.h>
#endif /* __UCLIBC_HAS_XLOCALE__ */
#endif /* __UCLIBC_HAS_XLOCALE__ */
 
 
 
 
 
 
/* Handle _STRTOD_HEXADECIMAL_FLOATS via uClibc config now. */
/* Handle _STRTOD_HEXADECIMAL_FLOATS via uClibc config now. */
#undef _STRTOD_HEXADECIMAL_FLOATS
#undef _STRTOD_HEXADECIMAL_FLOATS
#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
#define _STRTOD_HEXADECIMAL_FLOATS 1
#define _STRTOD_HEXADECIMAL_FLOATS 1
#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
 
 
/**********************************************************************/
/**********************************************************************/
 
 
#undef _STRTOD_FPMAX
#undef _STRTOD_FPMAX
 
 
#if FPMAX_TYPE == 3
#if FPMAX_TYPE == 3
 
 
#define NEED_STRTOLD_WRAPPER
#define NEED_STRTOLD_WRAPPER
#define NEED_STRTOD_WRAPPER
#define NEED_STRTOD_WRAPPER
#define NEED_STRTOF_WRAPPER
#define NEED_STRTOF_WRAPPER
 
 
#elif FPMAX_TYPE == 2
#elif FPMAX_TYPE == 2
 
 
#define NEED_STRTOD_WRAPPER
#define NEED_STRTOD_WRAPPER
#define NEED_STRTOF_WRAPPER
#define NEED_STRTOF_WRAPPER
 
 
#elif FPMAX_TYPE == 1
#elif FPMAX_TYPE == 1
 
 
#define NEED_STRTOF_WRAPPER
#define NEED_STRTOF_WRAPPER
 
 
#else
#else
 
 
#error unknown FPMAX_TYPE!
#error unknown FPMAX_TYPE!
 
 
#endif
#endif
 
 
extern void __fp_range_check(__fpmax_t y, __fpmax_t x);
extern void __fp_range_check(__fpmax_t y, __fpmax_t x);
 
 
/**********************************************************************/
/**********************************************************************/
 
 
#ifdef _STRTOD_RESTRICT_DIGITS
#ifdef _STRTOD_RESTRICT_DIGITS
#define EXP_DENORM_ADJUST DECIMAL_DIG
#define EXP_DENORM_ADJUST DECIMAL_DIG
#define MAX_ALLOWED_EXP (DECIMAL_DIG  + EXP_DENORM_ADJUST - FPMAX_MIN_10_EXP)
#define MAX_ALLOWED_EXP (DECIMAL_DIG  + EXP_DENORM_ADJUST - FPMAX_MIN_10_EXP)
 
 
#if MAX_ALLOWED_EXP > INT_MAX
#if MAX_ALLOWED_EXP > INT_MAX
#error size assumption violated for MAX_ALLOWED_EXP
#error size assumption violated for MAX_ALLOWED_EXP
#endif
#endif
#else
#else
/* We want some excess if we're not restricting mantissa digits. */
/* We want some excess if we're not restricting mantissa digits. */
#define MAX_ALLOWED_EXP ((20 - FPMAX_MIN_10_EXP) * 2)
#define MAX_ALLOWED_EXP ((20 - FPMAX_MIN_10_EXP) * 2)
#endif
#endif
 
 
 
 
#if defined(_STRTOD_RESTRICT_DIGITS) || defined(_STRTOD_ENDPTR) || defined(_STRTOD_HEXADECIMAL_FLOATS)
#if defined(_STRTOD_RESTRICT_DIGITS) || defined(_STRTOD_ENDPTR) || defined(_STRTOD_HEXADECIMAL_FLOATS)
#undef _STRTOD_NEED_NUM_DIGITS
#undef _STRTOD_NEED_NUM_DIGITS
#define _STRTOD_NEED_NUM_DIGITS 1
#define _STRTOD_NEED_NUM_DIGITS 1
#endif
#endif
 
 
/**********************************************************************/
/**********************************************************************/
#if defined(L___strtofpmax) || defined(L___strtofpmax_l) || defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
#if defined(L___strtofpmax) || defined(L___strtofpmax_l) || defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
 
 
#if defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
#if defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
 
 
#define __strtofpmax    __wcstofpmax
#define __strtofpmax    __wcstofpmax
#define __strtofpmax_l  __wcstofpmax_l
#define __strtofpmax_l  __wcstofpmax_l
 
 
#define Wchar wchar_t
#define Wchar wchar_t
#ifdef __UCLIBC_DO_XLOCALE
#ifdef __UCLIBC_DO_XLOCALE
#define ISSPACE(C) iswspace_l((C), locale_arg)
#define ISSPACE(C) iswspace_l((C), locale_arg)
#else
#else
#define ISSPACE(C) iswspace((C))
#define ISSPACE(C) iswspace((C))
#endif
#endif
 
 
#else  /* defined(L___wcstofpmax) || defined(L___wcstofpmax) */
#else  /* defined(L___wcstofpmax) || defined(L___wcstofpmax) */
 
 
#define Wchar char
#define Wchar char
#ifdef __UCLIBC_DO_XLOCALE
#ifdef __UCLIBC_DO_XLOCALE
#define ISSPACE(C) isspace_l((C), locale_arg)
#define ISSPACE(C) isspace_l((C), locale_arg)
#else
#else
#define ISSPACE(C) isspace((C))
#define ISSPACE(C) isspace((C))
#endif
#endif
 
 
#endif /* defined(L___wcstofpmax) || defined(L___wcstofpmax) */
#endif /* defined(L___wcstofpmax) || defined(L___wcstofpmax) */
 
 
 
 
#if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
#if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)
 
 
__fpmax_t __strtofpmax(const Wchar *str, Wchar **endptr, int exponent_power)
__fpmax_t __strtofpmax(const Wchar *str, Wchar **endptr, int exponent_power)
{
{
        return __strtofpmax_l(str, endptr, exponent_power, __UCLIBC_CURLOCALE);
        return __strtofpmax_l(str, endptr, exponent_power, __UCLIBC_CURLOCALE);
}
}
 
 
#else  /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
#else  /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
 
 
__fpmax_t __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endptr, int exponent_power
__fpmax_t __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endptr, int exponent_power
                                                                 __LOCALE_PARAM )
                                                                 __LOCALE_PARAM )
{
{
        __fpmax_t number;
        __fpmax_t number;
        __fpmax_t p_base = 10;                  /* Adjusted to 16 in the hex case. */
        __fpmax_t p_base = 10;                  /* Adjusted to 16 in the hex case. */
        Wchar *pos0;
        Wchar *pos0;
#ifdef _STRTOD_ENDPTR
#ifdef _STRTOD_ENDPTR
        Wchar *pos1;
        Wchar *pos1;
#endif
#endif
        Wchar *pos = (Wchar *) str;
        Wchar *pos = (Wchar *) str;
        int exponent_temp;
        int exponent_temp;
        int negative; /* A flag for the number, a multiplier for the exponent. */
        int negative; /* A flag for the number, a multiplier for the exponent. */
#ifdef _STRTOD_NEED_NUM_DIGITS
#ifdef _STRTOD_NEED_NUM_DIGITS
        int num_digits;
        int num_digits;
#endif
#endif
#ifdef __UCLIBC_HAS_LOCALE__
#ifdef __UCLIBC_HAS_LOCALE__
        const char *decpt = __LOCALE_PTR->decimal_point;
        const char *decpt = __LOCALE_PTR->decimal_point;
#if defined(L___wcstofpmax) || defined(L___wcstofpmax)
#if defined(L___wcstofpmax) || defined(L___wcstofpmax)
        wchar_t decpt_wc = __LOCALE_PTR->decimal_point;
        wchar_t decpt_wc = __LOCALE_PTR->decimal_point;
#else
#else
        int decpt_len = __LOCALE_PTR->decimal_point_len;
        int decpt_len = __LOCALE_PTR->decimal_point_len;
#endif
#endif
#endif
#endif
 
 
#ifdef _STRTOD_HEXADECIMAL_FLOATS
#ifdef _STRTOD_HEXADECIMAL_FLOATS
        Wchar expchar = 'e';
        Wchar expchar = 'e';
        Wchar *poshex = NULL;
        Wchar *poshex = NULL;
        __uint16_t is_mask = _ISdigit;
        __uint16_t is_mask = _ISdigit;
#define EXPCHAR         expchar
#define EXPCHAR         expchar
#define IS_X_DIGIT(C) __isctype((C), is_mask)
#define IS_X_DIGIT(C) __isctype((C), is_mask)
#else  /* _STRTOD_HEXADECIMAL_FLOATS */
#else  /* _STRTOD_HEXADECIMAL_FLOATS */
#define EXPCHAR         'e'
#define EXPCHAR         'e'
#define IS_X_DIGIT(C) isdigit((C))
#define IS_X_DIGIT(C) isdigit((C))
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
 
 
        while (ISSPACE(*pos)) {         /* Skip leading whitespace. */
        while (ISSPACE(*pos)) {         /* Skip leading whitespace. */
                ++pos;
                ++pos;
        }
        }
 
 
        negative = 0;
        negative = 0;
        switch(*pos) {                          /* Handle optional sign. */
        switch(*pos) {                          /* Handle optional sign. */
                case '-': negative = 1; /* Fall through to increment position. */
                case '-': negative = 1; /* Fall through to increment position. */
                case '+': ++pos;
                case '+': ++pos;
        }
        }
 
 
#ifdef _STRTOD_HEXADECIMAL_FLOATS
#ifdef _STRTOD_HEXADECIMAL_FLOATS
        if ((*pos == '0') && (((pos[1])|0x20) == 'x')) {
        if ((*pos == '0') && (((pos[1])|0x20) == 'x')) {
                poshex = ++pos;                 /* Save position of 'x' in case no digits */
                poshex = ++pos;                 /* Save position of 'x' in case no digits */
                ++pos;                                  /*   and advance past it.  */
                ++pos;                                  /*   and advance past it.  */
                is_mask = _ISxdigit;    /* Used by IS_X_DIGIT. */
                is_mask = _ISxdigit;    /* Used by IS_X_DIGIT. */
                expchar = 'p';                  /* Adjust exponent char. */
                expchar = 'p';                  /* Adjust exponent char. */
                p_base = 16;                    /* Adjust base multiplier. */
                p_base = 16;                    /* Adjust base multiplier. */
        }
        }
#endif
#endif
 
 
        number = 0.;
        number = 0.;
#ifdef _STRTOD_NEED_NUM_DIGITS
#ifdef _STRTOD_NEED_NUM_DIGITS
        num_digits = -1;
        num_digits = -1;
#endif
#endif
/*      exponent_power = 0; */
/*      exponent_power = 0; */
        pos0 = NULL;
        pos0 = NULL;
 
 
 LOOP:
 LOOP:
        while (IS_X_DIGIT(*pos)) {      /* Process string of (hex) digits. */
        while (IS_X_DIGIT(*pos)) {      /* Process string of (hex) digits. */
#ifdef _STRTOD_RESTRICT_DIGITS
#ifdef _STRTOD_RESTRICT_DIGITS
                if (num_digits < 0) {    /* First time through? */
                if (num_digits < 0) {    /* First time through? */
                        ++num_digits;           /* We've now seen a digit. */
                        ++num_digits;           /* We've now seen a digit. */
                }
                }
                if (num_digits || (*pos != '0')) { /* Had/have nonzero. */
                if (num_digits || (*pos != '0')) { /* Had/have nonzero. */
                        ++num_digits;
                        ++num_digits;
                        if (num_digits <= DECIMAL_DIG) { /* Is digit significant? */
                        if (num_digits <= DECIMAL_DIG) { /* Is digit significant? */
#ifdef _STRTOD_HEXADECIMAL_FLOATS
#ifdef _STRTOD_HEXADECIMAL_FLOATS
                                number = number * p_base
                                number = number * p_base
                                        + (isdigit(*pos)
                                        + (isdigit(*pos)
                                           ? (*pos - '0')
                                           ? (*pos - '0')
                                           : (((*pos)|0x20) - ('a' - 10)));
                                           : (((*pos)|0x20) - ('a' - 10)));
#else  /* _STRTOD_HEXADECIMAL_FLOATS */
#else  /* _STRTOD_HEXADECIMAL_FLOATS */
                                number = number * p_base + (*pos - '0');
                                number = number * p_base + (*pos - '0');
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
                        }
                        }
                }
                }
#else  /* _STRTOD_RESTRICT_DIGITS */
#else  /* _STRTOD_RESTRICT_DIGITS */
#ifdef _STRTOD_NEED_NUM_DIGITS
#ifdef _STRTOD_NEED_NUM_DIGITS
                ++num_digits;
                ++num_digits;
#endif
#endif
#ifdef _STRTOD_HEXADECIMAL_FLOATS
#ifdef _STRTOD_HEXADECIMAL_FLOATS
                number = number * p_base
                number = number * p_base
                        + (isdigit(*pos)
                        + (isdigit(*pos)
                           ? (*pos - '0')
                           ? (*pos - '0')
                           : (((*pos)|0x20) - ('a' - 10)));
                           : (((*pos)|0x20) - ('a' - 10)));
#else  /* _STRTOD_HEXADECIMAL_FLOATS */
#else  /* _STRTOD_HEXADECIMAL_FLOATS */
                number = number * p_base + (*pos - '0');
                number = number * p_base + (*pos - '0');
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
#endif /* _STRTOD_RESTRICT_DIGITS */
#endif /* _STRTOD_RESTRICT_DIGITS */
                ++pos;
                ++pos;
        }
        }
 
 
#ifdef __UCLIBC_HAS_LOCALE__
#ifdef __UCLIBC_HAS_LOCALE__
#if defined(L___wcstofpmax) || defined(L___wcstofpmax)
#if defined(L___wcstofpmax) || defined(L___wcstofpmax)
        if (!pos0 && (*pos == decpt_wc)) { /* First decimal point? */
        if (!pos0 && (*pos == decpt_wc)) { /* First decimal point? */
                pos0 = ++pos;
                pos0 = ++pos;
                goto LOOP;
                goto LOOP;
        }
        }
#else
#else
        if (!pos0 && !memcmp(pos, decpt, decpt_len)) { /* First decimal point? */
        if (!pos0 && !memcmp(pos, decpt, decpt_len)) { /* First decimal point? */
                pos0 = (pos += decpt_len);
                pos0 = (pos += decpt_len);
                goto LOOP;
                goto LOOP;
        }
        }
#endif
#endif
#else  /* __UCLIBC_HAS_LOCALE__ */
#else  /* __UCLIBC_HAS_LOCALE__ */
        if ((*pos == '.') && !pos0) { /* First decimal point? */
        if ((*pos == '.') && !pos0) { /* First decimal point? */
                pos0 = ++pos;                   /* Save position of decimal point */
                pos0 = ++pos;                   /* Save position of decimal point */
                goto LOOP;                              /*   and process rest of digits. */
                goto LOOP;                              /*   and process rest of digits. */
        }
        }
#endif /* __UCLIBC_HAS_LOCALE__ */
#endif /* __UCLIBC_HAS_LOCALE__ */
 
 
#ifdef _STRTOD_NEED_NUM_DIGITS
#ifdef _STRTOD_NEED_NUM_DIGITS
        if (num_digits<0) {                      /* Must have at least one digit. */
        if (num_digits<0) {                      /* Must have at least one digit. */
#ifdef _STRTOD_HEXADECIMAL_FLOATS
#ifdef _STRTOD_HEXADECIMAL_FLOATS
                if (poshex) {                   /* Back up to '0' in '0x' prefix. */
                if (poshex) {                   /* Back up to '0' in '0x' prefix. */
                        pos = poshex;
                        pos = poshex;
                        goto DONE;
                        goto DONE;
                }
                }
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
 
 
#ifdef _STRTOD_NAN_INF_STRINGS
#ifdef _STRTOD_NAN_INF_STRINGS
                if (!pos0) {                    /* No decimal point, so check for inf/nan. */
                if (!pos0) {                    /* No decimal point, so check for inf/nan. */
                        /* Note: nan is the first string so 'number = i/0.;' works. */
                        /* Note: nan is the first string so 'number = i/0.;' works. */
                        static const char nan_inf_str[] = "\05nan\0\012infinity\0\05inf\0";
                        static const char nan_inf_str[] = "\05nan\0\012infinity\0\05inf\0";
                        int i = 0;
                        int i = 0;
 
 
#ifdef __UCLIBC_HAS_LOCALE__
#ifdef __UCLIBC_HAS_LOCALE__
                        /* Avoid tolower problems for INFINITY in the tr_TR locale. (yuk)*/
                        /* Avoid tolower problems for INFINITY in the tr_TR locale. (yuk)*/
#undef _tolower
#undef _tolower
#define _tolower(C)     ((C)|0x20)
#define _tolower(C)     ((C)|0x20)
#endif /* __UCLIBC_HAS_LOCALE__ */
#endif /* __UCLIBC_HAS_LOCALE__ */
 
 
                        do {
                        do {
                                /* Unfortunately, we have no memcasecmp(). */
                                /* Unfortunately, we have no memcasecmp(). */
                                int j = 0;
                                int j = 0;
                                while (_tolower(pos[j]) == nan_inf_str[i+1+j]) {
                                while (_tolower(pos[j]) == nan_inf_str[i+1+j]) {
                                        ++j;
                                        ++j;
                                        if (!nan_inf_str[i+1+j]) {
                                        if (!nan_inf_str[i+1+j]) {
                                                number = i / 0.;
                                                number = i / 0.;
                                                if (negative) { /* Correct for sign. */
                                                if (negative) { /* Correct for sign. */
                                                        number = -number;
                                                        number = -number;
                                                }
                                                }
                                                pos += nan_inf_str[i] - 2;
                                                pos += nan_inf_str[i] - 2;
                                                goto DONE;
                                                goto DONE;
                                        }
                                        }
                                }
                                }
                                i += nan_inf_str[i];
                                i += nan_inf_str[i];
                        } while (nan_inf_str[i]);
                        } while (nan_inf_str[i]);
                }
                }
 
 
#endif /* STRTOD_NAN_INF_STRINGS */
#endif /* STRTOD_NAN_INF_STRINGS */
#ifdef _STRTOD_ENDPTR
#ifdef _STRTOD_ENDPTR
                pos = (Wchar *) str;
                pos = (Wchar *) str;
#endif
#endif
                goto DONE;
                goto DONE;
        }
        }
#endif /* _STRTOD_NEED_NUM_DIGITS */
#endif /* _STRTOD_NEED_NUM_DIGITS */
 
 
#ifdef _STRTOD_RESTRICT_DIGITS
#ifdef _STRTOD_RESTRICT_DIGITS
        if (num_digits > DECIMAL_DIG) { /* Adjust exponent for skipped digits. */
        if (num_digits > DECIMAL_DIG) { /* Adjust exponent for skipped digits. */
                exponent_power += num_digits - DECIMAL_DIG;
                exponent_power += num_digits - DECIMAL_DIG;
        }
        }
#endif
#endif
 
 
        if (pos0) {
        if (pos0) {
                exponent_power += pos0 - pos; /* Adjust exponent for decimal point. */
                exponent_power += pos0 - pos; /* Adjust exponent for decimal point. */
        }
        }
 
 
#ifdef _STRTOD_HEXADECIMAL_FLOATS
#ifdef _STRTOD_HEXADECIMAL_FLOATS
        if (poshex) {
        if (poshex) {
                exponent_power *= 4;    /* Above is 2**4, but below is 2. */
                exponent_power *= 4;    /* Above is 2**4, but below is 2. */
                p_base = 2;
                p_base = 2;
        }
        }
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
#endif /* _STRTOD_HEXADECIMAL_FLOATS */
 
 
        if (negative) {                         /* Correct for sign. */
        if (negative) {                         /* Correct for sign. */
                number = -number;
                number = -number;
        }
        }
 
 
        /* process an exponent string */
        /* process an exponent string */
        if (((*pos)|0x20) == EXPCHAR) {
        if (((*pos)|0x20) == EXPCHAR) {
#ifdef _STRTOD_ENDPTR
#ifdef _STRTOD_ENDPTR
                pos1 = pos;
                pos1 = pos;
#endif
#endif
                negative = 1;
                negative = 1;
                switch(*++pos) {                /* Handle optional sign. */
                switch(*++pos) {                /* Handle optional sign. */
                        case '-': negative = -1; /* Fall through to increment pos. */
                        case '-': negative = -1; /* Fall through to increment pos. */
                        case '+': ++pos;
                        case '+': ++pos;
                }
                }
 
 
                pos0 = pos;
                pos0 = pos;
                exponent_temp = 0;
                exponent_temp = 0;
                while (isdigit(*pos)) { /* Process string of digits. */
                while (isdigit(*pos)) { /* Process string of digits. */
#ifdef _STRTOD_RESTRICT_EXP
#ifdef _STRTOD_RESTRICT_EXP
                        if (exponent_temp < MAX_ALLOWED_EXP) { /* Avoid overflow. */
                        if (exponent_temp < MAX_ALLOWED_EXP) { /* Avoid overflow. */
                                exponent_temp = exponent_temp * 10 + (*pos - '0');
                                exponent_temp = exponent_temp * 10 + (*pos - '0');
                        }
                        }
#else
#else
                        exponent_temp = exponent_temp * 10 + (*pos - '0');
                        exponent_temp = exponent_temp * 10 + (*pos - '0');
#endif
#endif
                        ++pos;
                        ++pos;
                }
                }
 
 
#ifdef _STRTOD_ENDPTR
#ifdef _STRTOD_ENDPTR
                if (pos == pos0) {      /* No digits? */
                if (pos == pos0) {      /* No digits? */
                        pos = pos1;             /* Back up to {e|E}/{p|P}. */
                        pos = pos1;             /* Back up to {e|E}/{p|P}. */
                } /* else */
                } /* else */
#endif
#endif
 
 
                exponent_power += negative * exponent_temp;
                exponent_power += negative * exponent_temp;
        }
        }
 
 
#ifdef _STRTOD_ZERO_CHECK
#ifdef _STRTOD_ZERO_CHECK
        if (number == 0.) {
        if (number == 0.) {
                goto DONE;
                goto DONE;
        }
        }
#endif
#endif
 
 
        /* scale the result */
        /* scale the result */
#ifdef _STRTOD_LOG_SCALING
#ifdef _STRTOD_LOG_SCALING
        exponent_temp = exponent_power;
        exponent_temp = exponent_power;
 
 
        if (exponent_temp < 0) {
        if (exponent_temp < 0) {
                exponent_temp = -exponent_temp;
                exponent_temp = -exponent_temp;
        }
        }
 
 
        while (exponent_temp) {
        while (exponent_temp) {
                if (exponent_temp & 1) {
                if (exponent_temp & 1) {
                        if (exponent_power < 0) {
                        if (exponent_power < 0) {
                                /* Warning... caluclating a factor for the exponent and
                                /* Warning... caluclating a factor for the exponent and
                                 * then dividing could easily be faster.  But doing so
                                 * then dividing could easily be faster.  But doing so
                                 * might cause problems when dealing with denormals. */
                                 * might cause problems when dealing with denormals. */
                                number /= p_base;
                                number /= p_base;
                        } else {
                        } else {
                                number *= p_base;
                                number *= p_base;
                        }
                        }
                }
                }
                exponent_temp >>= 1;
                exponent_temp >>= 1;
                p_base *= p_base;
                p_base *= p_base;
        }
        }
 
 
#else  /* _STRTOD_LOG_SCALING */
#else  /* _STRTOD_LOG_SCALING */
        while (exponent_power) {
        while (exponent_power) {
                if (exponent_power < 0) {
                if (exponent_power < 0) {
                        number /= p_base;
                        number /= p_base;
                        exponent_power++;
                        exponent_power++;
                } else {
                } else {
                        number *= p_base;
                        number *= p_base;
                        exponent_power--;
                        exponent_power--;
                }
                }
        }
        }
#endif /* _STRTOD_LOG_SCALING */
#endif /* _STRTOD_LOG_SCALING */
 
 
#ifdef _STRTOD_ERRNO
#ifdef _STRTOD_ERRNO
        if (__FPMAX_ZERO_OR_INF_CHECK(number)) {
        if (__FPMAX_ZERO_OR_INF_CHECK(number)) {
                __set_errno(ERANGE);
                __set_errno(ERANGE);
        }
        }
#endif
#endif
 
 
 DONE:
 DONE:
#ifdef _STRTOD_ENDPTR
#ifdef _STRTOD_ENDPTR
        if (endptr) {
        if (endptr) {
                *endptr = pos;
                *endptr = pos;
        }
        }
#endif
#endif
 
 
        return number;
        return number;
}
}
 
 
#endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
#endif /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */
 
 
#endif
#endif
/**********************************************************************/
/**********************************************************************/
#ifdef L___fp_range_check
#ifdef L___fp_range_check
#if defined(NEED_STRTOF_WRAPPER) || defined(NEED_STRTOD_WRAPPER)
#if defined(NEED_STRTOF_WRAPPER) || defined(NEED_STRTOD_WRAPPER)
 
 
extern void __fp_range_check(__fpmax_t y, __fpmax_t x)
extern void __fp_range_check(__fpmax_t y, __fpmax_t x)
{
{
        if (__FPMAX_ZERO_OR_INF_CHECK(y) /* y is 0 or +/- infinity */
        if (__FPMAX_ZERO_OR_INF_CHECK(y) /* y is 0 or +/- infinity */
                && (y != 0)      /* y is not 0 (could have x>0, y==0 if underflow) */
                && (y != 0)      /* y is not 0 (could have x>0, y==0 if underflow) */
                && !__FPMAX_ZERO_OR_INF_CHECK(x) /* x is not 0 or +/- infinity */
                && !__FPMAX_ZERO_OR_INF_CHECK(x) /* x is not 0 or +/- infinity */
                ) {
                ) {
                __set_errno(ERANGE);    /* Then x is not in y's range. */
                __set_errno(ERANGE);    /* Then x is not in y's range. */
        }
        }
}
}
 
 
#endif
#endif
#endif
#endif
/**********************************************************************/
/**********************************************************************/
#if defined(L_strtof) || defined(L_strtof_l) || defined(L_wcstof) || defined(L_wcstof_l)
#if defined(L_strtof) || defined(L_strtof_l) || defined(L_wcstof) || defined(L_wcstof_l)
#if defined(NEED_STRTOF_WRAPPER)
#if defined(NEED_STRTOF_WRAPPER)
 
 
#if defined(L_wcstof) || defined(L_wcstof_l)
#if defined(L_wcstof) || defined(L_wcstof_l)
#define strtof           wcstof
#define strtof           wcstof
#define strtof_l         wcstof_l
#define strtof_l         wcstof_l
#define __strtof         __wcstof
#define __strtof         __wcstof
#define __strtof_l       __wcstof_l
#define __strtof_l       __wcstof_l
#define __strtofpmax     __wcstofpmax
#define __strtofpmax     __wcstofpmax
#define __strtofpmax_l   __wcstofpmax_l
#define __strtofpmax_l   __wcstofpmax_l
#define Wchar wchar_t
#define Wchar wchar_t
#else
#else
#define Wchar char
#define Wchar char
#endif
#endif
 
 
 
 
float __XL(strtof)(const Wchar *str, Wchar **endptr   __LOCALE_PARAM )
float __XL(strtof)(const Wchar *str, Wchar **endptr   __LOCALE_PARAM )
{
{
#if FPMAX_TYPE == 1
#if FPMAX_TYPE == 1
        return __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
        return __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
#else
#else
        __fpmax_t x;
        __fpmax_t x;
        float y;
        float y;
 
 
        x = __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
        x = __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
        y = (float) x;
        y = (float) x;
 
 
        __fp_range_check(y, x);
        __fp_range_check(y, x);
 
 
        return y;
        return y;
#endif
#endif
}
}
 
 
__XL_ALIAS(strtof)
__XL_ALIAS(strtof)
 
 
#endif
#endif
#endif
#endif
/**********************************************************************/
/**********************************************************************/
#if defined(L_strtod) || defined(L_strtod_l) || defined(L_wcstod) || defined(L_wcstod_l)
#if defined(L_strtod) || defined(L_strtod_l) || defined(L_wcstod) || defined(L_wcstod_l)
#if defined(NEED_STRTOD_WRAPPER)
#if defined(NEED_STRTOD_WRAPPER)
 
 
#if defined(L_wcstod) || defined(L_wcstod_l)
#if defined(L_wcstod) || defined(L_wcstod_l)
#define strtod           wcstod
#define strtod           wcstod
#define strtod_l         wcstod_l
#define strtod_l         wcstod_l
#define __strtod         __wcstod
#define __strtod         __wcstod
#define __strtod_l       __wcstod_l
#define __strtod_l       __wcstod_l
#define __strtofpmax     __wcstofpmax
#define __strtofpmax     __wcstofpmax
#define __strtofpmax_l   __wcstofpmax_l
#define __strtofpmax_l   __wcstofpmax_l
#define Wchar wchar_t
#define Wchar wchar_t
#else
#else
#define Wchar char
#define Wchar char
#endif
#endif
 
 
double __XL(strtod)(const Wchar *__restrict str,
double __XL(strtod)(const Wchar *__restrict str,
                                        Wchar **__restrict endptr   __LOCALE_PARAM )
                                        Wchar **__restrict endptr   __LOCALE_PARAM )
{
{
#if FPMAX_TYPE == 2
#if FPMAX_TYPE == 2
        return __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
        return __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
#else
#else
        __fpmax_t x;
        __fpmax_t x;
        double y;
        double y;
 
 
        x = __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
        x = __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
        y = (double) x;
        y = (double) x;
 
 
        __fp_range_check(y, x);
        __fp_range_check(y, x);
 
 
        return y;
        return y;
#endif
#endif
}
}
 
 
__XL_ALIAS(strtod)
__XL_ALIAS(strtod)
 
 
#endif
#endif
#endif
#endif
/**********************************************************************/
/**********************************************************************/
#if defined(L_strtold) || defined(L_strtold_l) || defined(L_wcstold) || defined(L_wcstold_l)
#if defined(L_strtold) || defined(L_strtold_l) || defined(L_wcstold) || defined(L_wcstold_l)
#if defined(NEED_STRTOLD_WRAPPER)
#if defined(NEED_STRTOLD_WRAPPER)
 
 
#if defined(L_wcstold) || defined(L_wcstold_l)
#if defined(L_wcstold) || defined(L_wcstold_l)
#define strtold           wcstold
#define strtold           wcstold
#define strtold_l         wcstold_l
#define strtold_l         wcstold_l
#define __strtold         __wcstold
#define __strtold         __wcstold
#define __strtold_l       __wcstold_l
#define __strtold_l       __wcstold_l
#define __strtofpmax     __wcstofpmax
#define __strtofpmax     __wcstofpmax
#define __strtofpmax_l   __wcstofpmax_l
#define __strtofpmax_l   __wcstofpmax_l
#define Wchar wchar_t
#define Wchar wchar_t
#else
#else
#define Wchar char
#define Wchar char
#endif
#endif
 
 
long double __XL(strtold)(const Wchar *str, Wchar **endptr   __LOCALE_PARAM )
long double __XL(strtold)(const Wchar *str, Wchar **endptr   __LOCALE_PARAM )
{
{
#if FPMAX_TYPE == 3
#if FPMAX_TYPE == 3
        return __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
        return __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
#else
#else
        __fpmax_t x;
        __fpmax_t x;
        long double y;
        long double y;
 
 
        x = __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
        x = __XL_NPP(__strtofpmax)(str, endptr, 0   __LOCALE_ARG );
        y = (long double) x;
        y = (long double) x;
 
 
        __fp_range_check(y, x);
        __fp_range_check(y, x);
 
 
        return y;
        return y;
#endif
#endif
}
}
 
 
__XL_ALIAS(strtold)
__XL_ALIAS(strtold)
 
 
#endif
#endif
#endif
#endif
/**********************************************************************/
/**********************************************************************/
 
 

powered by: WebSVN 2.1.0

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