/****************************************************************12The author of this software is David M. Gay.34Copyright (C) 2000 by Lucent Technologies5All Rights Reserved67Permission to use, copy, modify, and distribute this software and8its documentation for any purpose and without fee is hereby9granted, provided that the above copyright notice appear in all10copies and that both that the copyright notice and this11permission notice and warranty disclaimer appear in supporting12documentation, and that the name of Lucent or any of its entities13not be used in advertising or publicity pertaining to14distribution of the software without specific, written prior15permission.1617LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,18INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.19IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY20SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES21WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER22IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,23ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF24THIS SOFTWARE.2526****************************************************************/2728/* Please send bug reports to David M. Gay (dmg at acm dot org,29* with " at " changed at "@" and " dot " changed to "."). */3031#include "gdtoaimp.h"3233static void34#ifdef KR_headers35L_shift(x, x1, i) ULong *x; ULong *x1; int i;36#else37L_shift(ULong *x, ULong *x1, int i)38#endif39{40int j;4142i = 8 - i;43i <<= 2;44j = ULbits - i;45do {46*x |= x[1] << j;47x[1] >>= i;48} while(++x < x1);49}5051int52#ifdef KR_headers53hexnan(sp, fpi, x0)54CONST char **sp; FPI *fpi; ULong *x0;55#else56hexnan( CONST char **sp, FPI *fpi, ULong *x0)57#endif58{59ULong c, h, *x, *x1, *xe;60CONST char *s;61int havedig, hd0, i, nbits;6263if (!hexdig['0'])64hexdig_init_D2A();65nbits = fpi->nbits;66x = x0 + (nbits >> kshift);67if (nbits & kmask)68x++;69*--x = 0;70x1 = xe = x;71havedig = hd0 = i = 0;72s = *sp;73/* allow optional initial 0x or 0X */74while((c = *(CONST unsigned char*)(s+1)) && c <= ' ')75++s;76if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')77&& *(CONST unsigned char*)(s+3) > ' ')78s += 2;79while((c = *(CONST unsigned char*)++s)) {80if (!(h = hexdig[c])) {81if (c <= ' ') {82if (hd0 < havedig) {83if (x < x1 && i < 8)84L_shift(x, x1, i);85if (x <= x0) {86i = 8;87continue;88}89hd0 = havedig;90*--x = 0;91x1 = x;92i = 0;93}94while(*(CONST unsigned char*)(s+1) <= ' ')95++s;96if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')97&& *(CONST unsigned char*)(s+3) > ' ')98s += 2;99continue;100}101if (/*(*/ c == ')' && havedig) {102*sp = s + 1;103break;104}105#ifndef GDTOA_NON_PEDANTIC_NANCHECK106do {107if (/*(*/ c == ')') {108*sp = s + 1;109break;110}111} while((c = *++s));112#endif113return STRTOG_NaN;114}115havedig++;116if (++i > 8) {117if (x <= x0)118continue;119i = 1;120*--x = 0;121}122*x = (*x << 4) | (h & 0xf);123}124if (!havedig)125return STRTOG_NaN;126if (x < x1 && i < 8)127L_shift(x, x1, i);128if (x > x0) {129x1 = x0;130do *x1++ = *x++;131while(x <= xe);132do *x1++ = 0;133while(x1 <= xe);134}135else {136/* truncate high-order word if necessary */137if ( (i = nbits & (ULbits-1)) !=0)138*xe &= ((ULong)0xffffffff) >> (ULbits - i);139}140for(x1 = xe;; --x1) {141if (*x1 != 0)142break;143if (x1 == x0) {144*x1 = 1;145break;146}147}148return STRTOG_NaNbits;149}150151152