Created
February 20, 2022 02:24
-
-
Save JackZielke/3c67139667a7d485cd2d2db4e0e5b90d to your computer and use it in GitHub Desktop.
Generate a list of fractions and their decimal equivalents. Defaults to 1/64 increments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
scale=3 | |
if [ $# -lt 1 ]; then | |
fract=64 | |
else | |
fract=$1 | |
fi | |
for i in `seq 1 $[fract-1]`; do | |
temp=$i | |
div=$fract | |
while [ $[temp%2] -eq 0 ]; do | |
temp=$[temp/2] | |
div=$[div/2] | |
done | |
echo -en "${temp}/${div}\t" | |
echo -e "scale=${scale}\n${i}/${fract}" | bc | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was doing some work in CAD in "freedom units" and found this useful. It generates a list that looks like this:
1/64 .015
1/32 .031
3/64 .046
1/16 .062
5/64 .078
3/32 .093
7/64 .109
1/8 .125
...
61/64 .953
31/32 .968
63/64 .984
If you give it a parameter it will use that divisor instead of 64. The scale is set to 3 decimals at the top of the script.