Task 6 and 7 are done!
This commit is contained in:
parent
2f21a20fd1
commit
2efd819d0f
16 changed files with 334 additions and 4 deletions
|
@ -14,8 +14,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!((argc == 3) &&
|
!((argc == 3) &&
|
||||||
sscanf(argv[1], "%lf", &x) == 1 &&
|
sscanf(argv[1], "%le", &x) == 1 &&
|
||||||
((sscanf(argv[2], "%lf", &eps) == 1) && eps > 0))
|
((sscanf(argv[2], "%le", &eps) == 1) && eps > 0))
|
||||||
) {
|
) {
|
||||||
fprintf(stderr, "Usage: %s x eps\n", argv[0]);
|
fprintf(stderr, "Usage: %s x eps\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
42
2025.04.18/06Ex/Makefile
Normal file
42
2025.04.18/06Ex/Makefile
Normal 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 = a06.$(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)
|
38
2025.04.18/06Ex/contin_func.c
Normal file
38
2025.04.18/06Ex/contin_func.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include "contin_func.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
double ssin (const double x, const double eps)
|
||||||
|
{
|
||||||
|
double value = 0;
|
||||||
|
double el = x;
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
while (fabs(el) - eps >= DBL_EPSILON)
|
||||||
|
{
|
||||||
|
value += el;
|
||||||
|
|
||||||
|
el *= -(x*x / (i*i + 3*i + 2));
|
||||||
|
i+=2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
double scos (const double x, const double eps)
|
||||||
|
{
|
||||||
|
double value = 0;
|
||||||
|
double el = 1;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (fabs(el) - eps >= DBL_EPSILON)
|
||||||
|
{
|
||||||
|
value += el;
|
||||||
|
|
||||||
|
el *= - (x*x / (i*i + 3*i + 2));
|
||||||
|
i+=2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
7
2025.04.18/06Ex/contin_func.h
Normal file
7
2025.04.18/06Ex/contin_func.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef CONTIN_FUNC_H
|
||||||
|
#define CONTIN_FUNC_H
|
||||||
|
|
||||||
|
double ssin (const double x, const double eps);
|
||||||
|
double scos (const double x, const double eps);
|
||||||
|
|
||||||
|
#endif
|
9
2025.04.18/06Ex/io_status.h
Normal file
9
2025.04.18/06Ex/io_status.h
Normal 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/06Ex/main.c
Normal file
34
2025.04.18/06Ex/main.c
Normal 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 = 6;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!((argc == 3) &&
|
||||||
|
sscanf(argv[1], "%le", &x) == 1 &&
|
||||||
|
((sscanf(argv[2], "%le", &eps) == 1) && eps > 0))
|
||||||
|
) {
|
||||||
|
fprintf(stderr, "Usage: %s x eps\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
t = clock();
|
||||||
|
r1 = fcos(x, eps);
|
||||||
|
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
r2 = fabs(r1 - cos(x));
|
||||||
|
|
||||||
|
printf("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], task, r1, r2, t);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
39
2025.04.18/06Ex/solve.c
Normal file
39
2025.04.18/06Ex/solve.c
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#include "solve.h"
|
||||||
|
#include "contin_func.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
double fcos (double x, const double eps)
|
||||||
|
{
|
||||||
|
double answer;
|
||||||
|
short flag = 1;
|
||||||
|
|
||||||
|
if (x - M_PI*2 >= DBL_EPSILON)
|
||||||
|
x = fmod(x, M_PI*2);
|
||||||
|
|
||||||
|
if (x - M_PI >= DBL_EPSILON)
|
||||||
|
{
|
||||||
|
x -= M_PI;
|
||||||
|
flag *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x - 1 >= DBL_EPSILON)
|
||||||
|
{
|
||||||
|
x -= M_PI_2;
|
||||||
|
flag *= -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (abs(flag) == 2)
|
||||||
|
{
|
||||||
|
x /= 2;
|
||||||
|
|
||||||
|
answer = ((flag > 0) - (flag < 0)) * (2 * ssin(x, eps) * scos(x, eps));
|
||||||
|
} else
|
||||||
|
answer = flag * scos(x, eps);
|
||||||
|
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
6
2025.04.18/06Ex/solve.h
Normal file
6
2025.04.18/06Ex/solve.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef SOLVE_H
|
||||||
|
#define SOLVE_H
|
||||||
|
|
||||||
|
double fcos (double x, const double eps);
|
||||||
|
|
||||||
|
#endif
|
42
2025.04.18/07Ex/Makefile
Normal file
42
2025.04.18/07Ex/Makefile
Normal 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 = a07.$(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)
|
21
2025.04.18/07Ex/contin_func.c
Normal file
21
2025.04.18/07Ex/contin_func.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#include "contin_func.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
double sexp (const double x, const double eps)
|
||||||
|
{
|
||||||
|
double value = 1;
|
||||||
|
double monom = x;
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
while (monom - eps >= DBL_EPSILON)
|
||||||
|
{
|
||||||
|
value += monom;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
monom *= x/i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
6
2025.04.18/07Ex/contin_func.h
Normal file
6
2025.04.18/07Ex/contin_func.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef CONTIN_FUNC_H
|
||||||
|
#define CONTIN_FUNC_H
|
||||||
|
|
||||||
|
double sexp (const double x, const double eps);
|
||||||
|
|
||||||
|
#endif
|
9
2025.04.18/07Ex/io_status.h
Normal file
9
2025.04.18/07Ex/io_status.h
Normal 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/07Ex/main.c
Normal file
34
2025.04.18/07Ex/main.c
Normal 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 = 7;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!((argc == 3) &&
|
||||||
|
sscanf(argv[1], "%le", &x) == 1 &&
|
||||||
|
((sscanf(argv[2], "%le", &eps) == 1) && eps > 0))
|
||||||
|
) {
|
||||||
|
fprintf(stderr, "Usage: %s x eps\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
t = clock();
|
||||||
|
r1 = fexp(x, eps);
|
||||||
|
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
r2 = fabs(r1 - exp(x));
|
||||||
|
|
||||||
|
printf("%s : Task = %d Result = %e Residual = %e Elapsed = %.2f\n", argv[0], task, r1, r2, t);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
31
2025.04.18/07Ex/solve.c
Normal file
31
2025.04.18/07Ex/solve.c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include "solve.h"
|
||||||
|
#include "contin_func.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
double fexp (double x, const double eps)
|
||||||
|
{
|
||||||
|
double integral, fractal, answer = 1;
|
||||||
|
bool is_negative = false;
|
||||||
|
|
||||||
|
if (x < DBL_EPSILON)
|
||||||
|
{
|
||||||
|
is_negative = true;
|
||||||
|
x = -x;
|
||||||
|
}
|
||||||
|
|
||||||
|
integral = floor(x);
|
||||||
|
fractal = x - integral;
|
||||||
|
|
||||||
|
for (double i = 0; (integral - i) > DBL_EPSILON; ++i)
|
||||||
|
answer *= M_E;
|
||||||
|
|
||||||
|
answer *= sexp(fractal, eps);
|
||||||
|
if (is_negative)
|
||||||
|
answer = 1. / answer;
|
||||||
|
|
||||||
|
return answer;
|
||||||
|
}
|
6
2025.04.18/07Ex/solve.h
Normal file
6
2025.04.18/07Ex/solve.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef SOLVE_H
|
||||||
|
#define SOLVE_H
|
||||||
|
|
||||||
|
double fexp (double x, const double eps);
|
||||||
|
|
||||||
|
#endif
|
10
2025.04.18/dist/Ulyanov_MT/task07.c
vendored
10
2025.04.18/dist/Ulyanov_MT/task07.c
vendored
|
@ -30,8 +30,13 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
double solve7(double x, double eps)
|
double solve7(double x, double eps)
|
||||||
{
|
{
|
||||||
int i = 1, intg;
|
int sign = 1, i = 1, intg;
|
||||||
double mult = 1, el = 1, res = 0;
|
double mult = 1, el = 1, res = 0;
|
||||||
|
if (x < 0)
|
||||||
|
{
|
||||||
|
sign = -1;
|
||||||
|
x = fabs(x);
|
||||||
|
}
|
||||||
intg = floor(x);
|
intg = floor(x);
|
||||||
x = x - intg;
|
x = x - intg;
|
||||||
while (fabs(el) >= eps)
|
while (fabs(el) >= eps)
|
||||||
|
@ -44,5 +49,6 @@ double solve7(double x, double eps)
|
||||||
{
|
{
|
||||||
mult *= M_E;
|
mult *= M_E;
|
||||||
}
|
}
|
||||||
return mult * res;
|
if (sign == 1) return mult * res;
|
||||||
|
else return 1 / (mult * res);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue