diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2022-09-29 16:39:09 -0400 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2022-09-29 16:39:09 -0400 |
commit | e8364e95ee1b38e49af29a2aa1338b3d978411f0 (patch) | |
tree | 042a81f77fa1ef7e7cfca831307cc76486e5731d /format.h | |
parent | c56472ceb5d46af1db39b1ac2cd822baffa3ec30 (diff) |
Trigonometry somewhat works
Diffstat (limited to 'format.h')
-rw-r--r-- | format.h | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -10,6 +10,7 @@ #define TRUE 1 #define FALSE 0 + #define COUNT_OF( arr) (sizeof(arr)/sizeof(0[arr])) // Conversion table between uppercase and lowercase @@ -20,12 +21,14 @@ const char caps[2][26] = { 'n','o','p','q','r','s','t','u','v','w','x','y','z'} }; -int pow(int b, int e){ - int result =1; - for (int i = 0; i<e; i++){ - result *= b; +float mpow(float b, int e){ + if (e==1){ + return b; + } else if (e%2==0){ + return mpow(b*b,e/2); + } else { + return b * mpow(b*b, e/2); } - return result; } float avg(float arr[]){ @@ -51,8 +54,8 @@ char * lower(char *str){ return str; } +// Count the total number of spaces to define the new str size char * trim(char *str){ - // Count the total number of spaces to define the new str size int spc =0; for (int i=0; i<COUNT_OF(str); i++){ if (str[i] == ' '){ @@ -71,3 +74,7 @@ char * trim(char *str){ nstr[COUNT_OF(nstr)-1] = '\0'; return nstr; } + +float abs(float i){ + return (i>0) ? i : -i; +} |