also add unit THz as requested

This commit is contained in:
donovaly
2019-12-23 02:49:30 +01:00
committed by wwmayer
parent 63bc9c5683
commit 9c707479a6
8 changed files with 322 additions and 304 deletions

View File

@@ -174,6 +174,7 @@ EXPO [eE][-+]?[0-9]+
"kHz" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloHertz; yylval.quantity.unitStr = yytext; return UNIT; // kilo Hertz
"MHz" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaHertz; yylval.quantity.unitStr = yytext; return UNIT; // mega Hertz
"GHz" COUNTCHARS; yylval.quantity.scaler = Quantity::GigaHertz; yylval.quantity.unitStr = yytext; return UNIT; // giga Hertz
"THz" COUNTCHARS; yylval.quantity.scaler = Quantity::TeraHertz; yylval.quantity.unitStr = yytext; return UNIT; // tera Hertz
"ug" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroGram; yylval.quantity.unitStr = yytext; return UNIT; // micro gram
"\xC2\xB5g" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroGram; yylval.quantity.unitStr = yytext; return UNIT; // micro gram

View File

@@ -645,6 +645,7 @@ App.Units.Hertz = App.Units.Quantity('Hz')
App.Units.KiloHertz = App.Units.Quantity('kHz')
App.Units.MegaHertz = App.Units.Quantity('MHz')
App.Units.GigaHertz = App.Units.Quantity('GHz')
App.Units.TeraHertz = App.Units.Quantity('THz')
App.Units.MicroGram = App.Units.Quantity('ug')
App.Units.MilliGram = App.Units.Quantity('mg')

View File

@@ -258,6 +258,7 @@ Quantity Quantity::Hertz (1.0 ,Unit(0,0,-1));
Quantity Quantity::KiloHertz (1.0e3 ,Unit(0,0,-1));
Quantity Quantity::MegaHertz (1.0e6 ,Unit(0,0,-1));
Quantity Quantity::GigaHertz (1.0e9 ,Unit(0,0,-1));
Quantity Quantity::TeraHertz (1.0e12 ,Unit(0,0,-1));
Quantity Quantity::MicroGram (1.0e-9 ,Unit(0,1));
Quantity Quantity::MilliGram (1.0e-6 ,Unit(0,1));

View File

@@ -195,6 +195,7 @@ public:
static Quantity KiloHertz;
static Quantity MegaHertz;
static Quantity GigaHertz;
static Quantity TeraHertz;
static Quantity MicroGram;
static Quantity MilliGram;

File diff suppressed because it is too large Load Diff

View File

@@ -65,6 +65,7 @@ CGRP '\,'[0-9][0-9][0-9]
"kHz" yylval = Quantity::KiloHertz; return UNIT; // kilo Hertz
"MHz" yylval = Quantity::MegaHertz; return UNIT; // mega Hertz
"GHz" yylval = Quantity::GigaHertz; return UNIT; // giga Hertz
"THz" yylval = Quantity::TeraHertz; return UNIT; // tera Hertz
"ug" yylval = Quantity::MicroGram; return UNIT; // micro gram
"\xC2\xB5g" yylval = Quantity::MicroGram; return UNIT; // micro gram

View File

@@ -342,21 +342,25 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact
}
}
else if (unit == Unit::Frequency) {
if (UnitValue < 1000.0) {
if (UnitValue < 1e3) {
unitString = QString::fromLatin1("Hz");
factor = 1.0;
}
else if (UnitValue < 1000000.0) {
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("kHz");
factor = 1000.0;
factor = 1e3;
}
else if (UnitValue < 1000000000.0) {
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("MHz");
factor = 1000000.0;
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("GHz");
factor = 1e9;
}
else {
unitString = QString::fromLatin1("GHz");
factor = 1000000000.0;
unitString = QString::fromLatin1("THz");
factor = 1e12;
}
}
else if (unit == Unit::Velocity) {

View File

@@ -345,21 +345,25 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
factor = 1.0;
}
else if (unit == Unit::Frequency) {
if (UnitValue < 1000.0) {
if (UnitValue < 1e3) {
unitString = QString::fromLatin1("Hz");
factor = 1.0;
}
else if (UnitValue < 1000000.0) {
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("kHz");
factor = 1000.0;
factor = 1e3;
}
else if (UnitValue < 1000000000.0) {
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("MHz");
factor = 1000000.0;
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("GHz");
factor = 1e9;
}
else {
unitString = QString::fromLatin1("GHz");
factor = 1000000000.0;
unitString = QString::fromLatin1("THz");
factor = 1e12;
}
}
else if (unit == Unit::Velocity) {