Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
smisc.c File Reference
#include "gdtoaimp.h"
Include dependency graph for smisc.c:

Go to the source code of this file.

Functions

Bigints2b (CONST char *s, int nd0, int nd, ULong y9)
 
double ratio (Bigint *a, Bigint *b)
 
void copybits (ULong *c, int n, Bigint *b)
 
ULong any_on (Bigint *b, int k)
 

Function Documentation

◆ any_on()

ULong any_on ( Bigint b,
int  k 
)

Definition at line 210 of file smisc.c.

212 {
213  int n, nwds;
214  ULong *x, *x0, x1, x2;
215 
216  x = b->x;
217  nwds = b->wds;
218  n = k >> kshift;
219  if(n > nwds)
220  {
221  {
222  n = nwds;
223  }
224  }
225  else if(n < nwds && (k &= kmask))
226  {
227  x1 = x2 = x[n];
228  x1 >>= k;
229  x1 <<= k;
230  if(x1 != x2)
231  {
232  {
233  return 1;
234  }
235  }
236  }
237  x0 = x;
238  x += n;
239  while(x > x0)
240  {
241  {
242  if(*--x)
243  {
244  {
245  return 1;
246  }
247  }
248  }
249  }
250  return 0;
251 }
ULong x[1]
Definition: gdtoaimp.h:488
int wds
Definition: gdtoaimp.h:487
#define kshift
Definition: gdtoaimp.h:467
unsigned Long ULong
Definition: gdtoa.h:41
#define kmask
Definition: gdtoaimp.h:468

References kmask, kshift, Bigint::wds, and Bigint::x.

Referenced by gethex(), and rvOK().

◆ copybits()

void copybits ( ULong c,
int  n,
Bigint b 
)

Definition at line 171 of file smisc.c.

173 {
174  ULong *ce, *x, *xe;
175 #ifdef Pack_16
176  int nw, nw1;
177 #endif
178 
179  ce = c + ((n - 1) >> kshift) + 1;
180  x = b->x;
181 #ifdef Pack_32
182  xe = x + b->wds;
183  while(x < xe)
184  {
185  {
186  *c++ = *x++;
187  }
188  }
189 #else
190  nw = b->wds;
191  nw1 = nw & 1;
192  for(xe = x + (nw - nw1); x < xe; x += 2)
193  Storeinc(c, x[1], x[0]);
194  if(nw1)
195  *c++ = *x;
196 #endif
197  while(c < ce)
198  {
199  {
200  *c++ = 0;
201  }
202  }
203 }
ULong x[1]
Definition: gdtoaimp.h:488
int wds
Definition: gdtoaimp.h:487
#define Storeinc(a, b, c)
Definition: gdtoaimp.h:318
#define kshift
Definition: gdtoaimp.h:467
unsigned Long ULong
Definition: gdtoa.h:41

References kshift, Storeinc, Bigint::wds, and Bigint::x.

Referenced by rvOK(), strtod(), and strtodg().

◆ ratio()

double ratio ( Bigint a,
Bigint b 
)

Definition at line 96 of file smisc.c.

98 {
99  double da, db;
100  int k, ka, kb;
101 
102  dval(da) = b2d(a, &ka);
103  dval(db) = b2d(b, &kb);
104  k = ka - kb + ULbits * (a->wds - b->wds);
105 #ifdef IBM
106  if(k > 0)
107  {
108  word0(da) += (k >> 2) * Exp_msk1;
109  if(k &= 3)
110  dval(da) *= 1 << k;
111  }
112  else
113  {
114  k = -k;
115  word0(db) += (k >> 2) * Exp_msk1;
116  if(k &= 3)
117  dval(db) *= 1 << k;
118  }
119 #else
120  if(k > 0)
121  {
122  {
123  word0(da) += (unsigned)(k * Exp_msk1);
124  }
125  }
126  else
127  {
128  k = -k;
129  word0(db) += (unsigned)(k * Exp_msk1);
130  }
131 #endif
132  return dval(da) / dval(db);
133 }
int wds
Definition: gdtoaimp.h:487
#define Exp_msk1
Definition: gdtoaimp.h:396
double b2d(Bigint *a, int *e)
Definition: misc.c:724
#define dval(x)
Definition: gdtoaimp.h:307
#define word0(x)
Definition: gdtoaimp.h:304
#define ULbits
Definition: gdtoaimp.h:466

References b2d(), dval, Exp_msk1, ULbits, Bigint::wds, and word0.

Referenced by strtod(), and strtodg().

◆ s2b()

Bigint* s2b ( CONST char *  s,
int  nd0,
int  nd,
ULong  y9 
)

Definition at line 40 of file smisc.c.

42 {
43  Bigint* b;
44  int i, k;
45  Long x, y;
46 
47  x = (nd + 8) / 9;
48  for(k = 0, y = 1; x > y; y <<= 1, k++)
49  {
50  {
51  ;
52  }
53  }
54 #ifdef Pack_32
55  b = Balloc(k);
56  b->x[0] = y9;
57  b->wds = 1;
58 #else
59  b = Balloc(k + 1);
60  b->x[0] = y9 & 0xffff;
61  b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
62 #endif
63 
64  i = 9;
65  if(9 < nd0)
66  {
67  s += 9;
68  do
69  {
70  {
71  b = multadd(b, 10, *s++ - '0');
72  }
73  } while(++i < nd0);
74  s++;
75  }
76  else
77  {
78  {
79  s += 10;
80  }
81  }
82  for(; i < nd; i++)
83  {
84  {
85  b = multadd(b, 10, *s++ - '0');
86  }
87  }
88  return b;
89 }
ULong x[1]
Definition: gdtoaimp.h:488
int wds
Definition: gdtoaimp.h:487
Bigint * multadd(Bigint *b, int m, int a)
Definition: misc.c:171
Bigint * Balloc(int k)
Definition: misc.c:47
#define Long
Definition: gdtoa.h:38

References Balloc(), Long, multadd(), Bigint::wds, and Bigint::x.

Referenced by strtod(), and strtodg().