author | Alberto Bertogli
<albertito@blitiri.com.ar> 2010-08-31 00:14:37 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2010-08-31 00:16:02 UTC |
parent | 2cdbd730d14d8ef1c80021bccfeceb21e34ecb17 |
Makefile | +8 | -5 |
babilonio.cpp | +33 | -0 |
diff --git a/Makefile b/Makefile index 6f07f6c..f0235a6 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,18 @@ CXXFLAGS += -Wall -std=c++98 -pedantic -Wno-long-long -OBJS = aritmetica.o calc.o +OBJS = aritmetica.o -default: calc +default: calc babilonio all: default -calc: $(OBJS) - $(CXX) $(CXXFLAGS) $(OBJS) -o calc +calc: $(OBJS) calc.o + $(CXX) $(CXXFLAGS) $^ -o $@ + +babilonio: $(OBJS) babilonio.o + $(CXX) $(CXXFLAGS) $^ -o $@ clean: - rm -f $(OBJS) calc + rm -f $(OBJS) calc.o calc babilonio.o babilonio diff --git a/babilonio.cpp b/babilonio.cpp new file mode 100644 index 0000000..9b81e21 --- /dev/null +++ b/babilonio.cpp @@ -0,0 +1,33 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include "aritmetica.hpp" + +#define APROX 2 + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + printf("Uso: %s <prec> <niters>\n", argv[0]); + return 1; + } + + int prec = atoi(argv[1]); + int niters = atoi(argv[2]); + + /* Valores iniciales */ + numero n0(prec, APROX); + numero n1 = n0; + + /* Loop de la sucesion, niters veces */ + for (int i = 0; i < niters; i++) { + n0 = n1; + n1 = n0 / 2.0 + 1 / n0; + } + + printf("%.60f 0x%lx\n", (double) n1, to_u64(n1)); + + return 0; +} +