Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
1.75 -> 1-3/4
- X-seq: zsh-users 23435
- From: Emanuel Berg <moasen@xxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: 1.75 -> 1-3/4
- Date: Tue, 05 Jun 2018 00:09:20 +0200
- Cancel-lock: sha1:MtlRObIB4UekTYxXYZQxnL20piA=
- 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>
- Mail-copies-to: never
- Mail-followup-to: zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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
--
underground experts united
http://user.it.uu.se/~embe8573
Messages sorted by:
Reverse Date,
Date,
Thread,
Author