From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17552 invoked by alias); 5 Jun 2018 03:37:01 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23436 Received: (qmail 5870 invoked by uid 1010); 5 Jun 2018 03:37:01 -0000 X-Qmail-Scanner-Diagnostics: from forward1o.cmail.yandex.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(37.9.109.84):SA:0(-2.6/5.0):. Processed in 2.821003 secs); 05 Jun 2018 03:37:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: arto-p@yandex.ru X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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= Authentication-Results: mxback7g.mail.yandex.net; dkim=pass header.i=@yandex.ru From: Artur Penttinen To: Emanuel Berg , "zsh-users@zsh.org" In-Reply-To: <8636y25hm7.fsf@zoho.com> References: <8636y25hm7.fsf@zoho.com> Subject: Re: 1.75 -> 1-3/4 MIME-Version: 1.0 Message-Id: <2671261528169177@web23g.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Tue, 05 Jun 2018 06:26:17 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 05.06.2018, 01:27, "Emanuel Berg" : > 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