Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 1.75 -> 1-3/4



05.06.2018, 01:27, "Emanuel Berg" <moasen@xxxxxxxx>:
> Is this [1] the correct algorithm/a good
> implementation? It translates 1.75 into 1-3/4
> at least :P
>
> ths () {
>     local value=$1
>     local denom=${2:-16}
>     local whole=$(( int(floor($value)) ))
>     local rest=$(( $value - $whole ))
>     local frac=$(( int(rint($rest * $denom)) ))
>     if (( $(( $frac % 2 )) == 0 )); then
>         local new_denom=$(( denom / 2 ))
>         ths $value $new_denom
>     else
>         echo $whole-${frac}/${denom}
>     fi
> }
> # $ ths 1.75
> # 1-3/4
>
> [1] http://user.it.uu.se/~embe8573/conf/.zsh/math

  # ths 2 
  ths:8: maximum nested function level reached; increase FUNCNEST?

-- 
wbw, artur



Messages sorted by: Reverse Date, Date, Thread, Author