-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable.h
More file actions
92 lines (79 loc) · 2.27 KB
/
Copy pathvariable.h
File metadata and controls
92 lines (79 loc) · 2.27 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* @file variable.h Header file of variable.c
* @author Valentin Koeltgen
*/
#ifndef LINEARALGEBRA_VARIABLE_H
#define LINEARALGEBRA_VARIABLE_H
#include <stdlib.h>
#include <stdio.h>
#define IMAGINARY 12345.54321
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Structures
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/**
* @struct Variable
* Structure representing a variable
*/
typedef struct {
char *name; ///Name of the variable
double value; ///Value of the variable
} Variable;
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Construction functions
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/**
* Create a variable with the given value
* @param value - The value to initialise the variable
* @return created variable
*/
Variable newVariable(double value);
/**
* Free a variable
* @param toFree - The variable to free
*/
void freeVariable(Variable *toFree);
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Basic operator functions
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/**
* Print a variable
* Print a given variable in the terminal
* @param variable - Variable to print
*/
void printVariable(Variable variable);
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Basic mathematical operators
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/**
* Absolute value
* @param x - Input value
* @return |x|
*/
double absolute(double x);
/**
* Double multiplied to a certain power
* @param x - Value to multiply to the power
* @param power - Power to apply
* @return x^power
*/
double power(double x, int power);
/**
* Square root
* @param x - Input value
* @return Square root of x
*/
double sqrt(double x);
/**
* Round double to integer
* @param value - Value to round
* @return rounded value
*/
int roundDouble(double value);
/**
* Reduce precision of a double
* This function take a double and round it up to a lower precision (1e-9)
* @param value - Value to round
* @return rounded double
*/
double roundPreciseDouble(double value);
#endif //LINEARALGEBRA_VARIABLE_H