aboutsummaryrefslogtreecommitdiff
path: root/writeups/multiprecision/fibo.mjs
blob: 1cc9b10cbea22ca3592fa66f2e87cfebbdf6d6c0 (plain)
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
#!/bin/env node

function do_fibo (num_f) {
	let a, b, c;

	a = num_f('0');
	b = num_f('1');

	for (let i = 0; i < 101; i += 1) {
		c = a + b;
		console.info(c.toString());
		b = a;
		a = c;
	}
}

function parse_flag (s) {
	s = s.toLowerCase();

	if (s === 'true') {
		return true;
	}
	else if (s === 'false') {
		return false;
	}

	return Number(s);
}

const flag = process.argv.length > 2 ? parse_flag(process.argv[2]) : true;

if (flag) {
	do_fibo(BigInt);
}
else {
	do_fibo(Number);
}