+++ /dev/null
-/* $NetBSD: smisc.c,v 1.2.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, 1999 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
-#include <LibConfig.h>\r
-\r
-#include "gdtoaimp.h"\r
-\r
-#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */\r
-// Disable: warning C4700: uninitialized local variable 'xx' used\r
-#pragma warning ( disable : 4700 )\r
-#endif /* defined(_MSC_VER) */\r
-\r
-Bigint *\r
-s2b\r
-#ifdef KR_headers\r
- (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9;\r
-#else\r
- (CONST char *s, int nd0, int nd, ULong y9)\r
-#endif\r
-{\r
- Bigint *b;\r
- int i, k;\r
- Long x, y;\r
-\r
- x = (nd + 8) / 9;\r
- for(k = 0, y = 1; x > y; y <<= 1, k++) ;\r
-#ifdef Pack_32\r
- b = Balloc(k);\r
- if (b == NULL)\r
- return NULL;\r
- b->x[0] = y9;\r
- b->wds = 1;\r
-#else\r
- b = Balloc(k+1);\r
- if (b == NULL)\r
- return NULL;\r
- b->x[0] = y9 & 0xffff;\r
- b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;\r
-#endif\r
-\r
- i = 9;\r
- if (9 < nd0) {\r
- s += 9;\r
- do {\r
- b = multadd(b, 10, *s++ - '0');\r
- if (b == NULL)\r
- return NULL;\r
- } while(++i < nd0);\r
- s++;\r
- }\r
- else\r
- s += 10;\r
- for(; i < nd; i++) {\r
- b = multadd(b, 10, *s++ - '0');\r
- if (b == NULL)\r
- return NULL;\r
- }\r
- return b;\r
- }\r
-\r
- double\r
-ratio\r
-#ifdef KR_headers\r
- (a, b) Bigint *a, *b;\r
-#else\r
- (Bigint *a, Bigint *b)\r
-#endif\r
-{\r
- double da, db;\r
- int k, ka, kb;\r
-\r
- dval(da) = b2d(a, &ka);\r
- dval(db) = b2d(b, &kb);\r
- k = ka - kb + ULbits*(a->wds - b->wds);\r
-#ifdef IBM\r
- if (k > 0) {\r
- word0(da) += (k >> 2)*Exp_msk1;\r
- if (k &= 3)\r
- dval(da) *= 1 << k;\r
- }\r
- else {\r
- k = -k;\r
- word0(db) += (k >> 2)*Exp_msk1;\r
- if (k &= 3)\r
- dval(db) *= 1 << k;\r
- }\r
-#else\r
- if (k > 0)\r
- word0(da) += k*Exp_msk1;\r
- else {\r
- k = -k;\r
- word0(db) += k*Exp_msk1;\r
- }\r
-#endif\r
- return dval(da) / dval(db);\r
- }\r
-\r
-#ifdef INFNAN_CHECK\r
-\r
- int\r
-match\r
-#ifdef KR_headers\r
- (sp, t) CONST char **sp, *t;\r
-#else\r
- (CONST char **sp, CONST char *t)\r
-#endif\r
-{\r
- int c, d;\r
- CONST char *s = *sp;\r
-\r
- while( (d = *t++) !=0) {\r
- if ((c = *++s) >= 'A' && c <= 'Z')\r
- c += 'a' - 'A';\r
- if (c != d)\r
- return 0;\r
- }\r
- *sp = s + 1;\r
- return 1;\r
- }\r
-#endif /* INFNAN_CHECK */\r
-\r
- void\r
-#ifdef KR_headers\r
-copybits(c, n, b) ULong *c; int n; Bigint *b;\r
-#else\r
-copybits(ULong *c, int n, Bigint *b)\r
-#endif\r
-{\r
- ULong *ce, *x, *xe;\r
-#ifdef Pack_16\r
- int nw, nw1;\r
-#endif\r
-\r
- ce = c + ((unsigned int)(n-1) >> kshift) + 1;\r
- x = b->x;\r
-#ifdef Pack_32\r
- xe = x + b->wds;\r
- while(x < xe)\r
- *c++ = *x++;\r
-#else\r
- nw = b->wds;\r
- nw1 = nw & 1;\r
- for(xe = x + (nw - nw1); x < xe; x += 2)\r
- Storeinc(c, x[1], x[0]);\r
- if (nw1)\r
- *c++ = *x;\r
-#endif\r
- while(c < ce)\r
- *c++ = 0;\r
- }\r
-\r
- ULong\r
-#ifdef KR_headers\r
-any_on(b, k) Bigint *b; int k;\r
-#else\r
-any_on(Bigint *b, int k)\r
-#endif\r
-{\r
- int n, nwds;\r
- ULong *x, *x0, x1, x2;\r
-\r
- x = b->x;\r
- nwds = b->wds;\r
- n = (unsigned int)k >> kshift;\r
- if (n > nwds)\r
- n = nwds;\r
- else if (n < nwds && (k &= kmask)) {\r
- x1 = x2 = x[n];\r
- x1 >>= k;\r
- x1 <<= k;\r
- if (x1 != x2)\r
- return 1;\r
- }\r
- x0 = x;\r
- x += n;\r
- while(x > x0)\r
- if (*--x)\r
- return 1;\r
- return 0;\r
- }\r