Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Nadi Tomeh
SDA
Commits
d24f9e12
Commit
d24f9e12
authored
Sep 18, 2019
by
david
Browse files
long double in C
parent
80e299b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
C/analyzer.c
View file @
d24f9e12
...
...
@@ -35,25 +35,25 @@ void analyzer_append(analyzer_t * a, double x){
}
}
double
get_total_cost
(
analyzer_t
*
a
){
long
double
get_total_cost
(
analyzer_t
*
a
){
return
(
a
->
size
)
?
a
->
cumulative_cost
[
a
->
size
-
1
]
:
-
1
;
}
double
get_amortized_cost
(
analyzer_t
*
a
,
size_t
pos
){
long
double
get_amortized_cost
(
analyzer_t
*
a
,
size_t
pos
){
if
(
pos
>=
0
&&
pos
<
a
->
size
)
return
(
pos
)
?
a
->
cumulative_cost
[
pos
]
/
pos
:
a
->
cumulative_cost
[
pos
];
return
-
1
;
}
double
get_average_cost
(
analyzer_t
*
a
){
long
double
get_average_cost
(
analyzer_t
*
a
){
if
(
a
->
size
)
return
a
->
cumulative_cost
[
a
->
size
-
1
]
/
a
->
size
;
return
-
1
;
}
double
get_variance
(
analyzer_t
*
a
){
double
mean
,
mean_square
;
long
double
get_variance
(
analyzer_t
*
a
){
long
double
mean
,
mean_square
;
if
(
a
->
size
){
mean
=
get_average_cost
(
a
);
mean_square
=
mean
*
mean
;
...
...
@@ -62,7 +62,7 @@ double get_variance(analyzer_t * a){
return
-
1
;
}
double
get_standard_deviation
(
analyzer_t
*
a
){
long
double
get_standard_deviation
(
analyzer_t
*
a
){
if
(
a
->
size
)
return
sqrt
(
get_variance
(
a
));
return
-
1
;
...
...
@@ -73,7 +73,7 @@ void save_values(analyzer_t * a, char * path){
int
i
;
if
(
(
f
=
fopen
(
path
,
"w"
))
!=
NULL
){
for
(
i
=
0
;
i
<
a
->
size
;
++
i
){
fprintf
(
f
,
"%d %lf %
l
f
\n
"
,
i
,
a
->
cost
[
i
],
get_amortized_cost
(
a
,
i
));
fprintf
(
f
,
"%d %lf %
L
f
\n
"
,
i
,
a
->
cost
[
i
],
get_amortized_cost
(
a
,
i
));
}
}
else
{
fprintf
(
stderr
,
"Could not save values in file %s"
,
path
);
...
...
@@ -83,6 +83,6 @@ void save_values(analyzer_t * a, char * path){
void
plot_values
(
analyzer_t
*
a
){
int
i
;
for
(
i
=
0
;
i
<
a
->
size
;
++
i
){
printf
(
"%d %lf %
l
f
\n
"
,
i
,
a
->
cost
[
i
],
get_amortized_cost
(
a
,
i
));
printf
(
"%d %lf %
L
f
\n
"
,
i
,
a
->
cost
[
i
],
get_amortized_cost
(
a
,
i
));
}
}
C/analyzer.h
View file @
d24f9e12
...
...
@@ -51,7 +51,7 @@ void analyzer_append(analyzer_t * a, double cost);
@param a est une analyse.
@returns la somme des coûts enregistrés dans cette analyse.
*/
double
get_total_cost
(
analyzer_t
*
a
);
long
double
get_total_cost
(
analyzer_t
*
a
);
/**
Renvoie le coût amorti d'une opération.
...
...
@@ -60,7 +60,7 @@ double get_total_cost(analyzer_t * a);
@param pos est l'indice de l'opération pour laquelle on veut connaître le coût amorti.
@returns le coût amorti d'une opération.
*/
double
get_amortized_cost
(
analyzer_t
*
a
,
size_t
pos
);
long
double
get_amortized_cost
(
analyzer_t
*
a
,
size_t
pos
);
/**
Renvoie la moyenne des coûts de toutes les opérations enregistrées dans l'analyse.
...
...
@@ -68,7 +68,7 @@ double get_amortized_cost(analyzer_t * a, size_t pos);
@param a est une analyse.
@returns la moyenne des coûts de toutes les opérations enregistrées dans l'analyse.
*/
double
get_average_cost
(
analyzer_t
*
a
);
long
double
get_average_cost
(
analyzer_t
*
a
);
/**
Renvoie la variance des coûts de toutes les opérations enregistrées dans l'analyse.
...
...
@@ -76,7 +76,7 @@ double get_average_cost(analyzer_t * a);
@param a est une analyse.
@returns la variance des coûts de toutes les opérations enregistrées dans l'analyse.
*/
double
get_variance
(
analyzer_t
*
a
);
long
double
get_variance
(
analyzer_t
*
a
);
/**
Renvoie l'écart-type des coûts de toutes les opérations enregistrées dans l'analyse.
...
...
@@ -84,7 +84,7 @@ double get_variance(analyzer_t * a);
@param a est une analyse.
@returns l'écart-type des coûts de toutes les opérations enregistrées dans l'analyse.
*/
double
get_standard_deviation
(
analyzer_t
*
a
);
long
double
get_standard_deviation
(
analyzer_t
*
a
);
/**
Sauvegarde la liste des coûts et des coûts amortis dans un fichier.
...
...
C/main.c
View file @
d24f9e12
...
...
@@ -38,10 +38,10 @@ int main(int argc, char ** argv){
}
// Affichage de quelques statistiques sur l'expérience.
fprintf
(
stderr
,
"Total cost: %
l
f
\n
"
,
get_total_cost
(
time_analysis
));
fprintf
(
stderr
,
"Average cost: %
l
f
\n
"
,
get_average_cost
(
time_analysis
));
fprintf
(
stderr
,
"Variance: %
l
f
\n
"
,
get_variance
(
time_analysis
));
fprintf
(
stderr
,
"Standard deviation: %
l
f
\n
"
,
get_standard_deviation
(
time_analysis
));
fprintf
(
stderr
,
"Total cost: %
L
f
\n
"
,
get_total_cost
(
time_analysis
));
fprintf
(
stderr
,
"Average cost: %
L
f
\n
"
,
get_average_cost
(
time_analysis
));
fprintf
(
stderr
,
"Variance: %
L
f
\n
"
,
get_variance
(
time_analysis
));
fprintf
(
stderr
,
"Standard deviation: %
L
f
\n
"
,
get_standard_deviation
(
time_analysis
));
// Sauvegarde les données de l'expérience.
save_values
(
time_analysis
,
"../plots/dynamic_array_time_c.plot"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment