-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheqsolve_vector.c
More file actions
42 lines (36 loc) · 967 Bytes
/
eqsolve_vector.c
File metadata and controls
42 lines (36 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef _EQSOLVE_VECTOR_C_
#define _EQSOLVE_VECTOR_C_
#include "eqsolve_vector.h"
#include <stdlib.h>
eqsolve_vector *eqsolve_vector_alloc(size_t N) {
eqsolve_vector *object = malloc(sizeof(eqsolve_vector));
object->size = N;
object->vector = malloc(N * sizeof(double));
return object;
};
int eqsolve_vector_set(eqsolve_vector *vector, int i, double value) {
if (i >= 0 && i < vector->size)
vector->vector[i] = value;
return 0;
};
int eqsolve_vector_set_all(eqsolve_vector *vector, double value) {
if (vector->size > 0) {
for (int i = 0; i < vector->size; i++) {
vector->vector[i] = value;
}
}
return 0;
};
int eqsolve_vector_free(eqsolve_vector *vector) {
free(vector->vector);
free(vector);
return EXIT_SUCCESS;
};
double eqsolve_vector_abs_max(eqsolve_vector *vector) {
double max = 0;
for (int i = 0; i < vector->size; i++)
if (vector->vector[i] > max)
max = vector->vector[i];
return max;
};
#endif