From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24650 invoked by alias); 5 Jun 2018 22:33:00 -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: 23442 Received: (qmail 18214 invoked by uid 1010); 5 Jun 2018 22:33:00 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot0-f179.google.com 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(74.125.82.179):SA:0(-1.7/5.0):. Processed in 1.068678 secs); 05 Jun 2018 22:33:00 -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=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: phy1729@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=NDx7b6fvcCdOghmuNSzscjtU1dSC0ivWutsq42J2kXE=; b=Cx+j07X7M1I1iMXc6XUDUGSupT1hh7yQXWSeY69mN14HT/h/QqndbdERHEJSNRRxJv vqwmObtma9qDB7Op40H2pMMvTIJ/THeKZn29yQPI8v1ZZdquvI78C7KKoikvfOMhxxcU s+pmDVs7UOK2TtIsJARfH3eY1JC4b49krLdtq9hMGI0o9Qx3N/ygJCdDCS5/FF0QcHRW Q3I1LW4PLxW5xXoja+UM2UZ/GLj17cLeNsgE34fYxJJNqDe3wWdZYeFSkfvvJ9CEU8rL oEcRgG57zQKT13Fj9uuqkFi5R0qmp6LcFDOfNPLcGyaXGZMW/K5blVF0IFn0oC3Nq0wI vPIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=NDx7b6fvcCdOghmuNSzscjtU1dSC0ivWutsq42J2kXE=; b=AKcEtPJbF/9yXRt3ABs1uw50PS9jKIXnx24/FXI7URnLoYZJmiFW383PSmpGrMsMM+ tbMGApaWRRCHA/T+NhRV9+ioHlHVl7KrJq4oKNGxSYliSFY8TV4fdlLW6or/NaYAoa5H qPQ5Blo1Q3enLzdQgDgTdCA7TjMlWcqpwcZZJhgcLyFd1goMCXIDkEEI+emx8A4ys6F7 gDmS1vrpjf0cJbzJl1UwQbWjI5vrvIPN3f5TPg04qUFln80IXWN7rdZWUZxV//CI13vo 8oktHmx8pYwYi9ktWjQQ4XkjqDUpcy9g2dAeIxDyg/KMJ0tlFvrE6UsKqPJ1Wgy9knIR OA5Q== X-Gm-Message-State: APt69E0QK4bcpf0ADFLhdNRthh2UQRsBv2WpLey7t7SeTRYVh2P61Ijo oIcRfzJtjjsxfrkR2/+5kyBbiwve X-Google-Smtp-Source: ADUXVKLMheQZ8uWjqAiiFmTjHv/s6cSiKuKg9CVsb2xIAT2I+CRD0KV6XPWU3o8JDl7I32WqjesE5g== X-Received: by 2002:a9d:1bd6:: with SMTP id v22-v6mr375113otv.85.1528237976752; Tue, 05 Jun 2018 15:32:56 -0700 (PDT) Date: Tue, 5 Jun 2018 17:32:54 -0500 From: Matthew Martin To: zsh-users@zsh.org Subject: Re: 1.75 -> 1-3/4 Message-ID: <20180605223253.GA50167@CptOrmolo.darkstar> Mail-Followup-To: zsh-users@zsh.org References: <8636y25hm7.fsf@zoho.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8636y25hm7.fsf@zoho.com> User-Agent: Mutt/1.10.0 (2018-05-17) On Tue, Jun 05, 2018 at 12:09:20AM +0200, Emanuel Berg wrote: > Is this [1] the correct algorithm/a good > implementation? It translates 1.75 into 1-3/4 > at least :P What comes to mind first for me is the following. - Matthew Martin ths() { local decmal local -i denom num whole if [[ $1 != *.* ]]; then print -- $1 return fi whole=${1%.*} decimal=${1#*.} num=$decimal denom=$(( 10 ** ${#decimal} )) for d in 2 5; do while (( num % d == 0 && denom % d == 0 )); do (( num /= d )) (( denom /= d )) done done (( whole )) && print -n -- $whole (( whole && num )) && print -n ' ' (( num )) && print -n -- $num/$denom print }