initial import
[staff/goc4/2018bti7061.git] / c-3-libraries / examples / c-functions / myFirstLibrary.c
1 #include "myFirstLibrary.h"
2
3 /* Compute the factorial of a value
4 Input : val a long integer
5 Return : val! (i.e. 1*2*3* ...* val)
6 */
7 long factorial(long val){
8 long res= 1;
9 long i;
10 for(i=1; i <= val;i++){
11 res *= i;
12 }
13 return res;
14 }
15
16 /* Compute the protected integer binary logarithm of val
17 Input: val a long integer
18 Return : an integer for binary logarithm of val
19 or 0 if val is 0
20 */
21 long logarithm(long val){
22 long res=0;
23 if(val<=1){
24 return 0;
25 }
26 while(val>1){
27 val /=2;
28 res++;
29 }
30 return res;
31 }