Typica is a free program for professional coffee roasters. https://typica.us
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

units.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*269:*/
  2. #line 42 "./units.w"
  3. #include "units.h"
  4. #include <QtDebug>
  5. /*:269*//*270:*/
  6. #line 53 "./units.w"
  7. bool Units::isTemperatureUnit(Unit unit)
  8. {
  9. return(unit==Fahrenheit||
  10. unit==Celsius||
  11. unit==Kelvin||
  12. unit==Rankine);
  13. }
  14. /*:270*//*271:*/
  15. #line 71 "./units.w"
  16. double Units::convertTemperature(double value,Unit fromUnit,Unit toUnit)
  17. {
  18. if(!(isTemperatureUnit(fromUnit)&&isTemperatureUnit(toUnit)))
  19. {
  20. return 0;
  21. }
  22. switch(fromUnit)
  23. {
  24. case Fahrenheit:
  25. switch(toUnit)
  26. {
  27. case Fahrenheit:
  28. return value;
  29. break;
  30. case Celsius:
  31. return(value-32.0)*5.0/9.0;
  32. break;
  33. case Kelvin:
  34. return(value+459.67)*5.0/9.0;
  35. break;
  36. case Rankine:
  37. return value+459.67;
  38. break;
  39. default:
  40. qDebug()<<"Warning: Non-sensical unit conversion.";
  41. break;
  42. }
  43. break;
  44. case Celsius:
  45. switch(toUnit)
  46. {
  47. case Fahrenheit:
  48. return value*9.0/5.0+32.0;
  49. break;
  50. case Celsius:
  51. return value;
  52. break;
  53. case Kelvin:
  54. return value+273.15;
  55. break;
  56. case Rankine:
  57. return(value+273.15)*9.0/5.0;
  58. break;
  59. default:
  60. qDebug()<<"Warning: Non-sensical unit conversion.";
  61. break;
  62. }
  63. break;
  64. case Kelvin:
  65. switch(toUnit)
  66. {
  67. case Fahrenheit:
  68. return value*5.0/9.0-459.67;
  69. break;
  70. case Celsius:
  71. return value-273.15;
  72. break;
  73. case Kelvin:
  74. return value;
  75. break;
  76. case Rankine:
  77. return value*9.0/5.0;
  78. break;
  79. default:
  80. qDebug()<<"Warning: Non-sensical unit conversion.";
  81. break;
  82. }
  83. break;
  84. case Rankine:
  85. switch(toUnit)
  86. {
  87. case Fahrenheit:
  88. return value-457.67;
  89. break;
  90. case Celsius:
  91. return(value-491.67)*5.0/9.0;
  92. break;
  93. case Kelvin:
  94. return value*5.0/9.0;
  95. break;
  96. case Rankine:
  97. return value;
  98. break;
  99. default:
  100. qDebug()<<"Warning: Non-sensical unit conversion.";
  101. break;
  102. }
  103. break;
  104. default:
  105. return 0;
  106. break;
  107. }
  108. return 0;
  109. }
  110. /*:271*//*272:*/
  111. #line 169 "./units.w"
  112. double Units::convertRelativeTemperature(double value,Unit fromUnit,Unit toUnit)
  113. {
  114. if(!(isTemperatureUnit(fromUnit)&&isTemperatureUnit(toUnit)))
  115. {
  116. return 0;
  117. }
  118. switch(fromUnit)
  119. {
  120. case Fahrenheit:
  121. switch(toUnit)
  122. {
  123. case Fahrenheit:
  124. return value;
  125. break;
  126. case Celsius:
  127. return value*(5.0/9.0);
  128. break;
  129. case Kelvin:
  130. return value*(5.0/9.0);
  131. break;
  132. case Rankine:
  133. return value;
  134. break;
  135. default:
  136. return 0;
  137. break;
  138. }
  139. break;
  140. case Celsius:
  141. switch(toUnit)
  142. {
  143. case Fahrenheit:
  144. return value*(9.0/5.0);
  145. break;
  146. case Celsius:
  147. return value;
  148. break;
  149. case Kelvin:
  150. return value;
  151. break;
  152. case Rankine:
  153. return value*(9.0/5.0);
  154. break;
  155. default:
  156. return 0;
  157. break;
  158. }
  159. break;
  160. case Kelvin:
  161. switch(toUnit)
  162. {
  163. case Fahrenheit:
  164. return value*(5.0/9.0);
  165. break;
  166. case Celsius:
  167. return value;
  168. break;
  169. case Kelvin:
  170. return value;
  171. break;
  172. case Rankine:
  173. return value*(9.0/5.0);
  174. break;
  175. default:
  176. return 0;
  177. break;
  178. }
  179. break;
  180. case Rankine:
  181. switch(toUnit)
  182. {
  183. case Fahrenheit:
  184. return value;
  185. break;
  186. case Celsius:
  187. return value*(5.0/9.0);
  188. break;
  189. case Kelvin:
  190. return value*(5.0/9.0);
  191. break;
  192. case Rankine:
  193. return value;
  194. break;
  195. default:
  196. return 0;
  197. break;
  198. }
  199. break;
  200. default:
  201. return 0;
  202. break;
  203. }
  204. return 0;
  205. }
  206. /*:272*//*273:*/
  207. #line 267 "./units.w"
  208. double Units::convertWeight(double value,Unit fromUnit,Unit toUnit)
  209. {
  210. if(isWeightUnit(fromUnit)&&isWeightUnit(toUnit))
  211. {
  212. switch(fromUnit)
  213. {
  214. case Pound:
  215. switch(toUnit)
  216. {
  217. case Pound:
  218. return value;
  219. break;
  220. case Kilogram:
  221. return value/2.2;
  222. break;
  223. case Ounce:
  224. return value*16.0;
  225. break;
  226. case Gram:
  227. return value/0.0022;
  228. break;
  229. default:
  230. return 0;
  231. break;
  232. }
  233. break;
  234. case Kilogram:
  235. switch(toUnit)
  236. {
  237. case Pound:
  238. return value*2.2;
  239. break;
  240. case Kilogram:
  241. return value;
  242. break;
  243. case Ounce:
  244. return value*35.2;
  245. break;
  246. case Gram:
  247. return value*1000.0;
  248. break;
  249. default:
  250. return 0;
  251. break;
  252. }
  253. break;
  254. case Ounce:
  255. switch(toUnit)
  256. {
  257. case Pound:
  258. return value/16.0;
  259. break;
  260. case Kilogram:
  261. return value/35.2;
  262. break;
  263. case Ounce:
  264. return value;
  265. break;
  266. case Gram:
  267. return value/0.0352;
  268. break;
  269. default:
  270. return 0;
  271. break;
  272. }
  273. break;
  274. case Gram:
  275. switch(toUnit)
  276. {
  277. case Pound:
  278. return value*0.0022;
  279. break;
  280. case Kilogram:
  281. return value/1000.0;
  282. break;
  283. case Ounce:
  284. return value*0.0352;
  285. break;
  286. case Gram:
  287. return value;
  288. break;
  289. default:
  290. return 0;
  291. break;
  292. }
  293. break;
  294. default:
  295. return 0;
  296. break;
  297. }
  298. }
  299. return 0;
  300. }
  301. bool Units::isWeightUnit(Unit unit)
  302. {
  303. return(unit==Pound||
  304. unit==Kilogram||
  305. unit==Ounce||
  306. unit==Gram);
  307. }
  308. /*:273*/