source: trunk/Softwares/Common/src/c/func_factoriel.c @ 108

Last change on this file since 108 was 108, checked in by rosiere, 15 years ago

1) decod_queue : add reg_LAST_SLOT.
2) Commit : insert on event -> to pop decod_queue. Head test : add information (speculative or not)
3) Context State / UPT : Branch miss and Load miss in same cycle.
4) Free List : Bank is on LSB not MSB.
5) Platforms : move data

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1#include "func_factoriel.h"
2#include "func_math.h"
3#include "func_io.h"
4
5//-----[ Factoriel ]-------------------------------------------------------
6
7unsigned int factoriel_recursif (unsigned int x)
8{
9  if ( x <= 1)
10    return 1;
11
12  unsigned int res = mul_soft (x , factoriel_recursif (x-1));
13 
14  return res;
15}
16
17unsigned int factoriel_iteratif (unsigned int x)
18{
19  unsigned int res= 1;
20 
21  while (x > 1)
22    {
23      res = mul_soft(res,x);
24      x --;
25    }
26  return res;
27}
28
29//-------------------------------------------------------------------------
30//-----[ Test ]------------------------------------------------------------
31//-------------------------------------------------------------------------
32
33void test_factoriel_iteratif (int x)
34{
35  int x_min = 0;
36  int x_max = 12;
37  int wait [x_max+1];
38
39  wait[0]  = 1;         // 1
40  wait[1]  = 1;         // 1
41  wait[2]  = 2;         // 2
42  wait[3]  = 6;         // 6
43  wait[4]  = 24;        // 18
44  wait[5]  = 120;       // 78
45  wait[6]  = 720;       // 2d0
46  wait[7]  = 5040;      // 13b0
47  wait[8]  = 40320;     // 9d80
48  wait[9]  = 362880;    // 58980
49  wait[10] = 3628800;   // 375f00
50  wait[11] = 39916800;  // 2611500
51  wait[12] = 479001600; // 1c8cfc00
52 
53  for (int i = x_min; i <= ((x<x_max)?x:x_max); i ++)
54    if (factoriel_iteratif (i) != wait[i]) quit(i+1);
55}
56
57void test_factoriel_recursif (int x)
58{
59  int x_min = 0;
60  int x_max = 12;
61  int wait [x_max+1];
62
63  wait[0]  = 1;         // 1
64  wait[1]  = 1;         // 1
65  wait[2]  = 2;         // 2
66  wait[3]  = 6;         // 6
67  wait[4]  = 24;        // 18
68  wait[5]  = 120;       // 78
69  wait[6]  = 720;       // 2d0
70  wait[7]  = 5040;      // 13b0
71  wait[8]  = 40320;     // 9d80
72  wait[9]  = 362880;    // 58980
73  wait[10] = 3628800;   // 375f00
74  wait[11] = 39916800;  // 2611500
75  wait[12] = 479001600; // 1c8cfc00
76 
77  for (int i = x_min; i <= ((x<x_max)?x:x_max); i ++)
78    if (factoriel_recursif (i) != wait[i]) quit(i+1);
79}
Note: See TracBrowser for help on using the repository browser.