diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2022-09-29 16:57:25 -0400 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2022-09-29 16:57:25 -0400 |
commit | 1d4ad135a43747041afb58f3cce586ceab94e39a (patch) | |
tree | 77be34e9832220686800c127969acf5acc6e8f23 | |
parent | ed0bcc92f5101043fa9e09a1b7f66f339aaa177b (diff) |
clean up code
-rw-r--r-- | cosine.c | 11 | ||||
-rw-r--r-- | format.h | 6 | ||||
-rw-r--r-- | sine.c | 10 | ||||
-rw-r--r-- | tools/gen-trig-test.c | 19 |
4 files changed, 26 insertions, 20 deletions
@@ -11,14 +11,15 @@ #include "format.h" #include "testData.h" +const int DEBUG = FALSE; + double cos(double input, int precision){ double ttl = 1; int denom = 1; double num; for (int i=2;i<=(2*precision);i+=2){ - num = mpow(input,i); + num = pow(input,i); denom *= i*(i-1); - // ttl += num/denom; ttl += ( (i/2)%2 == 0 ) ? num/denom : -num/denom; } return ttl; @@ -40,9 +41,11 @@ int main(){ cos(piValues[i][0],precision)); return 1; } else { - printf("%f IS ALL GOOD!\n",piValues[i][0]); + if (DEBUG){ + printf("%f IS ALL GOOD!\n",piValues[i][0]); + } } } - + printf("All checks have passed!\n"); return 0; } @@ -21,13 +21,13 @@ const char caps[2][26] = { 'n','o','p','q','r','s','t','u','v','w','x','y','z'} }; -double mpow(double b, int e){ +double pow(double b, int e){ if (e==1){ return b; } else if (e%2==0){ - return mpow(b*b,e/2); + return pow(b*b,e/2); } else { - return b * mpow(b*b, e/2); + return b * pow(b*b, e/2); } } @@ -12,14 +12,14 @@ #include "format.h" #include "testData.h" -const int DEBUG = TRUE; +const int DEBUG = FALSE; double sin(double input, int precision){ double ttl = input; int denom = 1; double num; for (int i=3;i<(2*precision)+2;i+=2) { - num = mpow(input,i); + num = pow(input,i); denom *= i*(i-1); ttl += ((i-1)/2 %2 == 1) ? -num/denom : num/denom; } @@ -42,9 +42,11 @@ int main(){ sin(piValues[i][0],precision)); return 1; } else { - printf("%f IS ALL GOOD!\n",piValues[i][0]); + if (DEBUG){ + printf("%f IS ALL GOOD!\n",piValues[i][0]); + } } } - + printf("All checks have passed!\n"); return 0; } diff --git a/tools/gen-trig-test.c b/tools/gen-trig-test.c index 54b39bf..66a82ec 100644 --- a/tools/gen-trig-test.c +++ b/tools/gen-trig-test.c @@ -11,24 +11,25 @@ #include <stdio.h> #include <stdlib.h> -/* This code was used to generate double precision floating point numbers found - * in testData.h It's purpose is to generate a list of expected outputs for the - * sine and cosine function with a given number. It uses the math.h library - * which cannot be used for the assignment and which is therefore a great - * subject to test and compare with. +/* This code was used to generate floating point numbers found in testData.h + * It's purpose is to generate a list of expected outputs for the sine and + * cosine function with a given number. It uses the math.h library which cannot + * be used for the assignment and which is therefore a great subject to test + * and compare with. * * The generated [][3]int list is organized as follows: { original_value, * expected_sine, expected_cosine } * - * Values chosen here test the following edge cases, - Common trigonometric - * circle identities (0°,30°,45°,60°,90°, etc...) - Negative values - Values - * surpassing 2π + * Values chosen here test the following edge cases, + * - Common trigonometric circle identities (0°,30°,45°,60°,90°, etc...) + * - Negative values + * - Values surpassing 2π */ int main(){ // list of number {{{ - double lst[20] = { +const double lst[20] = { 0, // 0° M_PI/6, // 30° M_PI/4, // 45° |