OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [stdlib/] [strtod.c] - Diff between revs 207 and 345

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

Rev 207 Rev 345
/*
/*
FUNCTION
FUNCTION
        <<strtod>>, <<strtof>>---string to double or float
        <<strtod>>, <<strtof>>---string to double or float
 
 
INDEX
INDEX
        strtod
        strtod
INDEX
INDEX
        _strtod_r
        _strtod_r
INDEX
INDEX
        strtof
        strtof
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <stdlib.h>
        #include <stdlib.h>
        double strtod(const char *<[str]>, char **<[tail]>);
        double strtod(const char *<[str]>, char **<[tail]>);
        float strtof(const char *<[str]>, char **<[tail]>);
        float strtof(const char *<[str]>, char **<[tail]>);
 
 
        double _strtod_r(void *<[reent]>,
        double _strtod_r(void *<[reent]>,
                         const char *<[str]>, char **<[tail]>);
                         const char *<[str]>, char **<[tail]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <stdlib.h>
        #include <stdlib.h>
        double strtod(<[str]>,<[tail]>)
        double strtod(<[str]>,<[tail]>)
        char *<[str]>;
        char *<[str]>;
        char **<[tail]>;
        char **<[tail]>;
 
 
        float strtof(<[str]>,<[tail]>)
        float strtof(<[str]>,<[tail]>)
        char *<[str]>;
        char *<[str]>;
        char **<[tail]>;
        char **<[tail]>;
 
 
        double _strtod_r(<[reent]>,<[str]>,<[tail]>)
        double _strtod_r(<[reent]>,<[str]>,<[tail]>)
        char *<[reent]>;
        char *<[reent]>;
        char *<[str]>;
        char *<[str]>;
        char **<[tail]>;
        char **<[tail]>;
 
 
DESCRIPTION
DESCRIPTION
        The function <<strtod>> parses the character string <[str]>,
        The function <<strtod>> parses the 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]>.
        <<strtof>> is identical to <<strtod>> except for its return type.
        <<strtof>> is identical to <<strtod>> 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, <<strtof>> is currently subject to
        round-even rule.  However, <<strtof>> is currently subject to
        double rounding errors.
        double rounding errors.
 
 
        The alternate function <<_strtod_r>> is a reentrant version.
        The alternate function <<_strtod_r>> is a reentrant version.
        The extra argument <[reent]> is a pointer to a reentrancy structure.
        The extra argument <[reent]> is a pointer to a reentrancy structure.
 
 
RETURNS
RETURNS
        <<strtod>> returns the converted substring value, if any.  If
        <<strtod>> returns 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>>.
*/
*/
 
 
/****************************************************************
/****************************************************************
 
 
The author of this software is David M. Gay.
The author of this software is David M. Gay.
 
 
Copyright (C) 1998-2001 by Lucent Technologies
Copyright (C) 1998-2001 by Lucent Technologies
All Rights Reserved
All Rights Reserved
 
 
Permission to use, copy, modify, and distribute this software and
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby
its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of Lucent or any of its entities
documentation, and that the name of Lucent or any of its entities
not be used in advertising or publicity pertaining to
not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
distribution of the software without specific, written prior
permission.
permission.
 
 
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
THIS SOFTWARE.
 
 
****************************************************************/
****************************************************************/
 
 
/* Please send bug reports to David M. Gay (dmg at acm dot org,
/* Please send bug reports to David M. Gay (dmg at acm dot org,
 * with " at " changed at "@" and " dot " changed to ".").      */
 * with " at " changed at "@" and " dot " changed to ".").      */
 
 
/* Original file gdtoa-strtod.c Modified 06-21-2006 by Jeff Johnston to work within newlib.  */
/* Original file gdtoa-strtod.c Modified 06-21-2006 by Jeff Johnston to work within newlib.  */
 
 
#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 "mprec.h"
#include "mprec.h"
#include "gdtoa.h"
#include "gdtoa.h"
#include "gd_qnan.h"
#include "gd_qnan.h"
 
 
/* #ifndef NO_FENV_H */
/* #ifndef NO_FENV_H */
/* #include <fenv.h> */
/* #include <fenv.h> */
/* #endif */
/* #endif */
 
 
#include "locale.h"
#include "locale.h"
 
 
#ifdef IEEE_Arith
#ifdef IEEE_Arith
#ifndef NO_IEEE_Scale
#ifndef NO_IEEE_Scale
#define Avoid_Underflow
#define Avoid_Underflow
#undef tinytens
#undef tinytens
/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */
/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */
/* flag unnecessarily.  It leads to a song and dance at the end of strtod. */
/* flag unnecessarily.  It leads to a song and dance at the end of strtod. */
static _CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,
static _CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,
                9007199254740992.e-256
                9007199254740992.e-256
                };
                };
#endif
#endif
#endif
#endif
 
 
#ifdef Honor_FLT_ROUNDS
#ifdef Honor_FLT_ROUNDS
#define Rounding rounding
#define Rounding rounding
#undef Check_FLT_ROUNDS
#undef Check_FLT_ROUNDS
#define Check_FLT_ROUNDS
#define Check_FLT_ROUNDS
#else
#else
#define Rounding Flt_Rounds
#define Rounding Flt_Rounds
#endif
#endif
 
 
#ifndef NO_HEX_FP
#ifndef NO_HEX_FP
 
 
static void
static void
_DEFUN (ULtod, (L, bits, exp, k),
_DEFUN (ULtod, (L, bits, exp, k),
        __ULong *L _AND
        __ULong *L _AND
        __ULong *bits _AND
        __ULong *bits _AND
        Long exp _AND
        Long exp _AND
        int k)
        int k)
{
{
        switch(k & STRTOG_Retmask) {
        switch(k & STRTOG_Retmask) {
          case STRTOG_NoNumber:
          case STRTOG_NoNumber:
          case STRTOG_Zero:
          case STRTOG_Zero:
                L[0] = L[1] = 0;
                L[0] = L[1] = 0;
                break;
                break;
 
 
          case STRTOG_Denormal:
          case STRTOG_Denormal:
                L[_1] = bits[0];
                L[_1] = bits[0];
                L[_0] = bits[1];
                L[_0] = bits[1];
                break;
                break;
 
 
          case STRTOG_Normal:
          case STRTOG_Normal:
          case STRTOG_NaNbits:
          case STRTOG_NaNbits:
                L[_1] = bits[0];
                L[_1] = bits[0];
                L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
                L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
                break;
                break;
 
 
          case STRTOG_Infinite:
          case STRTOG_Infinite:
                L[_0] = 0x7ff00000;
                L[_0] = 0x7ff00000;
                L[_1] = 0;
                L[_1] = 0;
                break;
                break;
 
 
          case STRTOG_NaN:
          case STRTOG_NaN:
                L[_0] = 0x7fffffff;
                L[_0] = 0x7fffffff;
                L[_1] = (__ULong)-1;
                L[_1] = (__ULong)-1;
          }
          }
        if (k & STRTOG_Neg)
        if (k & STRTOG_Neg)
                L[_0] |= 0x80000000L;
                L[_0] |= 0x80000000L;
}
}
#endif /* !NO_HEX_FP */
#endif /* !NO_HEX_FP */
 
 
#ifdef INFNAN_CHECK
#ifdef INFNAN_CHECK
static int
static int
_DEFUN (match, (sp, t),
_DEFUN (match, (sp, t),
        _CONST char **sp _AND
        _CONST char **sp _AND
        char *t)
        char *t)
{
{
        int c, d;
        int c, d;
        _CONST char *s = *sp;
        _CONST char *s = *sp;
 
 
        while( (d = *t++) !=0) {
        while( (d = *t++) !=0) {
                if ((c = *++s) >= 'A' && c <= 'Z')
                if ((c = *++s) >= 'A' && c <= 'Z')
                        c += 'a' - 'A';
                        c += 'a' - 'A';
                if (c != d)
                if (c != d)
                        return 0;
                        return 0;
                }
                }
        *sp = s + 1;
        *sp = s + 1;
        return 1;
        return 1;
}
}
#endif /* INFNAN_CHECK */
#endif /* INFNAN_CHECK */
 
 
 
 
double
double
_DEFUN (_strtod_r, (ptr, s00, se),
_DEFUN (_strtod_r, (ptr, s00, se),
        struct _reent *ptr _AND
        struct _reent *ptr _AND
        _CONST char *s00 _AND
        _CONST char *s00 _AND
        char **se)
        char **se)
{
{
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
        int scale;
        int scale;
#endif
#endif
        int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, dsign,
        int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, dsign,
                 e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
                 e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
        _CONST char *s, *s0, *s1;
        _CONST char *s, *s0, *s1;
        double aadj, adj;
        double aadj, adj;
        U aadj1, rv, rv0;
        U aadj1, rv, rv0;
        Long L;
        Long L;
        __ULong y, z;
        __ULong y, z;
        _Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
        _Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
#ifdef SET_INEXACT
#ifdef SET_INEXACT
        int inexact, oldinexact;
        int inexact, oldinexact;
#endif
#endif
#ifdef Honor_FLT_ROUNDS
#ifdef Honor_FLT_ROUNDS
        int rounding;
        int rounding;
#endif
#endif
 
 
        delta = bs = bd = NULL;
        delta = bs = bd = NULL;
        sign = nz0 = nz = decpt = 0;
        sign = nz0 = nz = decpt = 0;
        dval(rv) = 0.;
        dval(rv) = 0.;
        for(s = s00;;s++) switch(*s) {
        for(s = s00;;s++) switch(*s) {
                case '-':
                case '-':
                        sign = 1;
                        sign = 1;
                        /* no break */
                        /* no break */
                case '+':
                case '+':
                        if (*++s)
                        if (*++s)
                                goto break2;
                                goto break2;
                        /* no break */
                        /* no break */
                case 0:
                case 0:
                        goto ret0;
                        goto ret0;
                case '\t':
                case '\t':
                case '\n':
                case '\n':
                case '\v':
                case '\v':
                case '\f':
                case '\f':
                case '\r':
                case '\r':
                case ' ':
                case ' ':
                        continue;
                        continue;
                default:
                default:
                        goto break2;
                        goto break2;
                }
                }
 break2:
 break2:
        if (*s == '0') {
        if (*s == '0') {
#ifndef NO_HEX_FP
#ifndef NO_HEX_FP
                {
                {
                static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
                static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
                Long exp;
                Long exp;
                __ULong bits[2];
                __ULong bits[2];
                switch(s[1]) {
                switch(s[1]) {
                  case 'x':
                  case 'x':
                  case 'X':
                  case 'X':
                        /* If the number is not hex, then the parse of
                        /* If the number is not hex, then the parse of
                           0 is still valid.  */
                           0 is still valid.  */
                        s00 = s + 1;
                        s00 = s + 1;
                        {
                        {
#if defined(FE_DOWNWARD) && defined(FE_TONEAREST) && defined(FE_TOWARDZERO) && defined(FE_UPWARD)
#if defined(FE_DOWNWARD) && defined(FE_TONEAREST) && defined(FE_TOWARDZERO) && defined(FE_UPWARD)
                        FPI fpi1 = fpi;
                        FPI fpi1 = fpi;
                        switch(fegetround()) {
                        switch(fegetround()) {
                          case FE_TOWARDZERO:   fpi1.rounding = 0; break;
                          case FE_TOWARDZERO:   fpi1.rounding = 0; break;
                          case FE_UPWARD:       fpi1.rounding = 2; break;
                          case FE_UPWARD:       fpi1.rounding = 2; break;
                          case FE_DOWNWARD:     fpi1.rounding = 3;
                          case FE_DOWNWARD:     fpi1.rounding = 3;
                          }
                          }
#else
#else
#define fpi1 fpi
#define fpi1 fpi
#endif
#endif
                        switch((i = gethex(ptr, &s, &fpi1, &exp, &bb, sign)) & STRTOG_Retmask) {
                        switch((i = gethex(ptr, &s, &fpi1, &exp, &bb, sign)) & STRTOG_Retmask) {
                          case STRTOG_NoNumber:
                          case STRTOG_NoNumber:
                                s = s00;
                                s = s00;
                          case STRTOG_Zero:
                          case STRTOG_Zero:
                                break;
                                break;
                          default:
                          default:
                                if (bb) {
                                if (bb) {
                                        copybits(bits, fpi.nbits, bb);
                                        copybits(bits, fpi.nbits, bb);
                                        Bfree(ptr,bb);
                                        Bfree(ptr,bb);
                                        }
                                        }
                                ULtod(rv.i, bits, exp, i);
                                ULtod(rv.i, bits, exp, i);
                          }}
                          }}
                        goto ret;
                        goto ret;
                  }
                  }
                }
                }
#endif
#endif
                nz0 = 1;
                nz0 = 1;
                while(*++s == '0') ;
                while(*++s == '0') ;
                if (!*s)
                if (!*s)
                        goto ret;
                        goto ret;
                }
                }
        s0 = s;
        s0 = s;
        y = z = 0;
        y = z = 0;
        for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
        for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
                if (nd < 9)
                if (nd < 9)
                        y = 10*y + c - '0';
                        y = 10*y + c - '0';
                else if (nd < 16)
                else if (nd < 16)
                        z = 10*z + c - '0';
                        z = 10*z + c - '0';
        nd0 = nd;
        nd0 = nd;
        if (strncmp (s, _localeconv_r (ptr)->decimal_point,
        if (strncmp (s, _localeconv_r (ptr)->decimal_point,
                     strlen (_localeconv_r (ptr)->decimal_point)) == 0)
                     strlen (_localeconv_r (ptr)->decimal_point)) == 0)
                {
                {
                decpt = 1;
                decpt = 1;
                c = *(s += strlen (_localeconv_r (ptr)->decimal_point));
                c = *(s += strlen (_localeconv_r (ptr)->decimal_point));
                if (!nd) {
                if (!nd) {
                        for(; c == '0'; c = *++s)
                        for(; c == '0'; c = *++s)
                                nz++;
                                nz++;
                        if (c > '0' && c <= '9') {
                        if (c > '0' && c <= '9') {
                                s0 = s;
                                s0 = s;
                                nf += nz;
                                nf += nz;
                                nz = 0;
                                nz = 0;
                                goto have_dig;
                                goto have_dig;
                                }
                                }
                        goto dig_done;
                        goto dig_done;
                        }
                        }
                for(; c >= '0' && c <= '9'; c = *++s) {
                for(; c >= '0' && c <= '9'; c = *++s) {
 have_dig:
 have_dig:
                        nz++;
                        nz++;
                        if (c -= '0') {
                        if (c -= '0') {
                                nf += nz;
                                nf += nz;
                                for(i = 1; i < nz; i++)
                                for(i = 1; i < nz; i++)
                                        if (nd++ < 9)
                                        if (nd++ < 9)
                                                y *= 10;
                                                y *= 10;
                                        else if (nd <= DBL_DIG + 1)
                                        else if (nd <= DBL_DIG + 1)
                                                z *= 10;
                                                z *= 10;
                                if (nd++ < 9)
                                if (nd++ < 9)
                                        y = 10*y + c;
                                        y = 10*y + c;
                                else if (nd <= DBL_DIG + 1)
                                else if (nd <= DBL_DIG + 1)
                                        z = 10*z + c;
                                        z = 10*z + c;
                                nz = 0;
                                nz = 0;
                                }
                                }
                        }
                        }
                }
                }
 dig_done:
 dig_done:
        e = 0;
        e = 0;
        if (c == 'e' || c == 'E') {
        if (c == 'e' || c == 'E') {
                if (!nd && !nz && !nz0) {
                if (!nd && !nz && !nz0) {
                        goto ret0;
                        goto ret0;
                        }
                        }
                s00 = s;
                s00 = s;
                esign = 0;
                esign = 0;
                switch(c = *++s) {
                switch(c = *++s) {
                        case '-':
                        case '-':
                                esign = 1;
                                esign = 1;
                        case '+':
                        case '+':
                                c = *++s;
                                c = *++s;
                        }
                        }
                if (c >= '0' && c <= '9') {
                if (c >= '0' && c <= '9') {
                        while(c == '0')
                        while(c == '0')
                                c = *++s;
                                c = *++s;
                        if (c > '0' && c <= '9') {
                        if (c > '0' && c <= '9') {
                                L = c - '0';
                                L = c - '0';
                                s1 = s;
                                s1 = s;
                                while((c = *++s) >= '0' && c <= '9')
                                while((c = *++s) >= '0' && c <= '9')
                                        L = 10*L + c - '0';
                                        L = 10*L + c - '0';
                                if (s - s1 > 8 || L > 19999)
                                if (s - s1 > 8 || L > 19999)
                                        /* Avoid confusion from exponents
                                        /* Avoid confusion from exponents
                                         * so large that e might overflow.
                                         * so large that e might overflow.
                                         */
                                         */
                                        e = 19999; /* safe for 16 bit ints */
                                        e = 19999; /* safe for 16 bit ints */
                                else
                                else
                                        e = (int)L;
                                        e = (int)L;
                                if (esign)
                                if (esign)
                                        e = -e;
                                        e = -e;
                                }
                                }
                        else
                        else
                                e = 0;
                                e = 0;
                        }
                        }
                else
                else
                        s = s00;
                        s = s00;
                }
                }
        if (!nd) {
        if (!nd) {
                if (!nz && !nz0) {
                if (!nz && !nz0) {
#ifdef INFNAN_CHECK
#ifdef INFNAN_CHECK
                        /* Check for Nan and Infinity */
                        /* Check for Nan and Infinity */
                        __ULong bits[2];
                        __ULong bits[2];
                        static FPI fpinan =     /* only 52 explicit bits */
                        static FPI fpinan =     /* only 52 explicit bits */
                                { 52, 1-1023-53+1, 2046-1023-53+1, 1, SI };
                                { 52, 1-1023-53+1, 2046-1023-53+1, 1, SI };
                        if (!decpt)
                        if (!decpt)
                         switch(c) {
                         switch(c) {
                          case 'i':
                          case 'i':
                          case 'I':
                          case 'I':
                                if (match(&s,"nf")) {
                                if (match(&s,"nf")) {
                                        --s;
                                        --s;
                                        if (!match(&s,"inity"))
                                        if (!match(&s,"inity"))
                                                ++s;
                                                ++s;
                                        dword0(rv) = 0x7ff00000;
                                        dword0(rv) = 0x7ff00000;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                        dword1(rv) = 0;
                                        dword1(rv) = 0;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                                        goto ret;
                                        goto ret;
                                        }
                                        }
                                break;
                                break;
                          case 'n':
                          case 'n':
                          case 'N':
                          case 'N':
                                if (match(&s, "an")) {
                                if (match(&s, "an")) {
#ifndef No_Hex_NaN
#ifndef No_Hex_NaN
                                        if (*s == '(' /*)*/
                                        if (*s == '(' /*)*/
                                         && hexnan(&s, &fpinan, bits)
                                         && hexnan(&s, &fpinan, bits)
                                                        == STRTOG_NaNbits) {
                                                        == STRTOG_NaNbits) {
                                                dword0(rv) = 0x7ff00000 | bits[1];
                                                dword0(rv) = 0x7ff00000 | bits[1];
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                                dword1(rv) = bits[0];
                                                dword1(rv) = bits[0];
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                                                }
                                                }
                                        else {
                                        else {
#endif
#endif
                                                dword0(rv) = NAN_WORD0;
                                                dword0(rv) = NAN_WORD0;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                                dword1(rv) = NAN_WORD1;
                                                dword1(rv) = NAN_WORD1;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
#ifndef No_Hex_NaN
#ifndef No_Hex_NaN
                                                }
                                                }
#endif
#endif
                                        goto ret;
                                        goto ret;
                                        }
                                        }
                          }
                          }
#endif /* INFNAN_CHECK */
#endif /* INFNAN_CHECK */
 ret0:
 ret0:
                        s = s00;
                        s = s00;
                        sign = 0;
                        sign = 0;
                        }
                        }
                goto ret;
                goto ret;
                }
                }
        e1 = e -= nf;
        e1 = e -= nf;
 
 
        /* Now we have nd0 digits, starting at s0, followed by a
        /* Now we have nd0 digits, starting at s0, followed by a
         * decimal point, followed by nd-nd0 digits.  The number we're
         * decimal point, followed by nd-nd0 digits.  The number we're
         * after is the integer represented by those digits times
         * after is the integer represented by those digits times
         * 10**e */
         * 10**e */
 
 
        if (!nd0)
        if (!nd0)
                nd0 = nd;
                nd0 = nd;
        k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
        k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
        dval(rv) = y;
        dval(rv) = y;
        if (k > 9) {
        if (k > 9) {
#ifdef SET_INEXACT
#ifdef SET_INEXACT
                if (k > DBL_DIG)
                if (k > DBL_DIG)
                        oldinexact = get_inexact();
                        oldinexact = get_inexact();
#endif
#endif
                dval(rv) = tens[k - 9] * dval(rv) + z;
                dval(rv) = tens[k - 9] * dval(rv) + z;
                }
                }
        bd0 = 0;
        bd0 = 0;
        if (nd <= DBL_DIG
        if (nd <= DBL_DIG
#ifndef RND_PRODQUOT
#ifndef RND_PRODQUOT
#ifndef Honor_FLT_ROUNDS
#ifndef Honor_FLT_ROUNDS
                && Flt_Rounds == 1
                && Flt_Rounds == 1
#endif
#endif
#endif
#endif
                        ) {
                        ) {
                if (!e)
                if (!e)
                        goto ret;
                        goto ret;
                if (e > 0) {
                if (e > 0) {
                        if (e <= Ten_pmax) {
                        if (e <= Ten_pmax) {
#ifdef VAX
#ifdef VAX
                                goto vax_ovfl_check;
                                goto vax_ovfl_check;
#else
#else
#ifdef Honor_FLT_ROUNDS
#ifdef Honor_FLT_ROUNDS
                                /* round correctly FLT_ROUNDS = 2 or 3 */
                                /* round correctly FLT_ROUNDS = 2 or 3 */
                                if (sign) {
                                if (sign) {
                                        dval(rv) = -dval(rv);
                                        dval(rv) = -dval(rv);
                                        sign = 0;
                                        sign = 0;
                                        }
                                        }
#endif
#endif
                                /* rv = */ rounded_product(dval(rv), tens[e]);
                                /* rv = */ rounded_product(dval(rv), tens[e]);
                                goto ret;
                                goto ret;
#endif
#endif
                                }
                                }
                        i = DBL_DIG - nd;
                        i = DBL_DIG - nd;
                        if (e <= Ten_pmax + i) {
                        if (e <= Ten_pmax + i) {
                                /* A fancier test would sometimes let us do
                                /* A fancier test would sometimes let us do
                                 * this for larger i values.
                                 * this for larger i values.
                                 */
                                 */
#ifdef Honor_FLT_ROUNDS
#ifdef Honor_FLT_ROUNDS
                                /* round correctly FLT_ROUNDS = 2 or 3 */
                                /* round correctly FLT_ROUNDS = 2 or 3 */
                                if (sign) {
                                if (sign) {
                                        dval(rv) = -dval(rv);
                                        dval(rv) = -dval(rv);
                                        sign = 0;
                                        sign = 0;
                                        }
                                        }
#endif
#endif
                                e -= i;
                                e -= i;
                                dval(rv) *= tens[i];
                                dval(rv) *= tens[i];
#ifdef VAX
#ifdef VAX
                                /* VAX exponent range is so narrow we must
                                /* VAX exponent range is so narrow we must
                                 * worry about overflow here...
                                 * worry about overflow here...
                                 */
                                 */
 vax_ovfl_check:
 vax_ovfl_check:
                                dword0(rv) -= P*Exp_msk1;
                                dword0(rv) -= P*Exp_msk1;
                                /* rv = */ rounded_product(dval(rv), tens[e]);
                                /* rv = */ rounded_product(dval(rv), tens[e]);
                                if ((dword0(rv) & Exp_mask)
                                if ((dword0(rv) & Exp_mask)
                                 > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
                                 > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
                                        goto ovfl;
                                        goto ovfl;
                                dword0(rv) += P*Exp_msk1;
                                dword0(rv) += P*Exp_msk1;
#else
#else
                                /* rv = */ rounded_product(dval(rv), tens[e]);
                                /* rv = */ rounded_product(dval(rv), tens[e]);
#endif
#endif
                                goto ret;
                                goto ret;
                                }
                                }
                        }
                        }
#ifndef Inaccurate_Divide
#ifndef Inaccurate_Divide
                else if (e >= -Ten_pmax) {
                else if (e >= -Ten_pmax) {
#ifdef Honor_FLT_ROUNDS
#ifdef Honor_FLT_ROUNDS
                        /* round correctly FLT_ROUNDS = 2 or 3 */
                        /* round correctly FLT_ROUNDS = 2 or 3 */
                        if (sign) {
                        if (sign) {
                                dval(rv) = -dval(rv);
                                dval(rv) = -dval(rv);
                                sign = 0;
                                sign = 0;
                                }
                                }
#endif
#endif
                        /* rv = */ rounded_quotient(dval(rv), tens[-e]);
                        /* rv = */ rounded_quotient(dval(rv), tens[-e]);
                        goto ret;
                        goto ret;
                        }
                        }
#endif
#endif
                }
                }
        e1 += nd - k;
        e1 += nd - k;
 
 
#ifdef IEEE_Arith
#ifdef IEEE_Arith
#ifdef SET_INEXACT
#ifdef SET_INEXACT
        inexact = 1;
        inexact = 1;
        if (k <= DBL_DIG)
        if (k <= DBL_DIG)
                oldinexact = get_inexact();
                oldinexact = get_inexact();
#endif
#endif
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
        scale = 0;
        scale = 0;
#endif
#endif
#ifdef Honor_FLT_ROUNDS
#ifdef Honor_FLT_ROUNDS
        if ((rounding = Flt_Rounds) >= 2) {
        if ((rounding = Flt_Rounds) >= 2) {
                if (sign)
                if (sign)
                        rounding = rounding == 2 ? 0 : 2;
                        rounding = rounding == 2 ? 0 : 2;
                else
                else
                        if (rounding != 2)
                        if (rounding != 2)
                                rounding = 0;
                                rounding = 0;
                }
                }
#endif
#endif
#endif /*IEEE_Arith*/
#endif /*IEEE_Arith*/
 
 
        /* Get starting approximation = rv * 10**e1 */
        /* Get starting approximation = rv * 10**e1 */
 
 
        if (e1 > 0) {
        if (e1 > 0) {
                if ( (i = e1 & 15) !=0)
                if ( (i = e1 & 15) !=0)
                        dval(rv) *= tens[i];
                        dval(rv) *= tens[i];
                if (e1 &= ~15) {
                if (e1 &= ~15) {
                        if (e1 > DBL_MAX_10_EXP) {
                        if (e1 > DBL_MAX_10_EXP) {
 ovfl:
 ovfl:
#ifndef NO_ERRNO
#ifndef NO_ERRNO
                                ptr->_errno = ERANGE;
                                ptr->_errno = ERANGE;
#endif
#endif
                                /* Can't trust HUGE_VAL */
                                /* Can't trust HUGE_VAL */
#ifdef IEEE_Arith
#ifdef IEEE_Arith
#ifdef Honor_FLT_ROUNDS
#ifdef Honor_FLT_ROUNDS
                                switch(rounding) {
                                switch(rounding) {
                                  case 0: /* toward 0 */
                                  case 0: /* toward 0 */
                                  case 3: /* toward -infinity */
                                  case 3: /* toward -infinity */
                                        dword0(rv) = Big0;
                                        dword0(rv) = Big0;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                        dword1(rv) = Big1;
                                        dword1(rv) = Big1;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                                        break;
                                        break;
                                  default:
                                  default:
                                        dword0(rv) = Exp_mask;
                                        dword0(rv) = Exp_mask;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                        dword1(rv) = 0;
                                        dword1(rv) = 0;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                                  }
                                  }
#else /*Honor_FLT_ROUNDS*/
#else /*Honor_FLT_ROUNDS*/
                                dword0(rv) = Exp_mask;
                                dword0(rv) = Exp_mask;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                dword1(rv) = 0;
                                dword1(rv) = 0;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*Honor_FLT_ROUNDS*/
#endif /*Honor_FLT_ROUNDS*/
#ifdef SET_INEXACT
#ifdef SET_INEXACT
                                /* set overflow bit */
                                /* set overflow bit */
                                dval(rv0) = 1e300;
                                dval(rv0) = 1e300;
                                dval(rv0) *= dval(rv0);
                                dval(rv0) *= dval(rv0);
#endif
#endif
#else /*IEEE_Arith*/
#else /*IEEE_Arith*/
                                dword0(rv) = Big0;
                                dword0(rv) = Big0;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                dword1(rv) = Big1;
                                dword1(rv) = Big1;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*IEEE_Arith*/
#endif /*IEEE_Arith*/
                                if (bd0)
                                if (bd0)
                                        goto retfree;
                                        goto retfree;
                                goto ret;
                                goto ret;
                                }
                                }
                        e1 >>= 4;
                        e1 >>= 4;
                        for(j = 0; e1 > 1; j++, e1 >>= 1)
                        for(j = 0; e1 > 1; j++, e1 >>= 1)
                                if (e1 & 1)
                                if (e1 & 1)
                                        dval(rv) *= bigtens[j];
                                        dval(rv) *= bigtens[j];
                /* The last multiplication could overflow. */
                /* The last multiplication could overflow. */
                        dword0(rv) -= P*Exp_msk1;
                        dword0(rv) -= P*Exp_msk1;
                        dval(rv) *= bigtens[j];
                        dval(rv) *= bigtens[j];
                        if ((z = dword0(rv) & Exp_mask)
                        if ((z = dword0(rv) & Exp_mask)
                         > Exp_msk1*(DBL_MAX_EXP+Bias-P))
                         > Exp_msk1*(DBL_MAX_EXP+Bias-P))
                                goto ovfl;
                                goto ovfl;
                        if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
                        if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
                                /* set to largest number */
                                /* set to largest number */
                                /* (Can't trust DBL_MAX) */
                                /* (Can't trust DBL_MAX) */
                                dword0(rv) = Big0;
                                dword0(rv) = Big0;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                dword1(rv) = Big1;
                                dword1(rv) = Big1;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                                }
                                }
                        else
                        else
                                dword0(rv) += P*Exp_msk1;
                                dword0(rv) += P*Exp_msk1;
                        }
                        }
                }
                }
        else if (e1 < 0) {
        else if (e1 < 0) {
                e1 = -e1;
                e1 = -e1;
                if ( (i = e1 & 15) !=0)
                if ( (i = e1 & 15) !=0)
                        dval(rv) /= tens[i];
                        dval(rv) /= tens[i];
                if (e1 >>= 4) {
                if (e1 >>= 4) {
                        if (e1 >= 1 << n_bigtens)
                        if (e1 >= 1 << n_bigtens)
                                goto undfl;
                                goto undfl;
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                        if (e1 & Scale_Bit)
                        if (e1 & Scale_Bit)
                                scale = 2*P;
                                scale = 2*P;
                        for(j = 0; e1 > 0; j++, e1 >>= 1)
                        for(j = 0; e1 > 0; j++, e1 >>= 1)
                                if (e1 & 1)
                                if (e1 & 1)
                                        dval(rv) *= tinytens[j];
                                        dval(rv) *= tinytens[j];
                        if (scale && (j = 2*P + 1 - ((dword0(rv) & Exp_mask)
                        if (scale && (j = 2*P + 1 - ((dword0(rv) & Exp_mask)
                                                >> Exp_shift)) > 0) {
                                                >> Exp_shift)) > 0) {
                                /* scaled rv is denormal; zap j low bits */
                                /* scaled rv is denormal; zap j low bits */
                                if (j >= 32) {
                                if (j >= 32) {
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                        dword1(rv) = 0;
                                        dword1(rv) = 0;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                                        if (j >= 53)
                                        if (j >= 53)
                                         dword0(rv) = (P+2)*Exp_msk1;
                                         dword0(rv) = (P+2)*Exp_msk1;
                                        else
                                        else
                                         dword0(rv) &= 0xffffffff << (j-32);
                                         dword0(rv) &= 0xffffffff << (j-32);
                                        }
                                        }
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                else
                                else
                                        dword1(rv) &= 0xffffffff << j;
                                        dword1(rv) &= 0xffffffff << j;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                                }
                                }
#else
#else
                        for(j = 0; e1 > 1; j++, e1 >>= 1)
                        for(j = 0; e1 > 1; j++, e1 >>= 1)
                                if (e1 & 1)
                                if (e1 & 1)
                                        dval(rv) *= tinytens[j];
                                        dval(rv) *= tinytens[j];
                        /* The last multiplication could underflow. */
                        /* The last multiplication could underflow. */
                        dval(rv0) = dval(rv);
                        dval(rv0) = dval(rv);
                        dval(rv) *= tinytens[j];
                        dval(rv) *= tinytens[j];
                        if (!dval(rv)) {
                        if (!dval(rv)) {
                                dval(rv) = 2.*dval(rv0);
                                dval(rv) = 2.*dval(rv0);
                                dval(rv) *= tinytens[j];
                                dval(rv) *= tinytens[j];
#endif
#endif
                                if (!dval(rv)) {
                                if (!dval(rv)) {
 undfl:
 undfl:
                                        dval(rv) = 0.;
                                        dval(rv) = 0.;
#ifndef NO_ERRNO
#ifndef NO_ERRNO
                                        ptr->_errno = ERANGE;
                                        ptr->_errno = ERANGE;
#endif
#endif
                                        if (bd0)
                                        if (bd0)
                                                goto retfree;
                                                goto retfree;
                                        goto ret;
                                        goto ret;
                                        }
                                        }
#ifndef Avoid_Underflow
#ifndef Avoid_Underflow
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                dword0(rv) = Tiny0;
                                dword0(rv) = Tiny0;
                                dword1(rv) = Tiny1;
                                dword1(rv) = Tiny1;
#else
#else
                                dword0(rv) = Tiny1;
                                dword0(rv) = Tiny1;
#endif /*_DOUBLE_IS_32BITS*/
#endif /*_DOUBLE_IS_32BITS*/
                                /* The refinement below will clean
                                /* The refinement below will clean
                                 * this approximation up.
                                 * this approximation up.
                                 */
                                 */
                                }
                                }
#endif
#endif
                        }
                        }
                }
                }
 
 
        /* Now the hard part -- adjusting rv to the correct value.*/
        /* Now the hard part -- adjusting rv to the correct value.*/
 
 
        /* Put digits into bd: true value = bd * 10^e */
        /* Put digits into bd: true value = bd * 10^e */
 
 
        bd0 = s2b(ptr, s0, nd0, nd, y);
        bd0 = s2b(ptr, s0, nd0, nd, y);
 
 
        for(;;) {
        for(;;) {
                bd = Balloc(ptr,bd0->_k);
                bd = Balloc(ptr,bd0->_k);
                Bcopy(bd, bd0);
                Bcopy(bd, bd0);
                bb = d2b(ptr,dval(rv), &bbe, &bbbits);  /* rv = bb * 2^bbe */
                bb = d2b(ptr,dval(rv), &bbe, &bbbits);  /* rv = bb * 2^bbe */
                bs = i2b(ptr,1);
                bs = i2b(ptr,1);
 
 
                if (e >= 0) {
                if (e >= 0) {
                        bb2 = bb5 = 0;
                        bb2 = bb5 = 0;
                        bd2 = bd5 = e;
                        bd2 = bd5 = e;
                        }
                        }
                else {
                else {
                        bb2 = bb5 = -e;
                        bb2 = bb5 = -e;
                        bd2 = bd5 = 0;
                        bd2 = bd5 = 0;
                        }
                        }
                if (bbe >= 0)
                if (bbe >= 0)
                        bb2 += bbe;
                        bb2 += bbe;
                else
                else
                        bd2 -= bbe;
                        bd2 -= bbe;
                bs2 = bb2;
                bs2 = bb2;
#ifdef Honor_FLT_ROUNDS
#ifdef Honor_FLT_ROUNDS
                if (rounding != 1)
                if (rounding != 1)
                        bs2++;
                        bs2++;
#endif
#endif
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                j = bbe - scale;
                j = bbe - scale;
                i = j + bbbits - 1;     /* logb(rv) */
                i = j + bbbits - 1;     /* logb(rv) */
                if (i < Emin)   /* denormal */
                if (i < Emin)   /* denormal */
                        j += P - Emin;
                        j += P - Emin;
                else
                else
                        j = P + 1 - bbbits;
                        j = P + 1 - bbbits;
#else /*Avoid_Underflow*/
#else /*Avoid_Underflow*/
#ifdef Sudden_Underflow
#ifdef Sudden_Underflow
#ifdef IBM
#ifdef IBM
                j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
                j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
#else
#else
                j = P + 1 - bbbits;
                j = P + 1 - bbbits;
#endif
#endif
#else /*Sudden_Underflow*/
#else /*Sudden_Underflow*/
                j = bbe;
                j = bbe;
                i = j + bbbits - 1;     /* logb(rv) */
                i = j + bbbits - 1;     /* logb(rv) */
                if (i < Emin)   /* denormal */
                if (i < Emin)   /* denormal */
                        j += P - Emin;
                        j += P - Emin;
                else
                else
                        j = P + 1 - bbbits;
                        j = P + 1 - bbbits;
#endif /*Sudden_Underflow*/
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
#endif /*Avoid_Underflow*/
                bb2 += j;
                bb2 += j;
                bd2 += j;
                bd2 += j;
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                bd2 += scale;
                bd2 += scale;
#endif
#endif
                i = bb2 < bd2 ? bb2 : bd2;
                i = bb2 < bd2 ? bb2 : bd2;
                if (i > bs2)
                if (i > bs2)
                        i = bs2;
                        i = bs2;
                if (i > 0) {
                if (i > 0) {
                        bb2 -= i;
                        bb2 -= i;
                        bd2 -= i;
                        bd2 -= i;
                        bs2 -= i;
                        bs2 -= i;
                        }
                        }
                if (bb5 > 0) {
                if (bb5 > 0) {
                        bs = pow5mult(ptr, bs, bb5);
                        bs = pow5mult(ptr, bs, bb5);
                        bb1 = mult(ptr, bs, bb);
                        bb1 = mult(ptr, bs, bb);
                        Bfree(ptr, bb);
                        Bfree(ptr, bb);
                        bb = bb1;
                        bb = bb1;
                        }
                        }
                if (bb2 > 0)
                if (bb2 > 0)
                        bb = lshift(ptr, bb, bb2);
                        bb = lshift(ptr, bb, bb2);
                if (bd5 > 0)
                if (bd5 > 0)
                        bd = pow5mult(ptr, bd, bd5);
                        bd = pow5mult(ptr, bd, bd5);
                if (bd2 > 0)
                if (bd2 > 0)
                        bd = lshift(ptr, bd, bd2);
                        bd = lshift(ptr, bd, bd2);
                if (bs2 > 0)
                if (bs2 > 0)
                        bs = lshift(ptr, bs, bs2);
                        bs = lshift(ptr, bs, bs2);
                delta = diff(ptr, bb, bd);
                delta = diff(ptr, bb, bd);
                dsign = delta->_sign;
                dsign = delta->_sign;
                delta->_sign = 0;
                delta->_sign = 0;
                i = cmp(delta, bs);
                i = cmp(delta, bs);
#ifdef Honor_FLT_ROUNDS
#ifdef Honor_FLT_ROUNDS
                if (rounding != 1) {
                if (rounding != 1) {
                        if (i < 0) {
                        if (i < 0) {
                                /* Error is less than an ulp */
                                /* Error is less than an ulp */
                                if (!delta->_x[0] && delta->_wds <= 1) {
                                if (!delta->_x[0] && delta->_wds <= 1) {
                                        /* exact */
                                        /* exact */
#ifdef SET_INEXACT
#ifdef SET_INEXACT
                                        inexact = 0;
                                        inexact = 0;
#endif
#endif
                                        break;
                                        break;
                                        }
                                        }
                                if (rounding) {
                                if (rounding) {
                                        if (dsign) {
                                        if (dsign) {
                                                adj = 1.;
                                                adj = 1.;
                                                goto apply_adj;
                                                goto apply_adj;
                                                }
                                                }
                                        }
                                        }
                                else if (!dsign) {
                                else if (!dsign) {
                                        adj = -1.;
                                        adj = -1.;
                                        if (!dword1(rv)
                                        if (!dword1(rv)
                                         && !(dword0(rv) & Frac_mask)) {
                                         && !(dword0(rv) & Frac_mask)) {
                                                y = dword0(rv) & Exp_mask;
                                                y = dword0(rv) & Exp_mask;
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                                                if (!scale || y > 2*P*Exp_msk1)
                                                if (!scale || y > 2*P*Exp_msk1)
#else
#else
                                                if (y)
                                                if (y)
#endif
#endif
                                                  {
                                                  {
                                                  delta = lshift(ptr, delta,Log2P);
                                                  delta = lshift(ptr, delta,Log2P);
                                                  if (cmp(delta, bs) <= 0)
                                                  if (cmp(delta, bs) <= 0)
                                                        adj = -0.5;
                                                        adj = -0.5;
                                                  }
                                                  }
                                                }
                                                }
 apply_adj:
 apply_adj:
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                                        if (scale && (y = dword0(rv) & Exp_mask)
                                        if (scale && (y = dword0(rv) & Exp_mask)
                                                <= 2*P*Exp_msk1)
                                                <= 2*P*Exp_msk1)
                                          dword0(adj) += (2*P+1)*Exp_msk1 - y;
                                          dword0(adj) += (2*P+1)*Exp_msk1 - y;
#else
#else
#ifdef Sudden_Underflow
#ifdef Sudden_Underflow
                                        if ((dword0(rv) & Exp_mask) <=
                                        if ((dword0(rv) & Exp_mask) <=
                                                        P*Exp_msk1) {
                                                        P*Exp_msk1) {
                                                dword0(rv) += P*Exp_msk1;
                                                dword0(rv) += P*Exp_msk1;
                                                dval(rv) += adj*ulp(dval(rv));
                                                dval(rv) += adj*ulp(dval(rv));
                                                dword0(rv) -= P*Exp_msk1;
                                                dword0(rv) -= P*Exp_msk1;
                                                }
                                                }
                                        else
                                        else
#endif /*Sudden_Underflow*/
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
#endif /*Avoid_Underflow*/
                                        dval(rv) += adj*ulp(dval(rv));
                                        dval(rv) += adj*ulp(dval(rv));
                                        }
                                        }
                                break;
                                break;
                                }
                                }
                        adj = ratio(delta, bs);
                        adj = ratio(delta, bs);
                        if (adj < 1.)
                        if (adj < 1.)
                                adj = 1.;
                                adj = 1.;
                        if (adj <= 0x7ffffffe) {
                        if (adj <= 0x7ffffffe) {
                                /* adj = rounding ? ceil(adj) : floor(adj); */
                                /* adj = rounding ? ceil(adj) : floor(adj); */
                                y = adj;
                                y = adj;
                                if (y != adj) {
                                if (y != adj) {
                                        if (!((rounding>>1) ^ dsign))
                                        if (!((rounding>>1) ^ dsign))
                                                y++;
                                                y++;
                                        adj = y;
                                        adj = y;
                                        }
                                        }
                                }
                                }
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                        if (scale && (y = dword0(rv) & Exp_mask) <= 2*P*Exp_msk1)
                        if (scale && (y = dword0(rv) & Exp_mask) <= 2*P*Exp_msk1)
                                dword0(adj) += (2*P+1)*Exp_msk1 - y;
                                dword0(adj) += (2*P+1)*Exp_msk1 - y;
#else
#else
#ifdef Sudden_Underflow
#ifdef Sudden_Underflow
                        if ((dword0(rv) & Exp_mask) <= P*Exp_msk1) {
                        if ((dword0(rv) & Exp_mask) <= P*Exp_msk1) {
                                dword0(rv) += P*Exp_msk1;
                                dword0(rv) += P*Exp_msk1;
                                adj *= ulp(dval(rv));
                                adj *= ulp(dval(rv));
                                if (dsign)
                                if (dsign)
                                        dval(rv) += adj;
                                        dval(rv) += adj;
                                else
                                else
                                        dval(rv) -= adj;
                                        dval(rv) -= adj;
                                dword0(rv) -= P*Exp_msk1;
                                dword0(rv) -= P*Exp_msk1;
                                goto cont;
                                goto cont;
                                }
                                }
#endif /*Sudden_Underflow*/
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
#endif /*Avoid_Underflow*/
                        adj *= ulp(dval(rv));
                        adj *= ulp(dval(rv));
                        if (dsign)
                        if (dsign)
                                dval(rv) += adj;
                                dval(rv) += adj;
                        else
                        else
                                dval(rv) -= adj;
                                dval(rv) -= adj;
                        goto cont;
                        goto cont;
                        }
                        }
#endif /*Honor_FLT_ROUNDS*/
#endif /*Honor_FLT_ROUNDS*/
 
 
                if (i < 0) {
                if (i < 0) {
                        /* Error is less than half an ulp -- check for
                        /* Error is less than half an ulp -- check for
                         * special case of mantissa a power of two.
                         * special case of mantissa a power of two.
                         */
                         */
                        if (dsign || dword1(rv) || dword0(rv) & Bndry_mask
                        if (dsign || dword1(rv) || dword0(rv) & Bndry_mask
#ifdef IEEE_Arith
#ifdef IEEE_Arith
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                         || (dword0(rv) & Exp_mask) <= (2*P+1)*Exp_msk1
                         || (dword0(rv) & Exp_mask) <= (2*P+1)*Exp_msk1
#else
#else
                         || (dword0(rv) & Exp_mask) <= Exp_msk1
                         || (dword0(rv) & Exp_mask) <= Exp_msk1
#endif
#endif
#endif
#endif
                                ) {
                                ) {
#ifdef SET_INEXACT
#ifdef SET_INEXACT
                                if (!delta->x[0] && delta->wds <= 1)
                                if (!delta->x[0] && delta->wds <= 1)
                                        inexact = 0;
                                        inexact = 0;
#endif
#endif
                                break;
                                break;
                                }
                                }
                        if (!delta->_x[0] && delta->_wds <= 1) {
                        if (!delta->_x[0] && delta->_wds <= 1) {
                                /* exact result */
                                /* exact result */
#ifdef SET_INEXACT
#ifdef SET_INEXACT
                                inexact = 0;
                                inexact = 0;
#endif
#endif
                                break;
                                break;
                                }
                                }
                        delta = lshift(ptr,delta,Log2P);
                        delta = lshift(ptr,delta,Log2P);
                        if (cmp(delta, bs) > 0)
                        if (cmp(delta, bs) > 0)
                                goto drop_down;
                                goto drop_down;
                        break;
                        break;
                        }
                        }
                if (i == 0) {
                if (i == 0) {
                        /* exactly half-way between */
                        /* exactly half-way between */
                        if (dsign) {
                        if (dsign) {
                                if ((dword0(rv) & Bndry_mask1) == Bndry_mask1
                                if ((dword0(rv) & Bndry_mask1) == Bndry_mask1
                                 &&  dword1(rv) == (
                                 &&  dword1(rv) == (
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                        (scale && (y = dword0(rv) & Exp_mask) <= 2*P*Exp_msk1)
                        (scale && (y = dword0(rv) & Exp_mask) <= 2*P*Exp_msk1)
                ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :
                ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :
#endif
#endif
                                                   0xffffffff)) {
                                                   0xffffffff)) {
                                        /*boundary case -- increment exponent*/
                                        /*boundary case -- increment exponent*/
                                        dword0(rv) = (dword0(rv) & Exp_mask)
                                        dword0(rv) = (dword0(rv) & Exp_mask)
                                                + Exp_msk1
                                                + Exp_msk1
#ifdef IBM
#ifdef IBM
                                                | Exp_msk1 >> 4
                                                | Exp_msk1 >> 4
#endif
#endif
                                                ;
                                                ;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                        dword1(rv) = 0;
                                        dword1(rv) = 0;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                                        dsign = 0;
                                        dsign = 0;
#endif
#endif
                                        break;
                                        break;
                                        }
                                        }
                                }
                                }
                        else if (!(dword0(rv) & Bndry_mask) && !dword1(rv)) {
                        else if (!(dword0(rv) & Bndry_mask) && !dword1(rv)) {
 drop_down:
 drop_down:
                                /* boundary case -- decrement exponent */
                                /* boundary case -- decrement exponent */
#ifdef Sudden_Underflow /*{{*/
#ifdef Sudden_Underflow /*{{*/
                                L = dword0(rv) & Exp_mask;
                                L = dword0(rv) & Exp_mask;
#ifdef IBM
#ifdef IBM
                                if (L <  Exp_msk1)
                                if (L <  Exp_msk1)
#else
#else
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                                if (L <= (scale ? (2*P+1)*Exp_msk1 : Exp_msk1))
                                if (L <= (scale ? (2*P+1)*Exp_msk1 : Exp_msk1))
#else
#else
                                if (L <= Exp_msk1)
                                if (L <= Exp_msk1)
#endif /*Avoid_Underflow*/
#endif /*Avoid_Underflow*/
#endif /*IBM*/
#endif /*IBM*/
                                        goto undfl;
                                        goto undfl;
                                L -= Exp_msk1;
                                L -= Exp_msk1;
#else /*Sudden_Underflow}{*/
#else /*Sudden_Underflow}{*/
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                                if (scale) {
                                if (scale) {
                                        L = dword0(rv) & Exp_mask;
                                        L = dword0(rv) & Exp_mask;
                                        if (L <= (2*P+1)*Exp_msk1) {
                                        if (L <= (2*P+1)*Exp_msk1) {
                                                if (L > (P+2)*Exp_msk1)
                                                if (L > (P+2)*Exp_msk1)
                                                        /* round even ==> */
                                                        /* round even ==> */
                                                        /* accept rv */
                                                        /* accept rv */
                                                        break;
                                                        break;
                                                /* rv = smallest denormal */
                                                /* rv = smallest denormal */
                                                goto undfl;
                                                goto undfl;
                                                }
                                                }
                                        }
                                        }
#endif /*Avoid_Underflow*/
#endif /*Avoid_Underflow*/
                                L = (dword0(rv) & Exp_mask) - Exp_msk1;
                                L = (dword0(rv) & Exp_mask) - Exp_msk1;
#endif /*Sudden_Underflow}*/
#endif /*Sudden_Underflow}*/
                                dword0(rv) = L | Bndry_mask1;
                                dword0(rv) = L | Bndry_mask1;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                dword1(rv) = 0xffffffff;
                                dword1(rv) = 0xffffffff;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
#ifdef IBM
#ifdef IBM
                                goto cont;
                                goto cont;
#else
#else
                                break;
                                break;
#endif
#endif
                                }
                                }
#ifndef ROUND_BIASED
#ifndef ROUND_BIASED
                        if (!(dword1(rv) & LSB))
                        if (!(dword1(rv) & LSB))
                                break;
                                break;
#endif
#endif
                        if (dsign)
                        if (dsign)
                                dval(rv) += ulp(dval(rv));
                                dval(rv) += ulp(dval(rv));
#ifndef ROUND_BIASED
#ifndef ROUND_BIASED
                        else {
                        else {
                                dval(rv) -= ulp(dval(rv));
                                dval(rv) -= ulp(dval(rv));
#ifndef Sudden_Underflow
#ifndef Sudden_Underflow
                                if (!dval(rv))
                                if (!dval(rv))
                                        goto undfl;
                                        goto undfl;
#endif
#endif
                                }
                                }
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                        dsign = 1 - dsign;
                        dsign = 1 - dsign;
#endif
#endif
#endif
#endif
                        break;
                        break;
                        }
                        }
                if ((aadj = ratio(delta, bs)) <= 2.) {
                if ((aadj = ratio(delta, bs)) <= 2.) {
                        if (dsign)
                        if (dsign)
                                aadj = dval(aadj1) = 1.;
                                aadj = dval(aadj1) = 1.;
                        else if (dword1(rv) || dword0(rv) & Bndry_mask) {
                        else if (dword1(rv) || dword0(rv) & Bndry_mask) {
#ifndef Sudden_Underflow
#ifndef Sudden_Underflow
                                if (dword1(rv) == Tiny1 && !dword0(rv))
                                if (dword1(rv) == Tiny1 && !dword0(rv))
                                        goto undfl;
                                        goto undfl;
#endif
#endif
                                aadj = 1.;
                                aadj = 1.;
                                dval(aadj1) = -1.;
                                dval(aadj1) = -1.;
                                }
                                }
                        else {
                        else {
                                /* special case -- power of FLT_RADIX to be */
                                /* special case -- power of FLT_RADIX to be */
                                /* rounded down... */
                                /* rounded down... */
 
 
                                if (aadj < 2./FLT_RADIX)
                                if (aadj < 2./FLT_RADIX)
                                        aadj = 1./FLT_RADIX;
                                        aadj = 1./FLT_RADIX;
                                else
                                else
                                        aadj *= 0.5;
                                        aadj *= 0.5;
                                dval(aadj1) = -aadj;
                                dval(aadj1) = -aadj;
                                }
                                }
                        }
                        }
                else {
                else {
                        aadj *= 0.5;
                        aadj *= 0.5;
                        dval(aadj1) = dsign ? aadj : -aadj;
                        dval(aadj1) = dsign ? aadj : -aadj;
#ifdef Check_FLT_ROUNDS
#ifdef Check_FLT_ROUNDS
                        switch(Rounding) {
                        switch(Rounding) {
                                case 2: /* towards +infinity */
                                case 2: /* towards +infinity */
                                        dval(aadj1) -= 0.5;
                                        dval(aadj1) -= 0.5;
                                        break;
                                        break;
                                case 0: /* towards 0 */
                                case 0: /* towards 0 */
                                case 3: /* towards -infinity */
                                case 3: /* towards -infinity */
                                        dval(aadj1) += 0.5;
                                        dval(aadj1) += 0.5;
                                }
                                }
#else
#else
                        if (Flt_Rounds == 0)
                        if (Flt_Rounds == 0)
                                dval(aadj1) += 0.5;
                                dval(aadj1) += 0.5;
#endif /*Check_FLT_ROUNDS*/
#endif /*Check_FLT_ROUNDS*/
                        }
                        }
                y = dword0(rv) & Exp_mask;
                y = dword0(rv) & Exp_mask;
 
 
                /* Check for overflow */
                /* Check for overflow */
 
 
                if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
                if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
                        dval(rv0) = dval(rv);
                        dval(rv0) = dval(rv);
                        dword0(rv) -= P*Exp_msk1;
                        dword0(rv) -= P*Exp_msk1;
                        adj = dval(aadj1) * ulp(dval(rv));
                        adj = dval(aadj1) * ulp(dval(rv));
                        dval(rv) += adj;
                        dval(rv) += adj;
                        if ((dword0(rv) & Exp_mask) >=
                        if ((dword0(rv) & Exp_mask) >=
                                        Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
                                        Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
                                if (dword0(rv0) == Big0 && dword1(rv0) == Big1)
                                if (dword0(rv0) == Big0 && dword1(rv0) == Big1)
                                        goto ovfl;
                                        goto ovfl;
                                dword0(rv) = Big0;
                                dword0(rv) = Big0;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                dword1(rv) = Big1;
                                dword1(rv) = Big1;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                                goto cont;
                                goto cont;
                                }
                                }
                        else
                        else
                                dword0(rv) += P*Exp_msk1;
                                dword0(rv) += P*Exp_msk1;
                        }
                        }
                else {
                else {
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                        if (scale && y <= 2*P*Exp_msk1) {
                        if (scale && y <= 2*P*Exp_msk1) {
                                if (aadj <= 0x7fffffff) {
                                if (aadj <= 0x7fffffff) {
                                        if ((z = aadj) <= 0)
                                        if ((z = aadj) <= 0)
                                                z = 1;
                                                z = 1;
                                        aadj = z;
                                        aadj = z;
                                        dval(aadj1) = dsign ? aadj : -aadj;
                                        dval(aadj1) = dsign ? aadj : -aadj;
                                        }
                                        }
                                dword0(aadj1) += (2*P+1)*Exp_msk1 - y;
                                dword0(aadj1) += (2*P+1)*Exp_msk1 - y;
                                }
                                }
                        adj = dval(aadj1) * ulp(dval(rv));
                        adj = dval(aadj1) * ulp(dval(rv));
                        dval(rv) += adj;
                        dval(rv) += adj;
#else
#else
#ifdef Sudden_Underflow
#ifdef Sudden_Underflow
                        if ((dword0(rv) & Exp_mask) <= P*Exp_msk1) {
                        if ((dword0(rv) & Exp_mask) <= P*Exp_msk1) {
                                dval(rv0) = dval(rv);
                                dval(rv0) = dval(rv);
                                dword0(rv) += P*Exp_msk1;
                                dword0(rv) += P*Exp_msk1;
                                adj = dval(aadj1) * ulp(dval(rv));
                                adj = dval(aadj1) * ulp(dval(rv));
                                dval(rv) += adj;
                                dval(rv) += adj;
#ifdef IBM
#ifdef IBM
                                if ((dword0(rv) & Exp_mask) <  P*Exp_msk1)
                                if ((dword0(rv) & Exp_mask) <  P*Exp_msk1)
#else
#else
                                if ((dword0(rv) & Exp_mask) <= P*Exp_msk1)
                                if ((dword0(rv) & Exp_mask) <= P*Exp_msk1)
#endif
#endif
                                        {
                                        {
                                        if (dword0(rv0) == Tiny0
                                        if (dword0(rv0) == Tiny0
                                         && dword1(rv0) == Tiny1)
                                         && dword1(rv0) == Tiny1)
                                                goto undfl;
                                                goto undfl;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                                        dword0(rv) = Tiny0;
                                        dword0(rv) = Tiny0;
                                        dword1(rv) = Tiny1;
                                        dword1(rv) = Tiny1;
#else
#else
                                        dword0(rv) = Tiny1;
                                        dword0(rv) = Tiny1;
#endif /*_DOUBLE_IS_32BITS*/
#endif /*_DOUBLE_IS_32BITS*/
                                        goto cont;
                                        goto cont;
                                        }
                                        }
                                else
                                else
                                        dword0(rv) -= P*Exp_msk1;
                                        dword0(rv) -= P*Exp_msk1;
                                }
                                }
                        else {
                        else {
                                adj = dval(aadj1) * ulp(dval(rv));
                                adj = dval(aadj1) * ulp(dval(rv));
                                dval(rv) += adj;
                                dval(rv) += adj;
                                }
                                }
#else /*Sudden_Underflow*/
#else /*Sudden_Underflow*/
                        /* Compute adj so that the IEEE rounding rules will
                        /* Compute adj so that the IEEE rounding rules will
                         * correctly round rv + adj in some half-way cases.
                         * correctly round rv + adj in some half-way cases.
                         * If rv * ulp(rv) is denormalized (i.e.,
                         * If rv * ulp(rv) is denormalized (i.e.,
                         * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
                         * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
                         * trouble from bits lost to denormalization;
                         * trouble from bits lost to denormalization;
                         * example: 1.2e-307 .
                         * example: 1.2e-307 .
                         */
                         */
                        if (y <= (P-1)*Exp_msk1 && aadj > 1.) {
                        if (y <= (P-1)*Exp_msk1 && aadj > 1.) {
                                dval(aadj1) = (double)(int)(aadj + 0.5);
                                dval(aadj1) = (double)(int)(aadj + 0.5);
                                if (!dsign)
                                if (!dsign)
                                        dval(aadj1) = -dval(aadj1);
                                        dval(aadj1) = -dval(aadj1);
                                }
                                }
                        adj = dval(aadj1) * ulp(dval(rv));
                        adj = dval(aadj1) * ulp(dval(rv));
                        dval(rv) += adj;
                        dval(rv) += adj;
#endif /*Sudden_Underflow*/
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
#endif /*Avoid_Underflow*/
                        }
                        }
                z = dword0(rv) & Exp_mask;
                z = dword0(rv) & Exp_mask;
#ifndef SET_INEXACT
#ifndef SET_INEXACT
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
                if (!scale)
                if (!scale)
#endif
#endif
                if (y == z) {
                if (y == z) {
                        /* Can we stop now? */
                        /* Can we stop now? */
                        L = (Long)aadj;
                        L = (Long)aadj;
                        aadj -= L;
                        aadj -= L;
                        /* The tolerances below are conservative. */
                        /* The tolerances below are conservative. */
                        if (dsign || dword1(rv) || dword0(rv) & Bndry_mask) {
                        if (dsign || dword1(rv) || dword0(rv) & Bndry_mask) {
                                if (aadj < .4999999 || aadj > .5000001)
                                if (aadj < .4999999 || aadj > .5000001)
                                        break;
                                        break;
                                }
                                }
                        else if (aadj < .4999999/FLT_RADIX)
                        else if (aadj < .4999999/FLT_RADIX)
                                break;
                                break;
                        }
                        }
#endif
#endif
 cont:
 cont:
                Bfree(ptr,bb);
                Bfree(ptr,bb);
                Bfree(ptr,bd);
                Bfree(ptr,bd);
                Bfree(ptr,bs);
                Bfree(ptr,bs);
                Bfree(ptr,delta);
                Bfree(ptr,delta);
                }
                }
#ifdef SET_INEXACT
#ifdef SET_INEXACT
        if (inexact) {
        if (inexact) {
                if (!oldinexact) {
                if (!oldinexact) {
                        dword0(rv0) = Exp_1 + (70 << Exp_shift);
                        dword0(rv0) = Exp_1 + (70 << Exp_shift);
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                        dword1(rv0) = 0;
                        dword1(rv0) = 0;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                        dval(rv0) += 1.;
                        dval(rv0) += 1.;
                        }
                        }
                }
                }
        else if (!oldinexact)
        else if (!oldinexact)
                clear_inexact();
                clear_inexact();
#endif
#endif
#ifdef Avoid_Underflow
#ifdef Avoid_Underflow
        if (scale) {
        if (scale) {
                dword0(rv0) = Exp_1 - 2*P*Exp_msk1;
                dword0(rv0) = Exp_1 - 2*P*Exp_msk1;
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
                dword1(rv0) = 0;
                dword1(rv0) = 0;
#endif /*!_DOUBLE_IS_32BITS*/
#endif /*!_DOUBLE_IS_32BITS*/
                dval(rv) *= dval(rv0);
                dval(rv) *= dval(rv0);
#ifndef NO_ERRNO
#ifndef NO_ERRNO
                /* try to avoid the bug of testing an 8087 register value */
                /* try to avoid the bug of testing an 8087 register value */
                if (dword0(rv) == 0 && dword1(rv) == 0)
                if (dword0(rv) == 0 && dword1(rv) == 0)
                        ptr->_errno = ERANGE;
                        ptr->_errno = ERANGE;
#endif
#endif
                }
                }
#endif /* Avoid_Underflow */
#endif /* Avoid_Underflow */
#ifdef SET_INEXACT
#ifdef SET_INEXACT
        if (inexact && !(dword0(rv) & Exp_mask)) {
        if (inexact && !(dword0(rv) & Exp_mask)) {
                /* set underflow bit */
                /* set underflow bit */
                dval(rv0) = 1e-300;
                dval(rv0) = 1e-300;
                dval(rv0) *= dval(rv0);
                dval(rv0) *= dval(rv0);
                }
                }
#endif
#endif
 retfree:
 retfree:
        Bfree(ptr,bb);
        Bfree(ptr,bb);
        Bfree(ptr,bd);
        Bfree(ptr,bd);
        Bfree(ptr,bs);
        Bfree(ptr,bs);
        Bfree(ptr,bd0);
        Bfree(ptr,bd0);
        Bfree(ptr,delta);
        Bfree(ptr,delta);
 ret:
 ret:
        if (se)
        if (se)
                *se = (char *)s;
                *se = (char *)s;
        return sign ? -dval(rv) : dval(rv);
        return sign ? -dval(rv) : dval(rv);
}
}
 
 
#ifndef _REENT_ONLY
#ifndef _REENT_ONLY
 
 
double
double
_DEFUN (strtod, (s00, se),
_DEFUN (strtod, (s00, se),
        _CONST char *s00 _AND char **se)
        _CONST char *s00 _AND char **se)
{
{
  return _strtod_r (_REENT, s00, se);
  return _strtod_r (_REENT, s00, se);
}
}
 
 
float
float
_DEFUN (strtof, (s00, se),
_DEFUN (strtof, (s00, se),
        _CONST char *s00 _AND
        _CONST char *s00 _AND
        char **se)
        char **se)
{
{
  double retval = _strtod_r (_REENT, s00, se);
  double retval = _strtod_r (_REENT, s00, se);
  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.