+++ /dev/null
-/* $NetBSD: hexnan.c,v 1.3 2006/03/11 18:38:14 kleink Exp $ */\r
-\r
-/****************************************************************\r
-\r
-The author of this software is David M. Gay.\r
-\r
-Copyright (C) 2000 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
- static void\r
-#ifdef KR_headers\r
-L_shift(x, x1, i) ULong *x; ULong *x1; int i;\r
-#else\r
-L_shift(ULong *x, ULong *x1, int i)\r
-#endif\r
-{\r
- int j;\r
-\r
- i = 8 - i;\r
- i <<= 2;\r
- j = ULbits - i;\r
- do {\r
- *x |= x[1] << j;\r
- x[1] >>= i;\r
- } while(++x < x1);\r
- }\r
-\r
- int\r
-#ifdef KR_headers\r
-hexnan(sp, fpi, x0)\r
- CONST char **sp; CONST FPI *fpi; ULong *x0;\r
-#else\r
-hexnan( CONST char **sp, CONST FPI *fpi, ULong *x0)\r
-#endif\r
-{\r
- ULong c, h, *x, *x1, *xe;\r
- CONST char *s;\r
- int havedig, hd0, i, nbits;\r
-\r
- if (!hexdig['0'])\r
- hexdig_init_D2A();\r
- nbits = fpi->nbits;\r
- x = x0 + ((unsigned int)nbits >> kshift);\r
- if (nbits & kmask)\r
- x++;\r
- *--x = 0;\r
- x1 = xe = x;\r
- havedig = hd0 = i = 0;\r
- s = *sp;\r
- while((c = *(CONST unsigned char*)++s) != 0) {\r
- if ((h = hexdig[c]) == 0) {\r
- if (c <= ' ') {\r
- if (hd0 < havedig) {\r
- if (x < x1 && i < 8)\r
- L_shift(x, x1, i);\r
- if (x <= x0) {\r
- i = 8;\r
- continue;\r
- }\r
- hd0 = havedig;\r
- *--x = 0;\r
- x1 = x;\r
- i = 0;\r
- }\r
- continue;\r
- }\r
- if (/*(*/ c == ')' && havedig) {\r
- *sp = s + 1;\r
- break;\r
- }\r
- return STRTOG_NaN;\r
- }\r
- havedig++;\r
- if (++i > 8) {\r
- if (x <= x0)\r
- continue;\r
- i = 1;\r
- *--x = 0;\r
- }\r
- *x = (*x << 4) | (h & 0xf);\r
- }\r
- if (!havedig)\r
- return STRTOG_NaN;\r
- if (x < x1 && i < 8)\r
- L_shift(x, x1, i);\r
- if (x > x0) {\r
- x1 = x0;\r
- do *x1++ = *x++;\r
- while(x <= xe);\r
- do *x1++ = 0;\r
- while(x1 <= xe);\r
- }\r
- else {\r
- /* truncate high-order word if necessary */\r
- if ( (i = nbits & (ULbits-1)) !=0)\r
- *xe &= ((ULong)0xffffffff) >> (ULbits - i);\r
- }\r
- for(x1 = xe;; --x1) {\r
- if (*x1 != 0)\r
- break;\r
- if (x1 == x0) {\r
- *x1 = 1;\r
- break;\r
- }\r
- }\r
- return STRTOG_NaNbits;\r
- }\r