source: trunk/Softwares/Basic_test.or32/src/c/test_setjmp.c @ 2

Last change on this file since 2 was 2, checked in by kane, 17 years ago

Import Morpheo

File size: 787 bytes
Line 
1#include <setjmp.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <math.h>
5jmp_buf env;
6
7int exec_setjmp (int val_max, int base)
8{
9  int res = -2;
10  int val = setjmp(env); // 1 call = 0, first return of longjmp -> 1, après renvoye X^N
11 
12  if (val < val_max)
13    {
14      print(val);
15      res ++;
16      longjmp (env,base*val);
17    }
18 
19  return res;
20}
21
22int test_setjmp  ()
23{
24  quit(exec_setjmp (366,2));
25 
26  return (1);
27 
28  /*
29  int base = 2;
30  int val,res,it;
31 
32  srand(0);
33 
34  for (it = 0; it < 10; it ++)
35    {
36      val = (rand()%1500);
37     
38      res = exec_setjmp (val,base);
39
40      print(res);
41     
42      //printf("test_setjmp : log2(%d)=%d (%d)\n",val,res,(unsigned int)log2((double)val));
43
44      if ((unsigned int)log2(val) != res)
45        return 0;
46    }
47  return 1;
48  */
49}
Note: See TracBrowser for help on using the repository browser.