Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: 1.75 -> 1-3/4
Artur Penttinen wrote:
>> [1] http://user.it.uu.se/~embe8573/conf/.zsh/math
>
> # ths 2
> ths:8: maximum nested function level reached; increase FUNCNEST?
Terve/priviet, nice catch, here's an update:
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 > 0 && $(( $frac % 2 )) == 0 )); then
local new_denom=$(( denom / 2 ))
ths $value $new_denom
else
local frace
(( $frac > 0 )) && frace=-${frac}/${denom}
echo ${whole}${frace}
fi
}
# $ ths 2.0
# 2
# $ ths 1.75
# 1-3/4
--
underground experts united
http://user.it.uu.se/~embe8573
Messages sorted by:
Reverse Date,
Date,
Thread,
Author