Task 8 is done

This commit is contained in:
AZEN-SGG 2025-04-18 03:01:54 +03:00
parent 2efd819d0f
commit 98a608ce96
22 changed files with 1270 additions and 0 deletions

42
2025.04.18/08Ex/Makefile Normal file
View file

@ -0,0 +1,42 @@
WFLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused \
-Wempty-body -Wlogical-op -Wold-style-declaration -Wmissing-parameter-type \
-Wignored-qualifiers -Winit-self -Wshadow -Wtype-limits \
-Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 \
-Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs \
-Wmissing-prototypes -Wmissing-declarations -Wold-style-definition \
-Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal \
-Wwrite-strings -Wno-long-long -std=gnu99 -Wstrict-prototypes \
-Wmissing-field-initializers -Wpointer-sign
CFLAGS = -std=gnu99 -mfpmath=sse -O3
ifeq ($(OS),Windows_NT)
EXE = exe
CLEAN = del
LFLAGS = -lssp -lm
else
EXE = out
CLEAN = rm -f
LFLAGS = -lm
endif
TARGET = a08.$(EXE)
OBJ = main.o solve.o contin_func.o
%.o: %.c
gcc $(CFLAGS) $(WFLAGS) -c $< -o $@
$(TARGET): $(OBJ)
gcc $^ -o $@ $(LFLAGS)
# Отладочная сборка (gdb)
gdb: CFLAGS = -mfpmath=sse -std=gnu99 -g -O0
gdb: clean $(TARGET)
# Профилировочная сборка (gprof)
prof: CFLAGS = -std=gnu99 -mfpmath=sse -pg -O3
prof: LFLAGS = -lm -pg
prof: clean $(TARGET)
clean:
$(CLEAN) *.o *$(EXE)

View file

@ -0,0 +1,42 @@
#include "contin_func.h"
#include <math.h>
#include <float.h>
double fln (const double x, const double eps)
{
const double z = (x - 1) / (x + 1);
double value = 0;
double monom = z, el = z;
int i = 1;
while (el - eps > DBL_EPSILON)
{
value += el;
i+=2;
monom *= z*z;
el = monom / i;
}
return 2 * value;
}
double sln (const double x, const double eps)
{
const double z = x - 1;
double value = 0;
double monom = z, el = z;
int i = 1;
while (fabs(el) - eps > DBL_EPSILON)
{
value += el;
i++;
monom *= -z;
el = monom / i;
}
return value;
}

View file

@ -0,0 +1,7 @@
#ifndef CONTIN_FUNC_H
#define CONTIN_FUNC_H
double fln (const double x, const double eps);
double sln (const double x, const double eps);
#endif

View file

@ -0,0 +1,9 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define ERR_MEM "Error: Not enough memory!"
#define ERR_OPEN "Error: Cannot open file"
#define ERR_READ "Error: Cannot read file"
#define ERR_FUNC "Error: Algorithm is not applicable!"
#endif

34
2025.04.18/08Ex/main.c Normal file
View file

@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "io_status.h"
#include "solve.h"
/* ./a.out x eps */
int main(int argc, char *argv[])
{
double x, eps, t, r1 = 0, r2 = 0;
int task = 8;
if (
!((argc == 3) &&
((sscanf(argv[1], "%le", &x) == 1) && x > 0) &&
((sscanf(argv[2], "%le", &eps) == 1) && eps > 0))
) {
fprintf(stderr, "Usage: %s x eps\n", argv[0]);
return 1;
}
t = clock();
r1 = dln(x, eps);
t = (clock() - t) / CLOCKS_PER_SEC;
r2 = fabs(r1 - log(x));
printf("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], task, r1, r2, t);
return 0;
}

30
2025.04.18/08Ex/solve.c Normal file
View file

@ -0,0 +1,30 @@
#include "solve.h"
#include "contin_func.h"
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <float.h>
double dln (double x, const double eps)
{
double value = 0;
int b = 0;
while (x - 2 > DBL_EPSILON)
{
x *= 0.5;
b++;
}
while (x - 1 <= DBL_EPSILON)
{
x *= 2;
b--;
}
value = fln(x, eps);
value += b * M_LN2;
return value;
}

6
2025.04.18/08Ex/solve.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef SOLVE_H
#define SOLVE_H
double dln (double x, const double eps);
#endif