Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: 1.75 -> 1-3/4
- X-seq: zsh-users 23436
- From: Artur Penttinen <arto-p@xxxxxxxxx>
- To: Emanuel Berg <moasen@xxxxxxxx>, "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: 1.75 -> 1-3/4
- Date: Tue, 05 Jun 2018 06:26:17 +0300
- Authentication-results: mxback7g.mail.yandex.net; dkim=pass header.i=@yandex.ru
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1528169177; bh=LiQETymDhOX3oEIrOYSMbXS6PO4rFbcpys0fDczR21Y=; h=From:To:In-Reply-To:References:Subject:Message-Id:Date; b=CpnpHqpfkeK22i4RulY8YIq7rlZMsoRAKCrfP6Ez3ez12z38qXD1hYnMs4ZoDOIvm o8RrWzd2RD1cJV2/i8ufVJuUDcmU6zBZJuqVOvdJvFufKnaHKB0pMqVkQEUcg0xPv6 qYfkJWitmaZp9s108YcxykDyWnTw33TuecnXbBko=
- In-reply-to: <8636y25hm7.fsf@zoho.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <8636y25hm7.fsf@zoho.com>
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