Skip to content

Draft: parse prefix as scale factor

Henrike Fleischhack requested to merge issue_prefix into main

Siehe #17 (closed)

Klappt jetzt fast alles. Es kann sein, dass nicht alle Ausgabenmodi die Scale-Faktoren enthalten. Ich habe auch noch nicht die Integration mit dccQuantities getestet.

Die Umrechnung in Base-Einheiten hat auch noch ein paar Probleme, siehe Test-case unten. Bin aber nicht sicher, ob das in den gleichen PR gehört.

Test-Code
from dsiUnits import dsiUnit

u_cm = dsiUnit(r"\centi\metre")
u_m = dsiUnit(r"\metre")
u_s = dsiUnit(r"\second")


u_cm2 = dsiUnit(r"\centi\metre\tothe{2}")
u_mcm = dsiUnit(r"\metre\centi\metre")
u_cmm = dsiUnit(r"\centi\metre\metre")

u_cm1 = dsiUnit(r"\centi\metre\tothe{-1}")
u_pcm = dsiUnit(r"\one\per\centi\metre")


print(f"s * cm = {u_s*u_cm} = {(u_s*u_cm).toBaseUnitTree()}")
print(f"cm * s = {u_cm*u_s} = {(u_cm*u_s).toBaseUnitTree()}")
print(f"cm * m = {u_cm*u_m} = {(u_cm*u_m).toBaseUnitTree()}")
print(f"m * cm = {u_m*u_cm} = {(u_m*u_cm).toBaseUnitTree()}")
print("")

print(f"cm = {u_cm} = {u_cm.toBaseUnitTree()}" )
print(f"cm2 = {u_cm2} = {u_cm2.toBaseUnitTree()}" )
print("")

print(f"cm-1 = {u_cm1} = {u_cm1.toBaseUnitTree()}" )
print(f"1/cm = {u_pcm} = {u_pcm.toBaseUnitTree()}" )
print("")

print(f"cm2^-1 = {u_cm2**-1} = {(u_cm2**-1).toBaseUnitTree()} " )
print(f"cm / (cm2) = {u_cm/u_cm2} = {(u_cm/u_cm2).toBaseUnitTree()}" )

print("")
print(f"cm2 / m = {u_cm2/u_m} = {(u_cm2/u_m).toBaseUnitTree()}" )
print(f"m*cm / (cm2) = {u_mcm/u_cm2} = {(u_mcm/u_cm2).toBaseUnitTree()}" )
print("")

u_eV = dsiUnit(r"\electronvolt")
u_J = dsiUnit(r"\joule")
print(f"eV = {u_eV} = {u_eV.toBaseUnitTree()}")
print(f"J = {u_J} = {u_J.toBaseUnitTree()}")
print(f"eV/J = {(u_eV/u_J)} = {(u_eV/u_J).toBaseUnitTree()}")
print(f"J*eV = {u_J*u_eV} = {(u_J*u_eV).toBaseUnitTree()}")
Ausgabe
s * cm = 0.01*\metre\second = 0.01*\metre\second
cm * s = 0.01*\metre\second = 0.01*\metre\second
cm * m = 0.01*\metre\tothe{2} = 0.01*\metre\tothe{2}
m * cm = 0.01*\metre\tothe{2} = 0.01*\metre\tothe{2}

cm = 0.01*\metre = 0.01*\metre
cm2 = 0.0001*\metre\tothe{2} = 0.0001*\metre\tothe{2}

cm-1 = 100.0*\metre\tothe{-1} = 100.0*\metre\tothe{-1}
1/cm = \one\per0.01*\metre = 100.0*\metre\tothe{-1}

cm2^-1 = 10000.0*\metre\tothe{-2} = 10000.0*\metre\tothe{-2}
cm / (cm2) = \one\per0.01*\metre = 100.0*\metre\tothe{-1}

cm2 / m = 0.0001*\metre = 0.0001*\metre
m*cm / (cm2) = 100.0*\one = 100.0*\one

eV = \electronvolt = 1.602176634e-19*\joule
J = \joule = \kilogram\metre\tothe{2}\second\tothe{-2}
eV/J = \electronvolt\per\joule = 1.602176634e-19*\joule\kilogram\tothe{-1}\metre\tothe{-2}\second\tothe{2}
J*eV = \electronvolt\joule = 1.602176634e-19*\joule\kilogram\metre\tothe{2}\second\tothe{-2}

Merge request reports