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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [math.c] - Blame information for rev 437

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

Line No. Rev Author Line
1 138 rhoads
/*--------------------------------------------------------------------
2
 * TITLE: Plasma Floating Point Library
3
 * AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
 * DATE CREATED: 3/2/06
5
 * FILENAME: math.c
6
 * PROJECT: Plasma CPU core
7
 * COPYRIGHT: Software placed into the public domain by the author.
8
 *    Software 'as is' without warranty.  Author liable for nothing.
9
 * DESCRIPTION:
10
 *    Plasma Floating Point Library
11
 *--------------------------------------------------------------------
12
 * IEEE_fp = sign(1) | exponent(8) | fraction(23)
13
 * cos(x)=1-x^2/2!+x^4/4!-x^6/6!+...
14
 * exp(x)=1+x+x^2/2!+x^3/3!+...
15 436 rhoads
 * e^x=2^y; ln2(e^x)=ln2(2^y); ln(e^x)/ln(2)=y; x/ln(2)=y; e^x=2^(x/ln(2))
16 138 rhoads
 * ln(1+x)=x-x^2/2+x^3/3-x^4/4+...
17
 * atan(x)=x-x^3/3+x^5/5-x^7/7+...
18
 * pow(x,y)=exp(y*ln(x))
19
 * x=tan(a+b)=(tan(a)+tan(b))/(1-tan(a)*tan(b))
20
 * atan(x)=b+atan((x-atan(b))/(1+x*atan(b)))
21
 * ln(a*x)=ln(a)+ln(x); ln(x^n)=n*ln(x)
22 436 rhoads
 * sqrt(x)=sqrt(f*2^e)=sqrt(f)*2^(e/2)
23 138 rhoads
 *--------------------------------------------------------------------*/
24
#include "rtos.h"
25
 
26 195 rhoads
//#define USE_SW_MULT
27
#if !defined(WIN32) && !defined(USE_SW_MULT)
28
#define USE_MULT64
29
#endif
30
 
31 138 rhoads
#define PI ((float)3.1415926)
32
#define PI_2 ((float)(PI/2.0))
33
#define PI2 ((float)(PI*2.0))
34
 
35
#define FtoL(X) (*(unsigned long*)&(X))
36
#define LtoF(X) (*(float*)&(X))
37
 
38
 
39
float FP_Neg(float a_fp)
40
{
41
   unsigned long a;
42
   a = FtoL(a_fp);
43
   a ^= 0x80000000;
44
   return LtoF(a);
45
}
46
 
47
 
48
float FP_Add(float a_fp, float b_fp)
49
{
50
   unsigned long a, b, c;
51
   unsigned long as, bs, cs;     //sign
52
   long ae, af, be, bf, ce, cf;  //exponent and fraction
53
   a = FtoL(a_fp);
54
   b = FtoL(b_fp);
55
   as = a >> 31;                        //sign
56
   ae = (a >> 23) & 0xff;               //exponent
57
   af = 0x00800000 | (a & 0x007fffff);  //fraction
58
   bs = b >> 31;
59
   be = (b >> 23) & 0xff;
60
   bf = 0x00800000 | (b & 0x007fffff);
61
   if(ae > be)
62
   {
63
      if(ae - be < 30)
64
         bf >>= ae - be;
65
      else
66
         bf = 0;
67
      ce = ae;
68
   }
69
   else
70
   {
71
      if(be - ae < 30)
72
         af >>= be - ae;
73
      else
74
         af = 0;
75
      ce = be;
76
   }
77
   cf = (as ? -af : af) + (bs ? -bf : bf);
78
   cs = cf < 0;
79
   cf = cf>=0 ? cf : -cf;
80
   if(cf == 0)
81
      return LtoF(cf);
82
   while(cf & 0xff000000)
83
   {
84
      ++ce;
85
      cf >>= 1;
86
   }
87
   while((cf & 0xff800000) == 0)
88
   {
89
      --ce;
90
      cf <<= 1;
91
   }
92
   c = (cs << 31) | (ce << 23) | (cf & 0x007fffff);
93
   if(ce < 1)
94
      c = 0;
95
   return LtoF(c);
96
}
97
 
98
 
99
float FP_Sub(float a_fp, float b_fp)
100
{
101
   return FP_Add(a_fp, FP_Neg(b_fp));
102
}
103
 
104
 
105
float FP_Mult(float a_fp, float b_fp)
106
{
107
   unsigned long a, b, c;
108
   unsigned long as, af, bs, bf, cs, cf;
109
   long ae, be, ce;
110 195 rhoads
#ifndef USE_MULT64
111 138 rhoads
   unsigned long a2, a1, b2, b1, med1, med2;
112
#endif
113
   unsigned long hi, lo;
114
   a = FtoL(a_fp);
115
   b = FtoL(b_fp);
116
   as = a >> 31;
117
   ae = (a >> 23) & 0xff;
118
   af = 0x00800000 | (a & 0x007fffff);
119
   bs = b >> 31;
120
   be = (b >> 23) & 0xff;
121
   bf = 0x00800000 | (b & 0x007fffff);
122
   cs = as ^ bs;
123 195 rhoads
#ifndef USE_MULT64
124 138 rhoads
   a1 = af & 0xffff;
125
   a2 = af >> 16;
126
   b1 = bf & 0xffff;
127
   b2 = bf >> 16;
128
   lo = a1 * b1;
129
   med1 = a2 * b1 + (lo >> 16);
130
   med2 = a1 * b2;
131
   hi = a2 * b2 + (med1 >> 16) + (med2 >> 16);
132
   med1 = (med1 & 0xffff) + (med2 & 0xffff);
133
   hi += (med1 >> 16);
134
   lo = (med1 << 16) | (lo & 0xffff);
135
#else
136
   lo = OS_AsmMult(af, bf, &hi);
137
#endif
138
   cf = (hi << 9) | (lo >> 23);
139
   ce = ae + be - 0x80 + 1;
140
   if(cf == 0)
141
      return LtoF(cf);
142
   while(cf & 0xff000000)
143
   {
144
      ++ce;
145
      cf >>= 1;
146
   }
147
   c = (cs << 31) | (ce << 23) | (cf & 0x007fffff);
148
   if(ce < 1)
149
      c = 0;
150
   return LtoF(c);
151
}
152
 
153
 
154
float FP_Div(float a_fp, float b_fp)
155
{
156
   unsigned long a, b, c;
157
   unsigned long as, af, bs, bf, cs, cf;
158
   unsigned long a1, b1;
159 195 rhoads
#ifndef USE_MULT64
160 138 rhoads
   unsigned long a2, b2, med1, med2;
161
#endif
162
   unsigned long hi, lo;
163
   long ae, be, ce, d;
164
   a = FtoL(a_fp);
165
   b = FtoL(b_fp);
166
   as = a >> 31;
167
   ae = (a >> 23) & 0xff;
168
   af = 0x00800000 | (a & 0x007fffff);
169
   bs = b >> 31;
170
   be = (b >> 23) & 0xff;
171
   bf = 0x00800000 | (b & 0x007fffff);
172
   cs = as ^ bs;
173
   ce = ae - (be - 0x80) + 6 - 8;
174
   a1 = af << 4; //8
175
   b1 = bf >> 8;
176
   cf = a1 / b1;
177
   cf <<= 12; //8
178
#if 1                  /*non-quick*/
179 195 rhoads
#ifndef USE_MULT64
180 138 rhoads
   a1 = cf & 0xffff;
181
   a2 = cf >> 16;
182
   b1 = bf & 0xffff;
183
   b2 = bf >> 16;
184
   lo = a1 * b1;
185
   med1 =a2 * b1 + (lo >> 16);
186
   med2 = a1 * b2;
187
   hi = a2 * b2 + (med1 >> 16) + (med2 >> 16);
188
   med1 = (med1 & 0xffff) + (med2 & 0xffff);
189
   hi += (med1 >> 16);
190
   lo = (med1 << 16) | (lo & 0xffff);
191
#else
192
   lo = OS_AsmMult(cf, bf, &hi);
193
#endif
194
   lo = (hi << 8) | (lo >> 24);
195
   d = af - lo;    //remainder
196
   assert(-0xffff < d && d < 0xffff);
197
   d <<= 16;
198
   b1 = bf >> 8;
199
   d = d / (long)b1;
200
   cf += d;
201
#endif
202
   if(cf == 0)
203
      return LtoF(cf);
204
   while(cf & 0xff000000)
205
   {
206
      ++ce;
207
      cf >>= 1;
208
   }
209
   if(ce < 0)
210
      ce = 0;
211
   c = (cs << 31) | (ce << 23) | (cf & 0x007fffff);
212
   if(ce < 1)
213
      c = 0;
214
   return LtoF(c);
215
}
216
 
217
 
218
long FP_ToLong(float a_fp)
219
{
220
   unsigned long a;
221
   unsigned long as;
222
   long ae;
223
   long af, shift;
224
   a = FtoL(a_fp);
225
   as = a >> 31;
226
   ae = (a >> 23) & 0xff;
227
   af = 0x00800000 | (a & 0x007fffff);
228
   af <<= 7;
229
   shift = -(ae - 0x80 - 29);
230
   if(shift > 0)
231
   {
232
      if(shift < 31)
233
         af >>= shift;
234
      else
235
         af = 0;
236
   }
237
   af = as ? -af: af;
238
   return af;
239
}
240
 
241
 
242
float FP_ToFloat(long af)
243
{
244
   unsigned long a;
245
   unsigned long as, ae;
246
   as = af>=0 ? 0: 1;
247
   af = af>=0 ? af: -af;
248
   ae = 0x80 + 22;
249
   if(af == 0)
250
      return LtoF(af);
251
   while(af & 0xff000000)
252
   {
253
      ++ae;
254
      af >>= 1;
255
   }
256
   while((af & 0xff800000) == 0)
257
   {
258
      --ae;
259
      af <<= 1;
260
   }
261
   a = (as << 31) | (ae << 23) | (af & 0x007fffff);
262
   return LtoF(a);
263
}
264
 
265
 
266
//0 iff a==b; 1 iff a>b; -1 iff a<b
267
int FP_Cmp(float a_fp, float b_fp)
268
{
269
   unsigned long a, b;
270
   unsigned long as, ae, af, bs, be, bf;
271
   int gt;
272
   a = FtoL(a_fp);
273
   b = FtoL(b_fp);
274
   if(a == b)
275
      return 0;
276
   as = a >> 31;
277
   bs = b >> 31;
278
   if(as > bs)
279
      return -1;
280
   if(as < bs)
281
      return 1;
282
   gt = as ? -1 : 1;
283
   ae = (a >> 23) & 0xff;
284
   be = (b >> 23) & 0xff;
285
   if(ae > be)
286
      return gt;
287
   if(ae < be)
288
      return -gt;
289
   af = 0x00800000 | (a & 0x007fffff);
290
   bf = 0x00800000 | (b & 0x007fffff);
291
   if(af > bf)
292
      return gt;
293
   return -gt;
294
}
295
 
296
 
297
int __ltsf2(float a, float b)
298
{
299
   return FP_Cmp(a, b);
300
}
301
 
302
int __lesf2(float a, float b)
303
{
304
   return FP_Cmp(a, b);
305
}
306
 
307
int __gtsf2(float a, float b)
308
{
309
   return FP_Cmp(a, b);
310
}
311
 
312
int __gesf2(float a, float b)
313
{
314
   return FP_Cmp(a, b);
315
}
316
 
317
int __eqsf2(float a, float b)
318
{
319
   return FtoL(a) != FtoL(b);
320
}
321
 
322
int __nesf2(float a, float b)
323
{
324
   return FtoL(a) != FtoL(b);
325
}
326
 
327
 
328
float FP_Sqrt(float a)
329
{
330
   float x1, y1, x2, y2, x3;
331
   long i;
332
   x1 = FP_ToFloat(1);
333
   y1 = FP_Sub(FP_Mult(x1, x1), a);  //y1=x1*x1-a;
334
   x2 = FP_ToFloat(100);
335
   y2 = FP_Sub(FP_Mult(x2, x2), a);
336
   for(i = 0; i < 10; ++i)
337
   {
338
      if(FtoL(y1) == FtoL(y2))
339
         return x2;
340
      //x3=x2-(x1-x2)*y2/(y1-y2);
341
      x3 = FP_Sub(x2, FP_Div(FP_Mult(FP_Sub(x1, x2), y2), FP_Sub(y1, y2)));
342
      x1 = x2;
343
      y1 = y2;
344
      x2 = x3;
345
      y2 = FP_Sub(FP_Mult(x2, x2), a);
346
   }
347
   return x2;
348
}
349
 
350
 
351
float FP_Cos(float rad)
352
{
353
   int n;
354
   float answer, x2, top, bottom, sign;
355
   while(FP_Cmp(rad, PI2) > 0)
356
      rad = FP_Sub(rad, PI2);
357
   while(FP_Cmp(rad, (float)0.0) < 0)
358
      rad = FP_Add(rad, PI2);
359 436 rhoads
   answer = (float)1.0;
360
   sign = (float)1.0;
361 138 rhoads
   if(FP_Cmp(rad, PI) >= 0)
362
   {
363
      rad = FP_Sub(rad, PI);
364
      sign = FP_ToFloat(-1);
365
   }
366
   if(FP_Cmp(rad, PI_2) >= 0)
367
   {
368
      rad = FP_Sub(PI, rad);
369
      sign = FP_Neg(sign);
370
   }
371
   x2 = FP_Mult(rad, rad);
372 436 rhoads
   top = (float)1.0;
373
   bottom = (float)1.0;
374 138 rhoads
   for(n = 2; n < 12; n += 2)
375
   {
376
      top = FP_Mult(top, FP_Neg(x2));
377
      bottom = FP_Mult(bottom, FP_ToFloat((n - 1) * n));
378
      answer = FP_Add(answer, FP_Div(top, bottom));
379
   }
380
   return FP_Mult(answer, sign);
381
}
382
 
383
 
384
float FP_Sin(float rad)
385
{
386
   const float pi_2=(float)(PI/2.0);
387
   return FP_Cos(FP_Sub(rad, pi_2));
388
}
389
 
390
 
391
float FP_Atan(float x)
392
{
393
   const float b=(float)(PI/8.0);
394
   const float atan_b=(float)0.37419668; //atan(b);
395
   int n;
396
   float answer, x2, top;
397
   if(FP_Cmp(x, (float)0.0) >= 0)
398
   {
399
      if(FP_Cmp(x, (float)1.0) > 0)
400
         return FP_Sub(PI_2, FP_Atan(FP_Div((float)1.0, x)));
401
   }
402
   else
403
   {
404
      if(FP_Cmp(x, (float)-1.0) > 0)
405
         return FP_Sub(-PI_2, FP_Atan(FP_Div((float)1.0, x)));
406
   }
407
   if(FP_Cmp(x, (float)0.45) > 0)
408
   {
409
      //answer = (x - atan_b) / (1 + x * atan_b);
410
      answer = FP_Div(FP_Sub(x, atan_b), FP_Add(1.0, FP_Mult(x, atan_b)));
411
      //answer = b + FP_Atan(answer) - (float)0.034633; /*FIXME fudge?*/
412
      answer = FP_Sub(FP_Add(b, FP_Atan(answer)), (float)0.034633);
413
      return answer;
414
   }
415
   if(FP_Cmp(x, (float)-0.45) < 0)
416
   {
417
      x = FP_Neg(x);
418
      //answer = (x - atan_b) / (1 + x * atan_b);
419
      answer = FP_Div(FP_Sub(x, atan_b), FP_Add(1.0, FP_Mult(x, atan_b)));
420
      //answer = b + FP_Atan(answer) - (float)0.034633; /*FIXME*/
421
      answer = FP_Sub(FP_Add(b, FP_Atan(answer)), (float)0.034633);
422
      return FP_Neg(answer);
423
   }
424
   answer = x;
425
   x2 = FP_Mult(FP_Neg(x), x);
426
   top = x;
427
   for(n = 3; n < 14; n += 2)
428
   {
429
      top = FP_Mult(top, x2);
430
      answer = FP_Add(answer, FP_Div(top, FP_ToFloat(n)));
431
   }
432
   return answer;
433
}
434
 
435
 
436
float FP_Atan2(float y, float x)
437
{
438
   float answer,r;
439
   r = y / x;
440
   answer = FP_Atan(r);
441
   if(FP_Cmp(x, (float)0.0) < 0)
442
   {
443
      if(FP_Cmp(y, (float)0.0) > 0)
444
         answer = FP_Add(answer, PI);
445
      else
446
         answer = FP_Sub(answer, PI);
447
   }
448
   return answer;
449
}
450
 
451
 
452
float FP_Exp(float x)
453
{
454
   const float e2=(float)7.389056099;
455
   const float inv_e2=(float)0.135335283;
456
   float answer, top, bottom, mult;
457
   int n;
458
 
459 436 rhoads
   mult = (float)1.0;
460 138 rhoads
   while(FP_Cmp(x, (float)2.0) > 0)
461
   {
462
      mult = FP_Mult(mult, e2);
463
      x = FP_Add(x, (float)-2.0);
464
   }
465
   while(FP_Cmp(x, (float)-2.0) < 0)
466
   {
467
      mult = FP_Mult(mult, inv_e2);
468
      x = FP_Add(x, (float)2.0);
469
   }
470
   answer = FP_Add((float)1.0, x);
471
   top = x;
472 436 rhoads
   bottom = (float)1.0;
473 138 rhoads
   for(n = 2; n < 15; ++n)
474
   {
475
      top = FP_Mult(top, x);
476
      bottom = FP_Mult(bottom, FP_ToFloat(n));
477
      answer = FP_Add(answer, FP_Div(top, bottom));
478
   }
479
   return FP_Mult(answer, mult);
480
}
481
 
482
 
483
float FP_Log(float x)
484
{
485
   const float log_2=(float)0.69314718; /*log(2.0)*/
486
   int n;
487
   float answer, top, add;
488 436 rhoads
   add = (float)0.0;
489
   while(FP_Cmp(x, (float)16.0) > 0)
490 138 rhoads
   {
491
      x = FP_Mult(x, (float)0.0625);
492
      add = FP_Add(add, (float)(log_2 * 4));
493
   }
494 436 rhoads
   while(FP_Cmp(x, (float)1.5) > 0)
495 138 rhoads
   {
496 436 rhoads
      x = FP_Mult(x, (float)0.5);
497 138 rhoads
      add = FP_Add(add, log_2);
498
   }
499
   while(FP_Cmp(x, 0.5) < 0)
500
   {
501 436 rhoads
      x = FP_Mult(x, (float)2.0);
502 138 rhoads
      add = FP_Sub(add, log_2);
503
   }
504 436 rhoads
   x = FP_Sub(x, (float)1.0);
505
   answer = (float)0.0;
506
   top = (float)-1.0;
507 138 rhoads
   for(n = 1; n < 14; ++n)
508
   {
509
      top = FP_Mult(top, FP_Neg(x));
510
      answer = FP_Add(answer, FP_Div(top, FP_ToFloat(n)));
511
   }
512
   return FP_Add(answer, add);
513
}
514
 
515
 
516
float FP_Pow(float x, float y)
517
{
518
   return FP_Exp(y * FP_Log(x));
519
}
520
 
521
 
522 195 rhoads
/********************************************/
523
//These five functions will only be used if the flag "-mno-mul" is enabled
524
#ifdef USE_SW_MULT
525
unsigned long __mulsi3(unsigned long a, unsigned long b)
526
{
527
   unsigned long answer = 0;
528 197 rhoads
   while(b)
529 195 rhoads
   {
530
      if(b & 1)
531
         answer += a;
532
      a <<= 1;
533
      b >>= 1;
534
   }
535
   return answer;
536
}
537
 
538
 
539
static unsigned long DivideMod(unsigned long a, unsigned long b, int doMod)
540
{
541
   unsigned long upper=a, lower=0;
542
   int i;
543
   a = b << 31;
544
   for(i = 0; i < 32; ++i)
545
   {
546
      lower = lower << 1;
547
      if(upper >= a && a && b < 2)
548
      {
549
         upper = upper - a;
550
         lower |= 1;
551
      }
552
      a = ((b&2) << 30) | (a >> 1);
553
      b = b >> 1;
554
   }
555
   if(!doMod)
556
      return lower;
557
   return upper;
558
}
559
 
560
 
561
unsigned long __udivsi3(unsigned long a, unsigned long b)
562
{
563
   return DivideMod(a, b, 0);
564
}
565
 
566
 
567
long __divsi3(long a, long b)
568
{
569
   long answer, negate=0;
570
   if(a < 0)
571
   {
572
      a = -a;
573
      negate = !negate;
574
   }
575
   if(b < 0)
576
   {
577
      b = -b;
578
      negate = !negate;
579
   }
580
   answer = DivideMod(a, b, 0);
581
   if(negate)
582
      answer = -answer;
583
   return answer;
584
}
585
 
586
 
587
unsigned long __umodsi3(unsigned long a, unsigned long b)
588
{
589
   return DivideMod(a, b, 1);
590
}
591
#endif
592
 
593
 
594 138 rhoads
/*************** Test *****************/
595
#ifdef WIN32
596 336 rhoads
#undef _LIBC
597 138 rhoads
#include <math.h>
598
struct {
599
   char *name;
600
   float low, high;
601
   double (*func1)(double);
602
   float (*func2)(float);
603
} test_info[]={
604
   {"cos", -2*PI, 2*PI, cos, FP_Cos},
605
   {"sin", -2*PI, 2*PI, sin, FP_Sin},
606
   {"atan", -3.0, 2.0, atan, FP_Atan},
607
   {"log", (float)0.01, (float)4.0, log, FP_Log},
608
   {"exp", (float)-5.01, (float)30.0, exp, FP_Exp},
609
   {"sqrt", (float)0.01, (float)1000.0, sqrt, FP_Sqrt}
610
};
611
 
612
 
613
void TestMathFull(void)
614
{
615
   float a, b, c, d;
616
   float error1, error2, error3, error4, error5;
617
   int test;
618
 
619
   a = PI * PI;
620
   b = PI;
621
   c = FP_Div(a, b);
622
   printf("%10f %10f %10f %10f %10f\n",
623
      (double)a, (double)b, (double)(a/b), (double)c, (double)(a/b-c));
624
   a = a * 200;
625
   for(b = -(float)2.718281828*100; b < 300; b += (float)23.678)
626
   {
627
      c = FP_Div(a, b);
628
      d = a / b - c;
629
      printf("%10f %10f %10f %10f %10f\n",
630
         (double)a, (double)b, (double)(a/b), (double)c, (double)(a/b-c));
631
   }
632 302 rhoads
   //getch();
633 138 rhoads
 
634
   for(test = 0; test < 6; ++test)
635
   {
636
      printf("\nTesting %s\n", test_info[test].name);
637
      for(a = test_info[test].low;
638
          a <= test_info[test].high;
639
          a += (test_info[test].high-test_info[test].low)/(float)20.0)
640
      {
641
         b = (float)test_info[test].func1(a);
642
         c = test_info[test].func2(a);
643
         d = b - c;
644
         printf("%s %10f %10f %10f %10f\n", test_info[test].name, a, b, c, d);
645
      }
646 302 rhoads
      //getch();
647 138 rhoads
   }
648
 
649
   a = FP_ToFloat((long)6.0);
650
   b = FP_ToFloat((long)2.0);
651
   printf("%f %f\n", (double)a, (double)b);
652
   c = FP_Add(a, b);
653
   printf("add %f %f\n", (double)(a + b), (double)c);
654
   c = FP_Sub(a, b);
655
   printf("sub %f %f\n", (double)(a - b), (double)c);
656
   c = FP_Mult(a, b);
657
   printf("mult %f %f\n", (double)(a * b), (double)c);
658
   c = FP_Div(a, b);
659
   printf("div %f %f\n", (double)(a / b), (double)c);
660 302 rhoads
   //getch();
661 138 rhoads
 
662
   for(a = (float)-13756.54; a < (float)17400.0; a += (float)64.45)
663
   {
664
      for(b = (float)-875.36; b < (float)935.8; b += (float)36.7)
665
      {
666
         error1 = (float)1.0 - (a + b) / FP_Add(a, b);
667
         error2 = (float)1.0 - (a * b) / FP_Mult(a, b);
668
         error3 = (float)1.0 - (a / b) / FP_Div(a, b);
669
         error4 = (float)1.0 - a / FP_ToFloat(FP_ToLong(a));
670
         error5 = error1 + error2 + error3 + error4;
671
         if(error5 < 0.00005)
672
            continue;
673
         printf("ERROR!\n");
674
         printf("a=%f b=%f\n", (double)a, (double)b);
675
         printf("  a+b=%f %f\n", (double)(a+b), (double)FP_Add(a, b));
676
         printf("  a*b=%f %f\n", (double)(a*b), (double)FP_Mult(a, b));
677
         printf("  a/b=%f %f\n", (double)(a/b), (double)FP_Div(a, b));
678
         printf("  a=%f %ld %f\n", (double)a, FP_ToLong(a),
679
                                   (double)FP_ToFloat((long)a));
680
         printf("  %f %f %f %f\n", (double)error1, (double)error2,
681
            (double)error3, (double)error4);
682 302 rhoads
         //if(error5 > 0.001) 
683
         //   getch();
684 138 rhoads
      }
685
   }
686
   printf("done.\n");
687 302 rhoads
   //getch();
688 138 rhoads
}
689
#endif
690
 
691
 

powered by: WebSVN 2.1.0

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