Skip to content

Instantly share code, notes, and snippets.

@JackZielke
Created February 20, 2022 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackZielke/3c67139667a7d485cd2d2db4e0e5b90d to your computer and use it in GitHub Desktop.
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.
#!/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
@JackZielke
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment