version 5.4.0
remove CORS default header from PIHTTPServer fix several docs fix PIMathVector::dot return type add units directory with PIUnits facility
This commit is contained in:
82
libs/main/units/piunits_class_temperature.cpp
Normal file
82
libs/main/units/piunits_class_temperature.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Temperature units
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piunits_class_temperature.h"
|
||||
|
||||
|
||||
PIString PIUnits::Class::Temperature::name(int type) const {
|
||||
switch (type) {
|
||||
case Kelvin: return "Kelvin"_tr("PIUnitsTemperature");
|
||||
case Celsius: return "Celsius"_tr("PIUnitsTemperature");
|
||||
case Fahrenheit: return "Fahrenheit"_tr("PIUnitsTemperature");
|
||||
}
|
||||
return Class::Internal::unknown;
|
||||
}
|
||||
|
||||
|
||||
PIString PIUnits::Class::Temperature::unit(int type) const {
|
||||
switch (type) {
|
||||
case Kelvin: return "K"_tr("PIUnitsTemperature");
|
||||
case Celsius: return "°C"_tr("PIUnitsTemperature");
|
||||
case Fahrenheit: return "°F"_tr("PIUnitsTemperature");
|
||||
}
|
||||
return Class::Internal::unknown;
|
||||
}
|
||||
|
||||
|
||||
double PIUnits::Class::Temperature::convert(double v, int from, int to) const {
|
||||
double K = v;
|
||||
switch (from) {
|
||||
case Celsius: K += 273.15; break;
|
||||
case Fahrenheit: K = (v + 459.67) * (5. / 9.); break;
|
||||
default: break;
|
||||
}
|
||||
switch (to) {
|
||||
case Celsius: return K - 273.15;
|
||||
case Fahrenheit: return (K * (9. / 5.) - 459.67);
|
||||
default: break;
|
||||
}
|
||||
return K;
|
||||
}
|
||||
|
||||
|
||||
PIString PIUnits::Class::Temperature::valueToString(double v, char format, int prec) const {
|
||||
return PIString::fromNumber(v, format, prec);
|
||||
}
|
||||
|
||||
|
||||
bool PIUnits::Class::Temperature::supportPrefixes(int type) const {
|
||||
if (type == Kelvin) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PIUnits::Class::Temperature::supportPrefixesNon3(int type) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PIUnits::Class::Temperature::supportPrefixesGreater(int type) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PIUnits::Class::Temperature::supportPrefixesSmaller(int type) const {
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user