all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 1.75 -> 1-3/4
@ 2018-06-05 13:01 Emanuel Berg
  2018-06-05 13:18 ` Teemu Likonen
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Emanuel Berg @ 2018-06-05 13:01 UTC (permalink / raw)
  To: help-gnu-emacs

Did anyone do the equivalent of this ("ths" zsh
below) in Elisp or any other Lisp? Just asking
before I do it myself. The algorithm should be
straightforward, but it uses recursion which
I plan to replace by a loop in the Elisp
version. But it looks good otherwise, right?

Before anyone tries to use it on a bicycle
tire, note that "[a] 26x1.5 tire and a 26x1-1/2
tire are different tire sizing systems" (JL on
rec.bicycles.tech). Read more here [1]

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}
        echo ${whole}${frace}
    fi
}
# $ ths 2.0
# 2
# $ ths 1.75
# 1-3/4

[1] http://www.sheldonbrown.com/tire-sizing.html

-- 
underground experts united
http://user.it.uu.se/~embe8573


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-06-05 18:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-05 13:01 1.75 -> 1-3/4 Emanuel Berg
2018-06-05 13:18 ` Teemu Likonen
2018-06-05 13:39   ` tomas
2018-06-05 13:49     ` tomas
2018-06-05 14:12       ` Teemu Likonen
     [not found]   ` <mailman.1205.1528205966.1292.help-gnu-emacs@gnu.org>
2018-06-05 15:30     ` Emanuel Berg
2018-06-05 17:00       ` tomas
     [not found]       ` <mailman.1245.1528218012.1292.help-gnu-emacs@gnu.org>
2018-06-05 18:08         ` Emanuel Berg
2018-06-05 15:25 ` Marko Vojinovic
     [not found] ` <mailman.1238.1528215089.1292.help-gnu-emacs@gnu.org>
2018-06-05 18:06   ` Emanuel Berg
     [not found] ` <mailman.1199.1528204714.1292.help-gnu-emacs@gnu.org>
2018-06-05 18:54   ` Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.