-/* $NetBSD: strtodg.c,v 1.5.14.1 2008/04/08 21:10:55 jdc Exp $ */\r
-\r
-/****************************************************************\r
-\r
-The author of this software is David M. Gay.\r
-\r
-Copyright (C) 1998-2001 by Lucent Technologies\r
-All Rights Reserved\r
-\r
-Permission to use, copy, modify, and distribute this software and\r
-its documentation for any purpose and without fee is hereby\r
-granted, provided that the above copyright notice appear in all\r
-copies and that both that the copyright notice and this\r
-permission notice and warranty disclaimer appear in supporting\r
-documentation, and that the name of Lucent or any of its entities\r
-not be used in advertising or publicity pertaining to\r
-distribution of the software without specific, written prior\r
-permission.\r
-\r
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
-THIS SOFTWARE.\r
-\r
-****************************************************************/\r
-\r
-/* Please send bug reports to David M. Gay (dmg at acm dot org,\r
- * with " at " changed at "@" and " dot " changed to "."). */\r
+/** @file\r
+\r
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials are licensed and made available under\r
+ the terms and conditions of the BSD License that accompanies this distribution.\r
+ The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ *****************************************************************\r
+\r
+ The author of this software is David M. Gay.\r
+\r
+ Copyright (C) 1998-2001 by Lucent Technologies\r
+ All Rights Reserved\r
+\r
+ Permission to use, copy, modify, and distribute this software and\r
+ its documentation for any purpose and without fee is hereby\r
+ granted, provided that the above copyright notice appear in all\r
+ copies and that both that the copyright notice and this\r
+ permission notice and warranty disclaimer appear in supporting\r
+ documentation, and that the name of Lucent or any of its entities\r
+ not be used in advertising or publicity pertaining to\r
+ distribution of the software without specific, written prior\r
+ permission.\r
+\r
+ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r
+ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r
+ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
+ THIS SOFTWARE.\r
+\r
+ Please send bug reports to David M. Gay (dmg at acm dot org,\r
+ with " at " changed at "@" and " dot " changed to ".").\r
+\r
+ *****************************************************************\r
+\r
+ NetBSD: strtodg.c,v 1.5.14.1 2008/04/08 21:10:55 jdc Exp\r
+**/\r
#include <LibConfig.h>\r
\r
#include "gdtoaimp.h"\r
};\r
\r
Bigint *\r
-#ifdef KR_headers\r
-increment(b) Bigint *b;\r
-#else\r
increment(Bigint *b)\r
-#endif\r
{\r
ULong *x, *xe;\r
Bigint *b1;\r
}\r
\r
int\r
-#ifdef KR_headers\r
-decrement(b) Bigint *b;\r
-#else\r
decrement(Bigint *b)\r
-#endif\r
{\r
ULong *x, *xe;\r
#ifdef Pack_16\r
}\r
\r
static int\r
-#ifdef KR_headers\r
-all_on(b, n) CONST Bigint *b; int n;\r
-#else\r
all_on(CONST Bigint *b, int n)\r
-#endif\r
{\r
CONST ULong *x, *xe;\r
\r
}\r
\r
Bigint *\r
-#ifdef KR_headers\r
-set_ones(b, n) Bigint *b; int n;\r
-#else\r
set_ones(Bigint *b, int n)\r
-#endif\r
{\r
int k;\r
ULong *x, *xe;\r
}\r
\r
static int\r
-rvOK\r
-#ifdef KR_headers\r
- (d, fpi, expt, bits, exact, rd, irv)\r
- double d; CONST FPI *fpi; Long *expt; ULong *bits; int exact, rd, *irv;\r
-#else\r
- (double d, CONST FPI *fpi, Long *expt, ULong *bits, int exact, int rd, int *irv)\r
-#endif\r
+rvOK (\r
+ double d, CONST FPI *fpi, Long *expt, ULong *bits, int exact, int rd, int *irv\r
+)\r
{\r
Bigint *b;\r
ULong carry, inex, lostbits;\r
return rv;\r
}\r
\r
-#ifndef VAX\r
static int\r
-#ifdef KR_headers\r
-mantbits(d) double d;\r
-#else\r
mantbits(double d)\r
-#endif\r
{\r
ULong L;\r
-#ifdef VAX\r
- L = word1(d) << 16 | word1(d) >> 16;\r
- if (L)\r
-#else\r
if ( (L = word1(d)) !=0)\r
-#endif\r
return P - lo0bits(&L);\r
-#ifdef VAX\r
- L = word0(d) << 16 | word0(d) >> 16 | Exp_msk11;\r
-#else\r
L = word0(d) | Exp_msk1;\r
-#endif\r
return P - 32 - lo0bits(&L);\r
}\r
-#endif /* !VAX */\r
\r
int\r
-strtodg\r
-#ifdef KR_headers\r
- (s00, se, fpi, expt, bits)\r
- CONST char *s00; char **se; CONST FPI *fpi; Long *expt; ULong *bits;\r
-#else\r
- (CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits)\r
-#endif\r
+strtodg (\r
+ CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits\r
+)\r
{\r
- int abe, abits, asub;\r
+ int abe = 0, abits = 0, asub;\r
int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm;\r
int dsign, e, e1, e2, emin, esign, finished, i, inex, irv;\r
int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign;\r
}\r
else if (e > 0) {\r
if (e <= Ten_pmax) {\r
-#ifdef VAX\r
- goto vax_ovfl_check;\r
-#else\r
i = fivesbits[e] + mantbits(dval(rv)) <= P;\r
/* rv = */ rounded_product(dval(rv), tens[e]);\r
if (rvOK(dval(rv), fpi, expt, bits, i, rd, &irv))\r
goto ret;\r
e1 -= e;\r
goto rv_notOK;\r
-#endif\r
}\r
i = DBL_DIG - nd;\r
if (e <= Ten_pmax + i) {\r
e2 = e - i;\r
e1 -= i;\r
dval(rv) *= tens[i];\r
-#ifdef VAX\r
- /* VAX exponent range is so narrow we must\r
- * worry about overflow here...\r
- */\r
- vax_ovfl_check:\r
- dval(adj) = dval(rv);\r
- word0(adj) -= P*Exp_msk1;\r
- /* adj = */ rounded_product(dval(adj), tens[e2]);\r
- if ((word0(adj) & Exp_mask)\r
- > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))\r
- goto rv_notOK;\r
- word0(adj) += P*Exp_msk1;\r
- dval(rv) = dval(adj);\r
-#else\r
/* rv = */ rounded_product(dval(rv), tens[e2]);\r
-#endif\r
if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv))\r
goto ret;\r
e1 -= e2;\r
if (e1 &= ~15) {\r
e1 = (unsigned int)e1 >> 4;\r
while(e1 >= (1 << (n_bigtens-1))) {\r
- e2 += ((word0(rv) & Exp_mask)\r
+ e2 += (unsigned int)((word0(rv) & Exp_mask)\r
>> Exp_shift1) - Bias;\r
word0(rv) &= ~Exp_mask;\r
word0(rv) |= Bias << Exp_shift1;\r
dval(rv) *= bigtens[n_bigtens-1];\r
e1 -= 1 << (n_bigtens-1);\r
}\r
- e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;\r
+ e2 += (unsigned int)((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;\r
word0(rv) &= ~Exp_mask;\r
word0(rv) |= Bias << Exp_shift1;\r
for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1)\r
if (e1 &= ~15) {\r
e1 = (unsigned int)e1 >> 4;\r
while(e1 >= (1 << (n_bigtens-1))) {\r
- e2 += ((word0(rv) & Exp_mask)\r
+ e2 += (unsigned int)((word0(rv) & Exp_mask)\r
>> Exp_shift1) - Bias;\r
word0(rv) &= ~Exp_mask;\r
word0(rv) |= Bias << Exp_shift1;\r
dval(rv) *= tinytens[n_bigtens-1];\r
e1 -= 1 << (n_bigtens-1);\r
}\r
- e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;\r
+ e2 += (unsigned int)((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;\r
word0(rv) &= ~Exp_mask;\r
word0(rv) |= Bias << Exp_shift1;\r
for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1)\r
dval(rv) *= tinytens[j];\r
}\r
}\r
-#ifdef IBM\r
- /* e2 is a correction to the (base 2) exponent of the return\r
- * value, reflecting adjustments above to avoid overflow in the\r
- * native arithmetic. For native IBM (base 16) arithmetic, we\r
- * must multiply e2 by 4 to change from base 16 to 2.\r
- */\r
- e2 <<= 2;\r
-#endif\r
rvb = d2b(dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */\r
if (rvb == NULL)\r
return STRTOG_NoMemory;\r
inex = STRTOG_Inexlo;\r
}\r
if (dval(adj) < 2147483647.) {\r
- L = (INT32)adj0;\r
+ L = (Long)adj0;\r
adj0 -= L;\r
switch(rd) {\r
case 0:\r
break;\r
case 2:\r
if (!asub && adj0 > 0.) {\r
- inc_L:\r
+inc_L:\r
L++;\r
inex = STRTOG_Inexact - inex;\r
}\r