Thread: MTB randonneur
View Single Post
  #13  
Old June 4th 18, 11:08 PM posted to rec.bicycles.tech
Emanuel Berg[_2_]
external usenet poster
 
Posts: 1,035
Default MTB randonneur

Perhaps just lack of
standardization/normalization behind those
"more than 8 eights" fractions...? Some of
the decimals seem to be unexpressable
(cleanly) as eights or sixteenths tho?


Is this [1] the correct algorithm?
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
Ads
 

Home - Home - Home - Home - Home