shithub: riscv

ref: 8e56bd06b559b45d6a8544ae2b1f752a5b3da516
dir: /rc/bin/approx/

View raw version
#!/bin/rc
if(! ~ $#* 3){
	echo usage: approx ratio min max >[1=2]
	exit usage
}
echo $1 $2 $3 | awk '
{
	y=$1;
	min=$2;
	max=$3;
	for(i = min; i <= max; i++){
		k = int(y*i+0.5);
		z = (k/i/y-1)*100;
		if(z < 0)
			z = -z;
		if(i == min || z < zm){
			zm = z;
			printf("%d/%d\t%g\t%.2g%%\n", k, i, k/i, z);
		}
	}
	exit
}
'