author | Alberto Bertogli
<albertito@blitiri.com.ar> 2010-09-06 22:25:24 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2010-09-06 22:25:24 UTC |
parent | 836b69d7065a7689ac98f13d5e83fa0e4948bf23 |
Makefile | +1 | -1 |
aritmetica.hpp | +3 | -7 |
babilonio.cpp | +2 | -1 |
binomial.cpp | +2 | -1 |
binomial_dec.cpp | +3 | -3 |
binomial_inc.cpp | +2 | -1 |
calc.cpp | +1 | -0 |
fcont.cpp | +3 | -1 |
fcont_int.cpp | +4 | -2 |
util.cpp | +12 | -0 |
util.hpp | +21 | -0 |
diff --git a/Makefile b/Makefile index 0d16f31..312759d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CXXFLAGS += -Wall -std=c++98 -pedantic -Wno-long-long -OBJS = aritmetica.o +OBJS = aritmetica.o util.o default: calc babilonio binomial fcont fcont_int binomial_inc binomial_dec all: default diff --git a/aritmetica.hpp b/aritmetica.hpp index 650b908..619edd5 100644 --- a/aritmetica.hpp +++ b/aritmetica.hpp @@ -2,11 +2,8 @@ #ifndef _ARITMETICA_HPP #define _ARITMETICA_HPP -#if __WORDSIZE == 64 -#define print_64t "l" -#else -#define print_64t "ll" -#endif +#include <stdint.h> // uint64_t + /* Recorta la precision del double dado, devuelve un double "recortado". */ double trunc(int prec, double n); @@ -75,6 +72,5 @@ uint64_t to_u64(numero n); double to_double(uint64_t n); - -#endif // ifdef _ARITMETICA_HPP +#endif // ifndef _ARITMETICA_HPP diff --git a/babilonio.cpp b/babilonio.cpp index d179cac..996403a 100644 --- a/babilonio.cpp +++ b/babilonio.cpp @@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdint.h> #include "aritmetica.hpp" +#include "util.hpp" int main(int argc, char *argv[]) { @@ -27,7 +28,7 @@ int main(int argc, char *argv[]) n1 = n0 / 2.0 + 1 / n0; } - printf("%.60f 0x%" print_64t "x\n", n1.to_double(), to_u64(n1)); + print_result(niters, n1); return 0; } diff --git a/binomial.cpp b/binomial.cpp index 9d69bdb..18c6efd 100644 --- a/binomial.cpp +++ b/binomial.cpp @@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdint.h> #include "aritmetica.hpp" +#include "util.hpp" int prec; @@ -56,7 +57,7 @@ int main(int argc, char *argv[]) //printf(" %d %.60f 0x%" print_64t "x\n", i, n.to_double(), to_u64(n)); } - printf("%.60f 0x%" print_64t "x\n", n.to_double(), to_u64(n)); + print_result(nterm, n); return 0; } diff --git a/binomial_dec.cpp b/binomial_dec.cpp index b84dae8..25387cc 100644 --- a/binomial_dec.cpp +++ b/binomial_dec.cpp @@ -4,6 +4,7 @@ #include <list> #include <stdint.h> #include "aritmetica.hpp" +#include "util.hpp" using namespace std; @@ -32,7 +33,7 @@ int main(int argc, char *argv[]) printf("Uso: %s <prec> <nterm>\n", argv[0]); return 1; } - + prec = atoi(argv[1]); int nterm = atoi(argv[2]); @@ -66,8 +67,7 @@ int main(int argc, char *argv[]) for ( it=terminos.end() ; it != terminos.begin(); it--) n = n + *it; - - printf("%.60f 0x%" print_64t "x\n", n.to_double(), to_u64(n)); + print_result(nterm, n); return 0; } diff --git a/binomial_inc.cpp b/binomial_inc.cpp index 8d34efc..82ebd46 100644 --- a/binomial_inc.cpp +++ b/binomial_inc.cpp @@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdint.h> #include "aritmetica.hpp" +#include "util.hpp" int prec; @@ -65,7 +66,7 @@ int main(int argc, char *argv[]) //printf(" %d %.60f 0x%" print_64t "x\n", i, n.to_double(), to_u64(n)); } - printf("%.60f 0x%" print_64t "x\n", n.to_double(), to_u64(n)); + print_result(nterm, n); return 0; } diff --git a/calc.cpp b/calc.cpp index 6e72178..bec88ad 100644 --- a/calc.cpp +++ b/calc.cpp @@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdint.h> #include "aritmetica.hpp" +#include "util.hpp" int main(int argc, char *argv[]) { diff --git a/fcont.cpp b/fcont.cpp index 21a7632..cf660bb 100644 --- a/fcont.cpp +++ b/fcont.cpp @@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdint.h> #include "aritmetica.hpp" +#include "util.hpp" int main(int argc, char *argv[]) { @@ -22,7 +23,8 @@ int main(int argc, char *argv[]) /* El último término tiene sumado 1 en lugar de 2 */ n = n + 1; - printf("%.60f 0x%" print_64t "x\n", n.to_double(), to_u64(n)); + + print_result(nterm, n); return 0; } diff --git a/fcont_int.cpp b/fcont_int.cpp index 18d1177..388f8f1 100644 --- a/fcont_int.cpp +++ b/fcont_int.cpp @@ -2,8 +2,9 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> -#include "aritmetica.hpp" #include <utility> +#include "aritmetica.hpp" +#include "util.hpp" using namespace std; @@ -45,7 +46,8 @@ int main(int argc, char *argv[]) } numero n = (a_i.first / a_i.second) + 1; - printf("%.60f 0x%" print_64t "x\n", n.to_double(), to_u64(n)); + + print_result(nterm, n); return 0; } diff --git a/util.cpp b/util.cpp new file mode 100644 index 0000000..db8e1ca --- /dev/null +++ b/util.cpp @@ -0,0 +1,12 @@ + +#include <stdio.h> +#include "aritmetica.hpp" +#include "util.hpp" + +void print_result(int niter, numero n) +{ + printf("%d %d %.60f 0x%" print_64t "x\n", + niter, n.get_prec(), n.to_double(), to_u64(n)); + +} + diff --git a/util.hpp b/util.hpp new file mode 100644 index 0000000..b008be8 --- /dev/null +++ b/util.hpp @@ -0,0 +1,21 @@ + +#ifndef _UTIL_HPP +#define _UTIL_HPP + +#include "aritmetica.hpp" + +/* Constante usada para imprimir enteros de 64 bits, la cual depende de si la + * plataforma es de 64 bits o no. */ +#if __WORDSIZE == 64 +#define print_64t "l" +#else +#define print_64t "ll" +#endif + + +/* Imprime el resultado de una corrida. Util para uniformizar, que luego nos + * sirve para generar los gráficos. */ +void print_result(int niter, numero n); + +#endif // ifndef _UTIL_HPP +