Skip to content

Instantly share code, notes, and snippets.

@erget
Last active August 15, 2017 09:18
Show Gist options
  • Save erget/90b2f59668d92fb34626f27cfef677df to your computer and use it in GitHub Desktop.
Save erget/90b2f59668d92fb34626f27cfef677df to your computer and use it in GitHub Desktop.
Show value domain given scale and reference value and width of field in bits
#!/usr/bin/env python
"""Show range and precision of encodable values."""
import argparse
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("scale", help="Scale value", type=int)
parser.add_argument("reference", help="Reference value", type=int)
parser.add_argument("width", help="Width in bits", type=int)
args = parser.parse_args()
max_val = (2**args.width - args.reference) * 10**-args.scale
print "Minimum value: " + str(args.reference)
print "Maximum value: " + str(max_val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment