Next Hold Space 44

Rational arithmetic

  • So the script does something like this:

          to_rational $1
          
          tick_index_d=$(( range_n * d * min_d ))
          tick_index_n=$(( ( n * min_d - min_n * d ) * number_of_tiers * range_d ))
          # round to nearest integer: first add 1/2
          tick_index_an=$(( tick_index_n * 2 + tick_index_d ))
          tick_index_ad=$(( tick_index_d * 2 ))
          
          # divide and truncate
          tick_index=$(( tick_index_an / tick_index_ad ))
          
          echo -n ${ticks[$tick_index]};
  • https://github.com/mjdominus/spark


Next Next