Skip to content

Instantly share code, notes, and snippets.

@GaryLee
Last active May 4, 2024 01:47
Show Gist options
  • Save GaryLee/adbd399e13de35a420a972d9ad6ea8a5 to your computer and use it in GitHub Desktop.
Save GaryLee/adbd399e13de35a420a972d9ad6ea8a5 to your computer and use it in GitHub Desktop.
Provide a serial of postfix unit symbol.
#!python
# Provide a serial of postfix unit symbol.
class UnitScaleOp:
def __init__(self, scale, desc=None):
self.scale = scale
self.desc = desc
def __rmatmul__(self, value):
return value * self.scale
Q = UnitScaleOp(1e30, 'quetta')
R = UnitScaleOp(1e27, 'ronna')
Y = UnitScaleOp(1e24, 'yotta')
Z = UnitScaleOp(1e21, 'zetta')
E = UnitScaleOp(1e18, 'exa')
P = UnitScaleOp(1e15, 'peta')
T = UnitScaleOp(1e12, 'tera')
G = UnitScaleOp(1e9, 'giga')
M = UnitScaleOp(1e6, 'mega')
K = UnitScaleOp(1e3, 'kilo')
H = UnitScaleOp(1e2, 'hecto')
D = UnitScaleOp(1e1, 'deca')
d = UnitScaleOp(1e-1, 'deci')
c = UnitScaleOp(1e-2, 'centi')
m = UnitScaleOp(1e-3, 'milli')
u = UnitScaleOp(1e-6, 'micro')
n = UnitScaleOp(1e-9, 'nano')
p = UnitScaleOp(1e-12, 'pico')
f = UnitScaleOp(1e-15, 'femto')
a = UnitScaleOp(1e-18, 'atto')
z = UnitScaleOp(1e-21, 'zepto')
y = UnitScaleOp(1e-24, 'yocto')
r = UnitScaleOp(1e-27, 'ronto')
q = UnitScaleOp(1e-30, 'quecto')
# Usage:
# print(1023.5@K + 34.6@M + 1000@G)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment