OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [stdlib/] [gdtoa-hexnan.c] - Blame information for rev 862

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/****************************************************************
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 <reent.h>
42
#include <string.h>
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
67
        FPI *fpi _AND
68
        __ULong *x0)
69
{
70
        __ULong c, h, *x, *x1, *xe;
71
        _CONST char *s;
72
        int havedig, hd0, i, nbits;
73
 
74
        if (!hexdig['0'])
75
                hexdig_init();
76
        nbits = fpi->nbits;
77
        x = x0 + (nbits >> kshift);
78
        if (nbits & kmask)
79
                x++;
80
        *--x = 0;
81
        x1 = xe = x;
82
        havedig = hd0 = i = 0;
83
        s = *sp;
84
        while((c = *(_CONST unsigned char*)++s)) {
85
                if (!(h = hexdig[c])) {
86
                        if (c <= ' ') {
87
                                if (hd0 < havedig) {
88
                                        if (x < x1 && i < 8)
89
                                                L_shift(x, x1, i);
90
                                        if (x <= x0) {
91
                                                i = 8;
92
                                                continue;
93
                                                }
94
                                        hd0 = havedig;
95
                                        *--x = 0;
96
                                        x1 = x;
97
                                        i = 0;
98
                                        }
99
                                continue;
100
                                }
101
                        if (/*(*/ c == ')') {
102
                                *sp = s + 1;
103
                                break;
104
                                }
105
                        return STRTOG_NaN;
106
                        }
107
                havedig++;
108
                if (++i > 8) {
109
                        if (x <= x0)
110
                                continue;
111
                        i = 1;
112
                        *--x = 0;
113
                        }
114
                *x = ((*x << 4) | (h & 0xf));
115
                }
116
        if (!havedig)
117
                return STRTOG_NaN;
118
        if (x < x1 && i < 8)
119
                L_shift(x, x1, i);
120
        if (x > x0) {
121
                x1 = x0;
122
                do *x1++ = *x++;
123
                        while(x <= xe);
124
                do *x1++ = 0;
125
                        while(x1 <= xe);
126
                }
127
        else {
128
                /* truncate high-order word if necessary */
129
                if ( (i = nbits & (ULbits-1)) !=0)
130
                        *xe &= ((__ULong)0xffffffff) >> (ULbits - i);
131
                }
132
        for(x1 = xe;; --x1) {
133
                if (*x1 != 0)
134
                        break;
135
                if (x1 == x0) {
136
                        *x1 = 1;
137
                        break;
138
                        }
139
                }
140
        return STRTOG_NaNbits;
141
}
142
#endif /* INFNAN_CHECK */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.