git » metnum-tp1.git » master » tree

[master] / babilonio.cpp

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "aritmetica.hpp"
#include "util.hpp"

int main(int argc, char *argv[])
{
	if (argc != 3 && argc != 4) {
		printf("Uso: %s <prec> <niters> [aprox]\n", argv[0]);
		return 1;
	}

	int aprox = 2;
	int prec = atoi(argv[1]);
	int niters = atoi(argv[2]);
	if (argc == 4)
		aprox = atoi(argv[3]);

	/* 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;
	}

	print_result(niters, n1);

	return 0;
}