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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-newlib/] [newlib-1.17.0/] [newlib/] [libm/] [test/] [test.c] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 jlechner
#include <signal.h>
2
#include  "test.h"
3
#include <math.h>
4
#include <ieeefp.h>
5
#include <string.h>
6
int verbose;
7
static int count;
8
int inacc;
9
 
10
 
11
int
12
_DEFUN(main,(ac, av),
13
       int ac _AND
14
       char **av)
15
{
16
  int i;
17
  int math2 = 1;
18
  int string= 1;
19
  int is = 1;
20
  int math= 1;
21
  int cvt = 1;
22
  int ieee= 1;
23
bt();
24
  for (i = 1; i < ac; i++)
25
  {
26
    if (strcmp(av[i],"-v")==0)
27
     verbose ++;
28
    if (strcmp(av[i],"-nomath2") == 0)
29
     math2 = 0;
30
    if (strcmp(av[i],"-nostrin") == 0)
31
     string= 0;
32
    if (strcmp(av[i],"-nois") == 0)
33
     is = 0;
34
    if (strcmp(av[i],"-nomath") == 0)
35
     math= 0;
36
    if (strcmp(av[i],"-nocvt") == 0)
37
     cvt = 0;
38
    if (strcmp(av[i],"-noiee") == 0)
39
     ieee= 0;
40
  }
41
  if (cvt)
42
   test_cvt();
43
 
44
  if (math2)
45
   test_math2();
46
  if (string)
47
   test_string();
48
  if (math)
49
   test_math();
50
  if (is)
51
   test_is();
52
  if (ieee)  test_ieee();
53
  printf("Tested %d functions, %d errors detected\n", count, inacc);
54
  return 0;
55
}
56
 
57
 
58
static _CONST char *iname = "foo";
59
void
60
_DEFUN(newfunc,(string),
61
       _CONST char *string)
62
{
63
  if (strcmp(iname, string))
64
  {
65
    printf("testing %s\n", string);
66
    fflush(stdout);
67
    iname = string;
68
  }
69
 
70
}
71
 
72
 
73
static int theline;
74
 
75
void line(li)
76
int li;
77
{
78
  if (verbose)
79
  {
80
    printf("  %d\n", li);
81
  }
82
  theline = li;
83
 
84
  count++;
85
}
86
 
87
 
88
 
89
int redo = 0;
90
int reduce = 0;
91
 
92
int strtod_vector = 0;
93
 
94
int
95
_DEFUN(bigger,(a,b),
96
           __ieee_double_shape_type *a  _AND
97
           __ieee_double_shape_type *b)
98
{
99
 
100
  if (a->parts.msw > b->parts.msw)
101
    {
102
 
103
      return 1;
104
    }
105
  else if (a->parts.msw == b->parts.msw)
106
    {
107
      if (a->parts.lsw > b->parts.lsw)
108
        {
109
          return 1;
110
        }
111
    }
112
  return 0;
113
}
114
 
115
 
116
 
117
/* Return the first bit different between two double numbers */
118
int
119
_DEFUN(mag_of_error,(is, shouldbe),
120
       double is _AND
121
       double shouldbe)
122
{
123
  __ieee_double_shape_type a,b;
124
  int i;
125
  int a_big;
126
  unsigned  int mask;
127
  unsigned long int __x;
128
  unsigned long int msw, lsw;
129
  a.value = is;
130
 
131
  b.value = shouldbe;
132
 
133
  if (a.parts.msw == b.parts.msw
134
      && a.parts.lsw== b.parts.lsw) return 64;
135
 
136
 
137
  /* Subtract the larger from the smaller number */
138
 
139
  a_big = bigger(&a, &b);
140
 
141
  if (!a_big) {
142
    int t;
143
    t = a.parts.msw;
144
    a.parts.msw = b.parts.msw;
145
    b.parts.msw = t;
146
 
147
    t = a.parts.lsw;
148
    a.parts.lsw = b.parts.lsw;
149
    b.parts.lsw = t;
150
  }
151
 
152
 
153
 
154
  __x = (a.parts.lsw) - (b.parts.lsw);
155
  msw = (a.parts.msw) - (b.parts.msw) - (__x > (a.parts.lsw));
156
  lsw = __x;
157
 
158
 
159
 
160
 
161
  /* Find out which bit the difference is in */
162
  mask = 0x80000000;
163
  for (i = 0; i < 32; i++)
164
  {
165
    if (((msw) & mask)!=0) return i;
166
    mask >>=1;
167
  }
168
 
169
  mask = 0x80000000;
170
  for (i = 0; i < 32; i++)
171
  {
172
 
173
    if (((lsw) & mask)!=0) return i+32;
174
    mask >>=1;
175
  }
176
 
177
  return 64;
178
 
179
}
180
 
181
 int ok_mag;
182
 
183
 
184
 
185
void
186
_DEFUN(test_sok,(is, shouldbe),
187
       char *is _AND
188
       char *shouldbe)
189
{
190
  if (strcmp(is,shouldbe))
191
    {
192
    printf("%s:%d, inacurate answer: (%s should be %s)\n",
193
           iname,
194
           theline,
195
           is, shouldbe);
196
    inacc++;
197
  }
198
}
199
void
200
_DEFUN(test_iok,(is, shouldbe),
201
       int is _AND
202
       int shouldbe)
203
{
204
  if (is != shouldbe){
205
    printf("%s:%d, inacurate answer: (%08x should be %08x)\n",
206
           iname,
207
           theline,
208
           is, shouldbe);
209
    inacc++;
210
  }
211
}
212
 
213
 
214
/* Compare counted strings upto a certain length - useful to test single
215
   prec float conversions against double results
216
*/
217
void
218
_DEFUN(test_scok,(is, shouldbe, count),
219
       char *is _AND
220
       char *shouldbe _AND
221
       int count)
222
{
223
  if (strncmp(is,shouldbe, count))
224
    {
225
    printf("%s:%d, inacurate answer: (%s should be %s)\n",
226
           iname,
227
           theline,
228
           is, shouldbe);
229
    inacc++;
230
  }
231
}
232
 
233
void
234
_DEFUN(test_eok,(is, shouldbe),
235
       int is _AND
236
       int shouldbe)
237
{
238
  if (is != shouldbe){
239
    printf("%s:%d, bad errno answer: (%d should be %d)\n",
240
           iname,
241
           theline,
242
           is, shouldbe);
243
    inacc++;
244
  }
245
}
246
 
247
void
248
_DEFUN(test_mok,(value, shouldbe, okmag),
249
       double value _AND
250
       double shouldbe _AND
251
       int okmag)
252
{
253
  __ieee_double_shape_type a,b;
254
  int mag = mag_of_error(value, shouldbe);
255
  if (mag == 0)
256
  {
257
    /* error in the first bit is ok if the numbers are both 0 */
258
    if (value == 0.0 && shouldbe == 0.0)
259
     return;
260
 
261
  }
262
  a.value = shouldbe;
263
  b.value = value;
264
 
265
  if (mag < okmag)
266
  {
267
    printf("%s:%d, wrong answer: bit %d ",
268
           iname,
269
           theline,
270
           mag);
271
     printf("%08x%08x %08x%08x) ",
272
            a.parts.msw,             a.parts.lsw,
273
            b.parts.msw,             b.parts.lsw);
274
    printf("(%g %g)\n",   a.value, b.value);
275
    inacc++;
276
  }
277
}
278
 
279
#ifdef __PCCNECV70__
280
kill() {}
281
getpid() {}
282
#endif
283
 
284
bt(){
285
 
286
  double f1,f2;
287
  f1 = 0.0;
288
  f2 = 0.0/f1;
289
  printf("(%g)\n", f2);
290
 
291
}

powered by: WebSVN 2.1.0

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