plan9fox/rc/bin/approx
Ori Bernstein 5bc9b0c3ca improve usage messages (thanks henesy)
Fix inconsistencies between programs and their usage
messages,  correct instances where information seems
to be missing or lost. This  includes missing arguments,
making usage consistent with manuals, and so on.
2020-03-10 10:09:34 -07:00

23 lines
325 B
Bash
Executable file

#!/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
}
'