123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- /*279:*/
- #line 42 "./units.w"
-
- #include "units.h"
- #include <QtDebug>
-
- /*:279*//*280:*/
- #line 53 "./units.w"
-
- bool Units::isTemperatureUnit(Unit unit)
- {
- return(unit==Fahrenheit||
- unit==Celsius||
- unit==Kelvin||
- unit==Rankine);
- }
-
- /*:280*//*281:*/
- #line 71 "./units.w"
-
- double Units::convertTemperature(double value,Unit fromUnit,Unit toUnit)
- {
- if(!(isTemperatureUnit(fromUnit)&&isTemperatureUnit(toUnit)))
- {
- return 0;
- }
- switch(fromUnit)
- {
- case Fahrenheit:
- switch(toUnit)
- {
- case Fahrenheit:
- return value;
- break;
- case Celsius:
- return(value-32.0)*5.0/9.0;
- break;
- case Kelvin:
- return(value+459.67)*5.0/9.0;
- break;
- case Rankine:
- return value+459.67;
- break;
- default:
- qDebug()<<"Warning: Non-sensical unit conversion.";
- break;
- }
- break;
- case Celsius:
- switch(toUnit)
- {
- case Fahrenheit:
- return value*9.0/5.0+32.0;
- break;
- case Celsius:
- return value;
- break;
- case Kelvin:
- return value+273.15;
- break;
- case Rankine:
- return(value+273.15)*9.0/5.0;
- break;
- default:
- qDebug()<<"Warning: Non-sensical unit conversion.";
- break;
- }
- break;
- case Kelvin:
- switch(toUnit)
- {
- case Fahrenheit:
- return value*5.0/9.0-459.67;
- break;
- case Celsius:
- return value-273.15;
- break;
- case Kelvin:
- return value;
- break;
- case Rankine:
- return value*9.0/5.0;
- break;
- default:
- qDebug()<<"Warning: Non-sensical unit conversion.";
- break;
- }
- break;
- case Rankine:
- switch(toUnit)
- {
- case Fahrenheit:
- return value-457.67;
- break;
- case Celsius:
- return(value-491.67)*5.0/9.0;
- break;
- case Kelvin:
- return value*5.0/9.0;
- break;
- case Rankine:
- return value;
- break;
- default:
- qDebug()<<"Warning: Non-sensical unit conversion.";
- break;
- }
- break;
- default:
- return 0;
- break;
- }
- return 0;
- }
-
- /*:281*//*282:*/
- #line 169 "./units.w"
-
- double Units::convertRelativeTemperature(double value,Unit fromUnit,Unit toUnit)
- {
- if(!(isTemperatureUnit(fromUnit)&&isTemperatureUnit(toUnit)))
- {
- return 0;
- }
- switch(fromUnit)
- {
- case Fahrenheit:
- switch(toUnit)
- {
- case Fahrenheit:
- return value;
- break;
- case Celsius:
- return value*(5.0/9.0);
- break;
- case Kelvin:
- return value*(5.0/9.0);
- break;
- case Rankine:
- return value;
- break;
- default:
- return 0;
- break;
- }
- break;
- case Celsius:
- switch(toUnit)
- {
- case Fahrenheit:
- return value*(9.0/5.0);
- break;
- case Celsius:
- return value;
- break;
- case Kelvin:
- return value;
- break;
- case Rankine:
- return value*(9.0/5.0);
- break;
- default:
- return 0;
- break;
- }
- break;
- case Kelvin:
- switch(toUnit)
- {
- case Fahrenheit:
- return value*(5.0/9.0);
- break;
- case Celsius:
- return value;
- break;
- case Kelvin:
- return value;
- break;
- case Rankine:
- return value*(9.0/5.0);
- break;
- default:
- return 0;
- break;
- }
- break;
- case Rankine:
- switch(toUnit)
- {
- case Fahrenheit:
- return value;
- break;
- case Celsius:
- return value*(5.0/9.0);
- break;
- case Kelvin:
- return value*(5.0/9.0);
- break;
- case Rankine:
- return value;
- break;
- default:
- return 0;
- break;
- }
- break;
- default:
- return 0;
- break;
- }
- return 0;
- }
-
- /*:282*//*283:*/
- #line 267 "./units.w"
-
- double Units::convertWeight(double value,Unit fromUnit,Unit toUnit)
- {
- if(isWeightUnit(fromUnit)&&isWeightUnit(toUnit))
- {
- switch(fromUnit)
- {
- case Pound:
- switch(toUnit)
- {
- case Pound:
- return value;
- break;
- case Kilogram:
- return value/2.2;
- break;
- case Ounce:
- return value*16.0;
- break;
- case Gram:
- return value/0.0022;
- break;
- default:
- return 0;
- break;
- }
- break;
- case Kilogram:
- switch(toUnit)
- {
- case Pound:
- return value*2.2;
- break;
- case Kilogram:
- return value;
- break;
- case Ounce:
- return value*35.2;
- break;
- case Gram:
- return value*1000.0;
- break;
- default:
- return 0;
- break;
- }
- break;
- case Ounce:
- switch(toUnit)
- {
- case Pound:
- return value/16.0;
- break;
- case Kilogram:
- return value/35.2;
- break;
- case Ounce:
- return value;
- break;
- case Gram:
- return value/0.0352;
- break;
- default:
- return 0;
- break;
- }
- break;
- case Gram:
- switch(toUnit)
- {
- case Pound:
- return value*0.0022;
- break;
- case Kilogram:
- return value/1000.0;
- break;
- case Ounce:
- return value*0.0352;
- break;
- case Gram:
- return value;
- break;
- default:
- return 0;
- break;
- }
- break;
- default:
- return 0;
- break;
- }
- }
- return 0;
- }
-
- bool Units::isWeightUnit(Unit unit)
- {
- return(unit==Pound||
- unit==Kilogram||
- unit==Ounce||
- unit==Gram);
- }
-
- /*:283*/
|