forked from M-Labs/artiq
1
0
Fork 0
artiq/artiq/language/units.py

21 lines
494 B
Python
Raw Normal View History

2015-06-30 02:36:20 +08:00
__all__ = []
2014-11-23 08:56:51 +08:00
_prefixes_str = "pnum_kMG"
_smallest_prefix_exp = -12
2014-09-05 12:03:22 +08:00
2014-05-17 20:08:50 +08:00
def _register_unit(unit, prefixes):
exponent = _smallest_prefix_exp
2014-09-05 12:03:22 +08:00
for prefix in _prefixes_str:
if prefix in prefixes:
full_name = prefix + unit if prefix != "_" else unit
globals()[full_name] = 10.**exponent
2015-06-30 02:36:20 +08:00
__all__.append(full_name)
exponent += 3
2014-05-17 20:08:50 +08:00
2014-08-13 17:52:01 +08:00
_register_unit("s", "pnum_")
_register_unit("Hz", "_kMG")
_register_unit("dB", "_")
2015-02-21 00:37:54 +08:00
_register_unit("V", "um_k")