Subversion Repositories Kolibri OS

Rev

Rev 4874 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/****************************************************************
2
 
3
The author of this software is David M. Gay.
4
 
5
Copyright (C) 2000 by Lucent Technologies
6
All Rights Reserved
7
 
8
Permission to use, copy, modify, and distribute this software and
9
its documentation for any purpose and without fee is hereby
10
granted, provided that the above copyright notice appear in all
11
copies and that both that the copyright notice and this
12
permission notice and warranty disclaimer appear in supporting
13
documentation, and that the name of Lucent or any of its entities
14
not be used in advertising or publicity pertaining to
15
distribution of the software without specific, written prior
16
permission.
17
 
18
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25
THIS SOFTWARE.
26
 
27
****************************************************************/
28
 
29
/* Please send bug reports to
30
	David M. Gay
31
	Bell Laboratories, Room 2C-463
32
	600 Mountain Avenue
33
	Murray Hill, NJ 07974-0636
34
	U.S.A.
35
	dmg@bell-labs.com
36
 */
37
 
38
/* Modified 06-21-2006 by Jeff Johnston to work with newlib.  */
39
 
40
#include <_ansi.h>
41
#include 
42
#include 
43
#include "mprec.h"
44
#include "gdtoa.h"
45
 
46
#ifdef INFNAN_CHECK
47
static void
48
_DEFUN (L_shift, (x, x1, i),
49
	__ULong *x _AND
50
	__ULong *x1 _AND
51
	int i)
52
{
53
	int j;
54
 
55
	i = 8 - i;
56
	i <<= 2;
57
	j = ULbits - i;
58
	do {
59
		*x |= x[1] << j;
60
		x[1] >>= i;
61
		} while(++x < x1);
62
}
63
 
64
int
65
_DEFUN (hexnan, (sp, fpi, x0),
66
	_CONST char **sp _AND
4921 Serge 67
	_CONST FPI *fpi _AND
4349 Serge 68
	__ULong *x0)
69
{
70
	__ULong c, h, *x, *x1, *xe;
71
	_CONST char *s;
72
	int havedig, hd0, i, nbits;
73
 
74
	nbits = fpi->nbits;
75
	x = x0 + (nbits >> kshift);
76
	if (nbits & kmask)
77
		x++;
78
	*--x = 0;
79
	x1 = xe = x;
80
	havedig = hd0 = i = 0;
81
	s = *sp;
82
	while((c = *(_CONST unsigned char*)++s)) {
4921 Serge 83
		if (!(h = __get_hexdig(c))) {
4349 Serge 84
			if (c <= ' ') {
85
				if (hd0 < havedig) {
86
					if (x < x1 && i < 8)
87
						L_shift(x, x1, i);
88
					if (x <= x0) {
89
						i = 8;
90
						continue;
91
						}
92
					hd0 = havedig;
93
					*--x = 0;
94
					x1 = x;
95
					i = 0;
96
					}
97
				continue;
98
				}
99
			if (/*(*/ c == ')') {
100
				*sp = s + 1;
101
				break;
102
				}
103
			return STRTOG_NaN;
104
			}
105
		havedig++;
106
		if (++i > 8) {
107
			if (x <= x0)
108
				continue;
109
			i = 1;
110
			*--x = 0;
111
			}
112
		*x = ((*x << 4) | (h & 0xf));
113
		}
114
	if (!havedig)
115
		return STRTOG_NaN;
116
	if (x < x1 && i < 8)
117
		L_shift(x, x1, i);
118
	if (x > x0) {
119
		x1 = x0;
120
		do *x1++ = *x++;
121
			while(x <= xe);
122
		do *x1++ = 0;
123
			while(x1 <= xe);
124
		}
125
	else {
126
		/* truncate high-order word if necessary */
127
		if ( (i = nbits & (ULbits-1)) !=0)
128
			*xe &= ((__ULong)0xffffffff) >> (ULbits - i);
129
		}
130
	for(x1 = xe;; --x1) {
131
		if (*x1 != 0)
132
			break;
133
		if (x1 == x0) {
134
			*x1 = 1;
135
			break;
136
			}
137
		}
138
	return STRTOG_NaNbits;
139
}
140
#endif /* INFNAN_CHECK */