StdLib: Fix a "potentially uninitialized variable" error.
gdtoa/gdtoa.c: Several "goto" paths allowed the initialization of a variable to be bypassed. Initialized it at the top of the function in order to eliminate the error. Updated the file header and copyright notices. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Daryl McDaniel <daryl.mcdaniel@intel.com> Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16324 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
931b2cff42
commit
2a7e98a8cc
@ -1,6 +1,15 @@
|
|||||||
/* $NetBSD: gdtoa.c,v 1.1.1.1.4.1.4.1 2008/04/08 21:10:55 jdc Exp $ */
|
/** @file
|
||||||
|
|
||||||
/****************************************************************
|
Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
|
This program and the accompanying materials are licensed and made available under
|
||||||
|
the terms and conditions of the BSD License that accompanies this distribution.
|
||||||
|
The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php.
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
***************************************************************
|
||||||
|
|
||||||
The author of this software is David M. Gay.
|
The author of this software is David M. Gay.
|
||||||
|
|
||||||
@ -26,10 +35,11 @@ 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,
|
||||||
|
with " at " changed at "@" and " dot " changed to ".").
|
||||||
|
|
||||||
/* Please send bug reports to David M. Gay (dmg at acm dot org,
|
NetBSD: gdtoa.c,v 1.1.1.1.4.1.4.1 2008/04/08 21:10:55 jdc Exp
|
||||||
* with " at " changed at "@" and " dot " changed to "."). */
|
**/
|
||||||
#include <LibConfig.h>
|
#include <LibConfig.h>
|
||||||
|
|
||||||
#include "gdtoaimp.h"
|
#include "gdtoaimp.h"
|
||||||
@ -53,7 +63,7 @@ bitstob(ULong *bits, int nbits, int *bbits)
|
|||||||
while(i < nbits) {
|
while(i < nbits) {
|
||||||
i <<= 1;
|
i <<= 1;
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
#ifndef Pack_32
|
#ifndef Pack_32
|
||||||
if (!k)
|
if (!k)
|
||||||
k = 1;
|
k = 1;
|
||||||
@ -68,19 +78,19 @@ bitstob(ULong *bits, int nbits, int *bbits)
|
|||||||
#ifdef Pack_16
|
#ifdef Pack_16
|
||||||
*x++ = (*bits >> 16) & ALL_ON;
|
*x++ = (*bits >> 16) & ALL_ON;
|
||||||
#endif
|
#endif
|
||||||
} while(++bits <= be);
|
} while(++bits <= be);
|
||||||
i = x - x0;
|
i = x - x0;
|
||||||
while(!x0[--i])
|
while(!x0[--i])
|
||||||
if (!i) {
|
if (!i) {
|
||||||
b->wds = 0;
|
b->wds = 0;
|
||||||
*bbits = 0;
|
*bbits = 0;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
b->wds = i + 1;
|
b->wds = i + 1;
|
||||||
*bbits = i*ULbits + 32 - hi0bits(b->x[i]);
|
*bbits = i*ULbits + 32 - hi0bits(b->x[i]);
|
||||||
ret:
|
ret:
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
|
/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
|
||||||
*
|
*
|
||||||
@ -162,11 +172,13 @@ gdtoa
|
|||||||
double d, d2, ds, eps;
|
double d, d2, ds, eps;
|
||||||
char *s, *s0;
|
char *s, *s0;
|
||||||
|
|
||||||
|
mlo = NULL;
|
||||||
|
|
||||||
#ifndef MULTIPLE_THREADS
|
#ifndef MULTIPLE_THREADS
|
||||||
if (dtoa_result) {
|
if (dtoa_result) {
|
||||||
freedtoa(dtoa_result);
|
freedtoa(dtoa_result);
|
||||||
dtoa_result = 0;
|
dtoa_result = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
inex = 0;
|
inex = 0;
|
||||||
if (*kindp & STRTOG_NoMemory)
|
if (*kindp & STRTOG_NoMemory)
|
||||||
@ -174,19 +186,19 @@ gdtoa
|
|||||||
kind = *kindp &= ~STRTOG_Inexact;
|
kind = *kindp &= ~STRTOG_Inexact;
|
||||||
switch(kind & STRTOG_Retmask) {
|
switch(kind & STRTOG_Retmask) {
|
||||||
case STRTOG_Zero:
|
case STRTOG_Zero:
|
||||||
goto ret_zero;
|
goto ret_zero;
|
||||||
case STRTOG_Normal:
|
case STRTOG_Normal:
|
||||||
case STRTOG_Denormal:
|
case STRTOG_Denormal:
|
||||||
break;
|
break;
|
||||||
case STRTOG_Infinite:
|
case STRTOG_Infinite:
|
||||||
*decpt = -32768;
|
*decpt = -32768;
|
||||||
return nrv_alloc("Infinity", rve, 8);
|
return nrv_alloc("Infinity", rve, 8);
|
||||||
case STRTOG_NaN:
|
case STRTOG_NaN:
|
||||||
*decpt = -32768;
|
*decpt = -32768;
|
||||||
return nrv_alloc("NaN", rve, 3);
|
return nrv_alloc("NaN", rve, 3);
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
b = bitstob(bits, nbits = fpi->nbits, &bbits);
|
b = bitstob(bits, nbits = fpi->nbits, &bbits);
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -195,13 +207,13 @@ gdtoa
|
|||||||
rshift(b, i);
|
rshift(b, i);
|
||||||
be += i;
|
be += i;
|
||||||
bbits -= i;
|
bbits -= i;
|
||||||
}
|
}
|
||||||
if (!b->wds) {
|
if (!b->wds) {
|
||||||
Bfree(b);
|
Bfree(b);
|
||||||
ret_zero:
|
ret_zero:
|
||||||
*decpt = 1;
|
*decpt = 1;
|
||||||
return nrv_alloc("0", rve, 1);
|
return nrv_alloc("0", rve, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
dval(d) = b2d(b, &i);
|
dval(d) = b2d(b, &i);
|
||||||
i = be + bbits - 1;
|
i = be + bbits - 1;
|
||||||
@ -261,33 +273,33 @@ gdtoa
|
|||||||
if (dval(d) < tens[k])
|
if (dval(d) < tens[k])
|
||||||
k--;
|
k--;
|
||||||
k_check = 0;
|
k_check = 0;
|
||||||
}
|
}
|
||||||
j = bbits - i - 1;
|
j = bbits - i - 1;
|
||||||
if (j >= 0) {
|
if (j >= 0) {
|
||||||
b2 = 0;
|
b2 = 0;
|
||||||
s2 = j;
|
s2 = j;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
b2 = -j;
|
b2 = -j;
|
||||||
s2 = 0;
|
s2 = 0;
|
||||||
}
|
}
|
||||||
if (k >= 0) {
|
if (k >= 0) {
|
||||||
b5 = 0;
|
b5 = 0;
|
||||||
s5 = k;
|
s5 = k;
|
||||||
s2 += k;
|
s2 += k;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
b2 -= k;
|
b2 -= k;
|
||||||
b5 = -k;
|
b5 = -k;
|
||||||
s5 = 0;
|
s5 = 0;
|
||||||
}
|
}
|
||||||
if (mode < 0 || mode > 9)
|
if (mode < 0 || mode > 9)
|
||||||
mode = 0;
|
mode = 0;
|
||||||
try_quick = 1;
|
try_quick = 1;
|
||||||
if (mode > 5) {
|
if (mode > 5) {
|
||||||
mode -= 4;
|
mode -= 4;
|
||||||
try_quick = 0;
|
try_quick = 0;
|
||||||
}
|
}
|
||||||
leftright = 1;
|
leftright = 1;
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -313,7 +325,7 @@ gdtoa
|
|||||||
ilim1 = i - 1;
|
ilim1 = i - 1;
|
||||||
if (i <= 0)
|
if (i <= 0)
|
||||||
i = 1;
|
i = 1;
|
||||||
}
|
}
|
||||||
s = s0 = rv_alloc((size_t)i);
|
s = s0 = rv_alloc((size_t)i);
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -323,7 +335,7 @@ gdtoa
|
|||||||
rdir = 2;
|
rdir = 2;
|
||||||
if (kind & STRTOG_Neg)
|
if (kind & STRTOG_Neg)
|
||||||
rdir = 3 - rdir;
|
rdir = 3 - rdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now rdir = 0 ==> round near, 1 ==> round up, 2 ==> round down. */
|
/* Now rdir = 0 ==> round near, 1 ==> round up, 2 ==> round down. */
|
||||||
|
|
||||||
@ -352,13 +364,13 @@ gdtoa
|
|||||||
j &= Bletch - 1;
|
j &= Bletch - 1;
|
||||||
dval(d) /= bigtens[n_bigtens-1];
|
dval(d) /= bigtens[n_bigtens-1];
|
||||||
ieps++;
|
ieps++;
|
||||||
}
|
}
|
||||||
for(; j; j /= 2, i++)
|
for(; j; j /= 2, i++)
|
||||||
if (j & 1) {
|
if (j & 1) {
|
||||||
ieps++;
|
ieps++;
|
||||||
ds *= bigtens[i];
|
ds *= bigtens[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ds = 1.;
|
ds = 1.;
|
||||||
if ( (jj1 = -k) !=0) {
|
if ( (jj1 = -k) !=0) {
|
||||||
@ -367,9 +379,9 @@ gdtoa
|
|||||||
if (j & 1) {
|
if (j & 1) {
|
||||||
ieps++;
|
ieps++;
|
||||||
dval(d) *= bigtens[i];
|
dval(d) *= bigtens[i];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (k_check && dval(d) < 1. && ilim > 0) {
|
if (k_check && dval(d) < 1. && ilim > 0) {
|
||||||
if (ilim1 <= 0)
|
if (ilim1 <= 0)
|
||||||
goto fast_failed;
|
goto fast_failed;
|
||||||
@ -377,7 +389,7 @@ gdtoa
|
|||||||
k--;
|
k--;
|
||||||
dval(d) *= 10.;
|
dval(d) *= 10.;
|
||||||
ieps++;
|
ieps++;
|
||||||
}
|
}
|
||||||
dval(eps) = ieps*dval(d) + 7.;
|
dval(eps) = ieps*dval(d) + 7.;
|
||||||
word0(eps) -= (P-1)*Exp_msk1;
|
word0(eps) -= (P-1)*Exp_msk1;
|
||||||
if (ilim == 0) {
|
if (ilim == 0) {
|
||||||
@ -388,7 +400,7 @@ gdtoa
|
|||||||
if (dval(d) < -dval(eps))
|
if (dval(d) < -dval(eps))
|
||||||
goto no_digits;
|
goto no_digits;
|
||||||
goto fast_failed;
|
goto fast_failed;
|
||||||
}
|
}
|
||||||
#ifndef No_leftright
|
#ifndef No_leftright
|
||||||
if (leftright) {
|
if (leftright) {
|
||||||
/* Use Steele & White method of only
|
/* Use Steele & White method of only
|
||||||
@ -403,15 +415,15 @@ gdtoa
|
|||||||
if (dval(d))
|
if (dval(d))
|
||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
goto ret1;
|
goto ret1;
|
||||||
}
|
}
|
||||||
if (ds - dval(d) < dval(eps))
|
if (ds - dval(d) < dval(eps))
|
||||||
goto bump_up;
|
goto bump_up;
|
||||||
if (++i >= ilim)
|
if (++i >= ilim)
|
||||||
break;
|
break;
|
||||||
dval(eps) *= 10.;
|
dval(eps) *= 10.;
|
||||||
dval(d) *= 10.;
|
dval(d) *= 10.;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
#endif
|
#endif
|
||||||
/* Generate ilim digits, then fix them up. */
|
/* Generate ilim digits, then fix them up. */
|
||||||
@ -430,19 +442,19 @@ gdtoa
|
|||||||
if (dval(d))
|
if (dval(d))
|
||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
goto ret1;
|
goto ret1;
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
#ifndef No_leftright
|
|
||||||
}
|
}
|
||||||
|
#ifndef No_leftright
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
fast_failed:
|
fast_failed:
|
||||||
s = s0;
|
s = s0;
|
||||||
dval(d) = d2;
|
dval(d) = d2;
|
||||||
k = k0;
|
k = k0;
|
||||||
ilim = ilim0;
|
ilim = ilim0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do we have a "small" integer? */
|
/* Do we have a "small" integer? */
|
||||||
|
|
||||||
@ -454,7 +466,7 @@ gdtoa
|
|||||||
if (ilim < 0 || dval(d) <= 5*ds)
|
if (ilim < 0 || dval(d) <= 5*ds)
|
||||||
goto no_digits;
|
goto no_digits;
|
||||||
goto one_digit;
|
goto one_digit;
|
||||||
}
|
}
|
||||||
for(i = 1;; i++, dval(d) *= 10.) {
|
for(i = 1;; i++, dval(d) *= 10.) {
|
||||||
L = dval(d) / ds;
|
L = dval(d) / ds;
|
||||||
dval(d) -= L*ds;
|
dval(d) -= L*ds;
|
||||||
@ -463,7 +475,7 @@ gdtoa
|
|||||||
if (dval(d) < 0) {
|
if (dval(d) < 0) {
|
||||||
L--;
|
L--;
|
||||||
dval(d) += ds;
|
dval(d) += ds;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
*s++ = '0' + (int)L;
|
*s++ = '0' + (int)L;
|
||||||
if (dval(d) == 0.)
|
if (dval(d) == 0.)
|
||||||
@ -474,37 +486,38 @@ gdtoa
|
|||||||
goto bump_up;
|
goto bump_up;
|
||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
goto ret1;
|
goto ret1;
|
||||||
}
|
}
|
||||||
dval(d) += dval(d);
|
dval(d) += dval(d);
|
||||||
if (dval(d) > ds || (dval(d) == ds && L & 1)) {
|
if (dval(d) > ds || (dval(d) == ds && L & 1)) {
|
||||||
bump_up:
|
bump_up:
|
||||||
inex = STRTOG_Inexhi;
|
inex = STRTOG_Inexhi;
|
||||||
while(*--s == '9')
|
while(*--s == '9')
|
||||||
if (s == s0) {
|
if (s == s0) {
|
||||||
k++;
|
k++;
|
||||||
*s = '0';
|
*s = '0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++*s++;
|
++*s++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
goto ret1;
|
|
||||||
}
|
}
|
||||||
|
goto ret1;
|
||||||
|
}
|
||||||
|
|
||||||
m2 = b2;
|
m2 = b2;
|
||||||
m5 = b5;
|
m5 = b5;
|
||||||
mhi = mlo = 0;
|
mhi = NULL;
|
||||||
|
mlo = NULL;
|
||||||
if (leftright) {
|
if (leftright) {
|
||||||
if (mode < 2) {
|
if (mode < 2) {
|
||||||
i = nbits - bbits;
|
i = nbits - bbits;
|
||||||
if (be - i++ < fpi->emin)
|
if (be - i++ < fpi->emin)
|
||||||
/* denormal */
|
/* denormal */
|
||||||
i = be - fpi->emin + 1;
|
i = be - fpi->emin + 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
j = ilim - 1;
|
j = ilim - 1;
|
||||||
if (m5 >= j)
|
if (m5 >= j)
|
||||||
@ -513,22 +526,22 @@ gdtoa
|
|||||||
s5 += j -= m5;
|
s5 += j -= m5;
|
||||||
b5 += j;
|
b5 += j;
|
||||||
m5 = 0;
|
m5 = 0;
|
||||||
}
|
}
|
||||||
if ((i = ilim) < 0) {
|
if ((i = ilim) < 0) {
|
||||||
m2 -= i;
|
m2 -= i;
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
b2 += i;
|
b2 += i;
|
||||||
s2 += i;
|
s2 += i;
|
||||||
mhi = i2b(1);
|
mhi = i2b(1);
|
||||||
}
|
}
|
||||||
if (m2 > 0 && s2 > 0) {
|
if (m2 > 0 && s2 > 0) {
|
||||||
i = m2 < s2 ? m2 : s2;
|
i = m2 < s2 ? m2 : s2;
|
||||||
b2 -= i;
|
b2 -= i;
|
||||||
m2 -= i;
|
m2 -= i;
|
||||||
s2 -= i;
|
s2 -= i;
|
||||||
}
|
}
|
||||||
if (b5 > 0) {
|
if (b5 > 0) {
|
||||||
if (leftright) {
|
if (leftright) {
|
||||||
if (m5 > 0) {
|
if (m5 > 0) {
|
||||||
@ -540,19 +553,19 @@ gdtoa
|
|||||||
return NULL;
|
return NULL;
|
||||||
Bfree(b);
|
Bfree(b);
|
||||||
b = b1;
|
b = b1;
|
||||||
}
|
}
|
||||||
if ( (j = b5 - m5) !=0) {
|
if ( (j = b5 - m5) !=0) {
|
||||||
b = pow5mult(b, j);
|
b = pow5mult(b, j);
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
b = pow5mult(b, b5);
|
b = pow5mult(b, b5);
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
S = i2b(1);
|
S = i2b(1);
|
||||||
if (S == NULL)
|
if (S == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -560,7 +573,7 @@ gdtoa
|
|||||||
S = pow5mult(S, s5);
|
S = pow5mult(S, s5);
|
||||||
if (S == NULL)
|
if (S == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for special case that d is a normalized power of 2. */
|
/* Check for special case that d is a normalized power of 2. */
|
||||||
|
|
||||||
@ -571,8 +584,8 @@ gdtoa
|
|||||||
b2++;
|
b2++;
|
||||||
s2++;
|
s2++;
|
||||||
spec_case = 1;
|
spec_case = 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Arrange for convenient computation of quotients:
|
/* Arrange for convenient computation of quotients:
|
||||||
* shift left if necessary so divisor has 4 leading 0 bits.
|
* shift left if necessary so divisor has 4 leading 0 bits.
|
||||||
@ -593,13 +606,13 @@ gdtoa
|
|||||||
b2 += i;
|
b2 += i;
|
||||||
m2 += i;
|
m2 += i;
|
||||||
s2 += i;
|
s2 += i;
|
||||||
}
|
}
|
||||||
else if (i < 4) {
|
else if (i < 4) {
|
||||||
i += 28;
|
i += 28;
|
||||||
b2 += i;
|
b2 += i;
|
||||||
m2 += i;
|
m2 += i;
|
||||||
s2 += i;
|
s2 += i;
|
||||||
}
|
}
|
||||||
if (b2 > 0)
|
if (b2 > 0)
|
||||||
b = lshift(b, b2);
|
b = lshift(b, b2);
|
||||||
if (s2 > 0)
|
if (s2 > 0)
|
||||||
@ -614,30 +627,30 @@ gdtoa
|
|||||||
mhi = multadd(mhi, 10, 0);
|
mhi = multadd(mhi, 10, 0);
|
||||||
if (mhi == NULL)
|
if (mhi == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
ilim = ilim1;
|
|
||||||
}
|
}
|
||||||
|
ilim = ilim1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (ilim <= 0 && mode > 2) {
|
if (ilim <= 0 && mode > 2) {
|
||||||
if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
|
if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
|
||||||
/* no digits, fcvt style */
|
/* no digits, fcvt style */
|
||||||
no_digits:
|
no_digits:
|
||||||
k = -1 - ndigits;
|
k = -1 - ndigits;
|
||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
one_digit:
|
one_digit:
|
||||||
inex = STRTOG_Inexhi;
|
inex = STRTOG_Inexhi;
|
||||||
*s++ = '1';
|
*s++ = '1';
|
||||||
k++;
|
k++;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
if (leftright) {
|
if (leftright) {
|
||||||
if (m2 > 0) {
|
if (m2 > 0) {
|
||||||
mhi = lshift(mhi, m2);
|
mhi = lshift(mhi, m2);
|
||||||
if (mhi == NULL)
|
if (mhi == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute mlo -- check for special case
|
/* Compute mlo -- check for special case
|
||||||
* that d is a normalized power of 2.
|
* that d is a normalized power of 2.
|
||||||
@ -652,7 +665,7 @@ gdtoa
|
|||||||
mhi = lshift(mhi, 1);
|
mhi = lshift(mhi, 1);
|
||||||
if (mhi == NULL)
|
if (mhi == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 1;;i++) {
|
for(i = 1;;i++) {
|
||||||
dig = quorem(b,S) + '0';
|
dig = quorem(b,S) + '0';
|
||||||
@ -672,14 +685,14 @@ gdtoa
|
|||||||
if (j <= 0) {
|
if (j <= 0) {
|
||||||
if (b->wds > 1 || b->x[0])
|
if (b->wds > 1 || b->x[0])
|
||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dig++;
|
dig++;
|
||||||
inex = STRTOG_Inexhi;
|
inex = STRTOG_Inexhi;
|
||||||
}
|
}
|
||||||
*s++ = dig;
|
*s++ = dig;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (j < 0 || (j == 0 && !mode
|
if (j < 0 || (j == 0 && !mode
|
||||||
#ifndef ROUND_BIASED
|
#ifndef ROUND_BIASED
|
||||||
@ -690,7 +703,7 @@ gdtoa
|
|||||||
if (rdir == 2) {
|
if (rdir == 2) {
|
||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
goto accept;
|
goto accept;
|
||||||
}
|
}
|
||||||
while (cmp(S,mhi) > 0) {
|
while (cmp(S,mhi) > 0) {
|
||||||
*s++ = dig;
|
*s++ = dig;
|
||||||
mhi1 = multadd(mhi, 10, 0);
|
mhi1 = multadd(mhi, 10, 0);
|
||||||
@ -703,12 +716,12 @@ gdtoa
|
|||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
dig = quorem(b,S) + '0';
|
dig = quorem(b,S) + '0';
|
||||||
}
|
}
|
||||||
if (dig++ == '9')
|
if (dig++ == '9')
|
||||||
goto round_9_up;
|
goto round_9_up;
|
||||||
inex = STRTOG_Inexhi;
|
inex = STRTOG_Inexhi;
|
||||||
goto accept;
|
goto accept;
|
||||||
}
|
}
|
||||||
if (jj1 > 0) {
|
if (jj1 > 0) {
|
||||||
b = lshift(b, 1);
|
b = lshift(b, 1);
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
@ -718,24 +731,24 @@ gdtoa
|
|||||||
&& dig++ == '9')
|
&& dig++ == '9')
|
||||||
goto round_9_up;
|
goto round_9_up;
|
||||||
inex = STRTOG_Inexhi;
|
inex = STRTOG_Inexhi;
|
||||||
}
|
}
|
||||||
if (b->wds > 1 || b->x[0])
|
if (b->wds > 1 || b->x[0])
|
||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
accept:
|
accept:
|
||||||
*s++ = dig;
|
*s++ = dig;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
if (jj1 > 0 && rdir != 2) {
|
if (jj1 > 0 && rdir != 2) {
|
||||||
if (dig == '9') { /* possible if i == 1 */
|
if (dig == '9') { /* possible if i == 1 */
|
||||||
round_9_up:
|
round_9_up:
|
||||||
*s++ = '9';
|
*s++ = '9';
|
||||||
inex = STRTOG_Inexhi;
|
inex = STRTOG_Inexhi;
|
||||||
goto roundoff;
|
goto roundoff;
|
||||||
}
|
}
|
||||||
inex = STRTOG_Inexhi;
|
inex = STRTOG_Inexhi;
|
||||||
*s++ = dig + 1;
|
*s++ = dig + 1;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
*s++ = dig;
|
*s++ = dig;
|
||||||
if (i == ilim)
|
if (i == ilim)
|
||||||
break;
|
break;
|
||||||
@ -746,7 +759,7 @@ gdtoa
|
|||||||
mlo = mhi = multadd(mhi, 10, 0);
|
mlo = mhi = multadd(mhi, 10, 0);
|
||||||
if (mlo == NULL)
|
if (mlo == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mlo = multadd(mlo, 10, 0);
|
mlo = multadd(mlo, 10, 0);
|
||||||
if (mlo == NULL)
|
if (mlo == NULL)
|
||||||
@ -754,9 +767,9 @@ gdtoa
|
|||||||
mhi = multadd(mhi, 10, 0);
|
mhi = multadd(mhi, 10, 0);
|
||||||
if (mhi == NULL)
|
if (mhi == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
for(i = 1;; i++) {
|
for(i = 1;; i++) {
|
||||||
*s++ = dig = quorem(b,S) + '0';
|
*s++ = dig = quorem(b,S) + '0';
|
||||||
@ -765,7 +778,7 @@ gdtoa
|
|||||||
b = multadd(b, 10, 0);
|
b = multadd(b, 10, 0);
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Round off last digit */
|
/* Round off last digit */
|
||||||
|
|
||||||
@ -773,37 +786,37 @@ gdtoa
|
|||||||
if (rdir == 2 || (b->wds <= 1 && !b->x[0]))
|
if (rdir == 2 || (b->wds <= 1 && !b->x[0]))
|
||||||
goto chopzeros;
|
goto chopzeros;
|
||||||
goto roundoff;
|
goto roundoff;
|
||||||
}
|
}
|
||||||
b = lshift(b, 1);
|
b = lshift(b, 1);
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
j = cmp(b, S);
|
j = cmp(b, S);
|
||||||
if (j > 0 || (j == 0 && dig & 1)) {
|
if (j > 0 || (j == 0 && dig & 1)) {
|
||||||
roundoff:
|
roundoff:
|
||||||
inex = STRTOG_Inexhi;
|
inex = STRTOG_Inexhi;
|
||||||
while(*--s == '9')
|
while(*--s == '9')
|
||||||
if (s == s0) {
|
if (s == s0) {
|
||||||
k++;
|
k++;
|
||||||
*s++ = '1';
|
*s++ = '1';
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
++*s++;
|
++*s++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chopzeros:
|
chopzeros:
|
||||||
if (b->wds > 1 || b->x[0])
|
if (b->wds > 1 || b->x[0])
|
||||||
inex = STRTOG_Inexlo;
|
inex = STRTOG_Inexlo;
|
||||||
while(*--s == '0'){}
|
while(*--s == '0'){}
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
ret:
|
ret:
|
||||||
Bfree(S);
|
Bfree(S);
|
||||||
if (mhi) {
|
if (mhi) {
|
||||||
if (mlo && mlo != mhi)
|
if (mlo && mlo != mhi)
|
||||||
Bfree(mlo);
|
Bfree(mlo);
|
||||||
Bfree(mhi);
|
Bfree(mhi);
|
||||||
}
|
}
|
||||||
ret1:
|
ret1:
|
||||||
Bfree(b);
|
Bfree(b);
|
||||||
*s = 0;
|
*s = 0;
|
||||||
*decpt = k + 1;
|
*decpt = k + 1;
|
||||||
@ -811,4 +824,4 @@ gdtoa
|
|||||||
*rve = s;
|
*rve = s;
|
||||||
*kindp |= inex;
|
*kindp |= inex;
|
||||||
return s0;
|
return s0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user