ref: 9ca3fc3a1d157ef7b3eb78453f96ae466b765306
parent: 167ab1f0fa682cd798c1b59aa832a485cc0029bc
author: aiju <[email protected]>
date: Sat Jun 27 18:00:33 EDT 2015
added approx(1)
--- /dev/null
+++ b/rc/bin/approx
@@ -1,0 +1,23 @@
+#!/bin/rc
+if(! ~ $#* 3){
+ echo usage: approx ratio min max
+ 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
+}
+'