Typica is a free program for professional coffee roasters. https://typica.us
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

units.cpp 3.7KB

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