diff --git a/src/utils.c b/src/utils.c index 86d3056..3f39bb1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -194,10 +194,10 @@ float m_tan(float x) // return ((func(a+h)-func(a))/h); // } -// euler method in one dimension +// newton method in one dimension // takes a function and find one of the root // return the status 0 if success >0 if error -int m_euler_method(float (*func)(float, float), float param, float startsAt, float* resPtr) +int m_newton_method(float (*func)(float, float), float param, float startsAt, float* resPtr) { // (x-b)f'(b)+f(b) = 0 // xf'(b)-bf'(b)+f(b) = 0 @@ -217,7 +217,7 @@ int m_euler_method(float (*func)(float, float), float param, float startsAt, flo return 0; } if (runs > 100) { - printf("ERR: euler methods failed, coup dur pour euler \n"); + printf("ERR: newton methods failed, coup dur pour newton \n"); return 100; } cursor = newCursor; @@ -235,7 +235,7 @@ float m_sqrt_equation(float x, float y) float m_sqrt(float x) { float res = 0; - m_euler_method(&m_sqrt_equation, x, 4, &res); + m_newton_method(&m_sqrt_equation, x, 4, &res); return res; } @@ -248,7 +248,7 @@ float m_ln_equation(float x, float y) float m_ln(float x) { float res = 0; - m_euler_method(&m_ln_equation, x, 4, &res); + m_newton_method(&m_ln_equation, x, 4, &res); return res; } diff --git a/src/utils.h b/src/utils.h index 6cd8d25..13a5c72 100644 --- a/src/utils.h +++ b/src/utils.h @@ -11,6 +11,7 @@ // define custom type (unsigned char) typedef unsigned char byte; + int get_int_rep_from_float(float ft); float get_float_from_int_rep(int representation); @@ -27,6 +28,9 @@ float m_float_modulus(float a, float mod); int m_factorial(int x); + +int m_newton_method(float (*func)(float, float), float param, float startsAt, float* resPtr); + float m_float_pow(float base, int exponent); float m_sqrt(float x); @@ -48,6 +52,7 @@ int is_full_of_space(char* str); void str_extract(char* res, char* subject, int initial, int length); byte str_needle_at_pos(char* needle, char* subject, int pos); + byte str_starts_with(char* needle, char* subject); void trim_space(char* dst, char* subject);