From 0cde98a5543adcd1d1ceaee0d75480e4388aa55f Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Sun, 11 May 2025 09:09:14 +0300 Subject: [PATCH] Task 8 is done --- 2025.05.02/08Ex/comp.h | 50 ----------------------------------------- 2025.05.02/08Ex/solve.c | 16 ++++++------- 2 files changed, 8 insertions(+), 58 deletions(-) delete mode 100644 2025.05.02/08Ex/comp.h diff --git a/2025.05.02/08Ex/comp.h b/2025.05.02/08Ex/comp.h deleted file mode 100644 index 6b09d43..0000000 --- a/2025.05.02/08Ex/comp.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef COMP_H -#define COMP_H - -#include -#include - -static inline double * fpmax (double *pa, double *pb, double fa, double fb, double *max_f_p) -{ - if ((fa - fb) > DBL_EPSILON) - { - *max_f_p = fa; - return pa; - } else - { - *max_f_p = fb; - return pb; - } -} - -static inline double * fp_abs_max (double *pa, double *pb, double *fa, double *fb, double **max_f_p) -{ - if ((fabs(*fa) - fabs(*fb)) > DBL_EPSILON) - { - *max_f_p = fa; - return pa; - } else - { - *max_f_p = fb; - return pb; - } -} - -static inline int is_equal (const double a, const double b) -{ - double diff = a - b; - double max_val = (a > b) ? a : b; - return ((diff < 0) ? -diff : diff) < (DBL_EPSILON * max_val); -} - -static inline int is_null (const double a) -{ - return ((a < 0) ? -a : a) < DBL_EPSILON; -} - -static inline int is_eps (const double a, const double eps) -{ - return (((a < 0) ? -a : a) - eps) < DBL_EPSILON; -} - -#endif diff --git a/2025.05.02/08Ex/solve.c b/2025.05.02/08Ex/solve.c index a4268b9..06d388f 100644 --- a/2025.05.02/08Ex/solve.c +++ b/2025.05.02/08Ex/solve.c @@ -33,20 +33,20 @@ int t8_solve ( y_l = y; x += h; + y = f(x); + if ((y_l - y) > DBL_EPSILON) + break; if ((a - x) > DBL_EPSILON || (x - b) > DBL_EPSILON) { *res = x_l; return it; } - y = f(x); - if ((y_l - y) > DBL_EPSILON) { - if ((y_l - y) < eps) { - *res = x_l; - return it; - } - break; - } + } + + if ((y_l - y) < eps) { + *res = x_l; + return it; } }