help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 1.75 -> 1-3/4


From: Marko Vojinovic
Subject: Re: 1.75 -> 1-3/4
Date: Tue, 5 Jun 2018 17:25:26 +0200

On Tue, 05 Jun 2018 15:01:33 +0200
Emanuel Berg <moasen@zoho.com> wrote:

> 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}

Umm, not to be a nitpick, but how about you change the minus in the
above line into a plus?

I mean, 1.75 is equal to 1+3/4, rather than 1-3/4 (the latter
obviously being equal to 0.25). I kind-of assume you know what you are
doing, but still, other people may get confused.

>         echo ${whole}${frace}
>     fi
> }
> # $ ths 2.0
> # 2
> # $ ths 1.75
> # 1-3/4
> 

HTH, :-)
Marko





reply via email to

[Prev in Thread] Current Thread [Next in Thread]