PageRenderTime 51ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 1ms

/saf/lib/Ext/PHPExcel/Calculation/Engineering.php

https://github.com/lux/sitellite
PHP | 2174 lines | 1563 code | 210 blank | 401 comment | 339 complexity | a900301b65939c4e8ed8bdf7ed621695 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, GPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2011 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Calculation
  23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.6, 2011-02-27
  26. */
  27. /** PHPExcel root directory */
  28. if (!defined('PHPEXCEL_ROOT')) {
  29. /**
  30. * @ignore
  31. */
  32. define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
  33. require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  34. }
  35. /** EULER */
  36. define('EULER', 2.71828182845904523536);
  37. /**
  38. * PHPExcel_Calculation_Engineering
  39. *
  40. * @category PHPExcel
  41. * @package PHPExcel_Calculation
  42. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  43. */
  44. class PHPExcel_Calculation_Engineering {
  45. private static $_conversionUnits = array( 'g' => array( 'Group' => 'Mass', 'Unit Name' => 'Gram', 'AllowPrefix' => True ),
  46. 'sg' => array( 'Group' => 'Mass', 'Unit Name' => 'Slug', 'AllowPrefix' => False ),
  47. 'lbm' => array( 'Group' => 'Mass', 'Unit Name' => 'Pound mass (avoirdupois)', 'AllowPrefix' => False ),
  48. 'u' => array( 'Group' => 'Mass', 'Unit Name' => 'U (atomic mass unit)', 'AllowPrefix' => True ),
  49. 'ozm' => array( 'Group' => 'Mass', 'Unit Name' => 'Ounce mass (avoirdupois)', 'AllowPrefix' => False ),
  50. 'm' => array( 'Group' => 'Distance', 'Unit Name' => 'Meter', 'AllowPrefix' => True ),
  51. 'mi' => array( 'Group' => 'Distance', 'Unit Name' => 'Statute mile', 'AllowPrefix' => False ),
  52. 'Nmi' => array( 'Group' => 'Distance', 'Unit Name' => 'Nautical mile', 'AllowPrefix' => False ),
  53. 'in' => array( 'Group' => 'Distance', 'Unit Name' => 'Inch', 'AllowPrefix' => False ),
  54. 'ft' => array( 'Group' => 'Distance', 'Unit Name' => 'Foot', 'AllowPrefix' => False ),
  55. 'yd' => array( 'Group' => 'Distance', 'Unit Name' => 'Yard', 'AllowPrefix' => False ),
  56. 'ang' => array( 'Group' => 'Distance', 'Unit Name' => 'Angstrom', 'AllowPrefix' => True ),
  57. 'Pica' => array( 'Group' => 'Distance', 'Unit Name' => 'Pica (1/72 in)', 'AllowPrefix' => False ),
  58. 'yr' => array( 'Group' => 'Time', 'Unit Name' => 'Year', 'AllowPrefix' => False ),
  59. 'day' => array( 'Group' => 'Time', 'Unit Name' => 'Day', 'AllowPrefix' => False ),
  60. 'hr' => array( 'Group' => 'Time', 'Unit Name' => 'Hour', 'AllowPrefix' => False ),
  61. 'mn' => array( 'Group' => 'Time', 'Unit Name' => 'Minute', 'AllowPrefix' => False ),
  62. 'sec' => array( 'Group' => 'Time', 'Unit Name' => 'Second', 'AllowPrefix' => True ),
  63. 'Pa' => array( 'Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => True ),
  64. 'p' => array( 'Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => True ),
  65. 'atm' => array( 'Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => True ),
  66. 'at' => array( 'Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => True ),
  67. 'mmHg' => array( 'Group' => 'Pressure', 'Unit Name' => 'mm of Mercury', 'AllowPrefix' => True ),
  68. 'N' => array( 'Group' => 'Force', 'Unit Name' => 'Newton', 'AllowPrefix' => True ),
  69. 'dyn' => array( 'Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => True ),
  70. 'dy' => array( 'Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => True ),
  71. 'lbf' => array( 'Group' => 'Force', 'Unit Name' => 'Pound force', 'AllowPrefix' => False ),
  72. 'J' => array( 'Group' => 'Energy', 'Unit Name' => 'Joule', 'AllowPrefix' => True ),
  73. 'e' => array( 'Group' => 'Energy', 'Unit Name' => 'Erg', 'AllowPrefix' => True ),
  74. 'c' => array( 'Group' => 'Energy', 'Unit Name' => 'Thermodynamic calorie', 'AllowPrefix' => True ),
  75. 'cal' => array( 'Group' => 'Energy', 'Unit Name' => 'IT calorie', 'AllowPrefix' => True ),
  76. 'eV' => array( 'Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => True ),
  77. 'ev' => array( 'Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => True ),
  78. 'HPh' => array( 'Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => False ),
  79. 'hh' => array( 'Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => False ),
  80. 'Wh' => array( 'Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => True ),
  81. 'wh' => array( 'Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => True ),
  82. 'flb' => array( 'Group' => 'Energy', 'Unit Name' => 'Foot-pound', 'AllowPrefix' => False ),
  83. 'BTU' => array( 'Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => False ),
  84. 'btu' => array( 'Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => False ),
  85. 'HP' => array( 'Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => False ),
  86. 'h' => array( 'Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => False ),
  87. 'W' => array( 'Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => True ),
  88. 'w' => array( 'Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => True ),
  89. 'T' => array( 'Group' => 'Magnetism', 'Unit Name' => 'Tesla', 'AllowPrefix' => True ),
  90. 'ga' => array( 'Group' => 'Magnetism', 'Unit Name' => 'Gauss', 'AllowPrefix' => True ),
  91. 'C' => array( 'Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => False ),
  92. 'cel' => array( 'Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => False ),
  93. 'F' => array( 'Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => False ),
  94. 'fah' => array( 'Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => False ),
  95. 'K' => array( 'Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => False ),
  96. 'kel' => array( 'Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => False ),
  97. 'tsp' => array( 'Group' => 'Liquid', 'Unit Name' => 'Teaspoon', 'AllowPrefix' => False ),
  98. 'tbs' => array( 'Group' => 'Liquid', 'Unit Name' => 'Tablespoon', 'AllowPrefix' => False ),
  99. 'oz' => array( 'Group' => 'Liquid', 'Unit Name' => 'Fluid Ounce', 'AllowPrefix' => False ),
  100. 'cup' => array( 'Group' => 'Liquid', 'Unit Name' => 'Cup', 'AllowPrefix' => False ),
  101. 'pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => False ),
  102. 'us_pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => False ),
  103. 'uk_pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.K. Pint', 'AllowPrefix' => False ),
  104. 'qt' => array( 'Group' => 'Liquid', 'Unit Name' => 'Quart', 'AllowPrefix' => False ),
  105. 'gal' => array( 'Group' => 'Liquid', 'Unit Name' => 'Gallon', 'AllowPrefix' => False ),
  106. 'l' => array( 'Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => True ),
  107. 'lt' => array( 'Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => True )
  108. );
  109. private static $_conversionMultipliers = array( 'Y' => array( 'multiplier' => 1E24, 'name' => 'yotta' ),
  110. 'Z' => array( 'multiplier' => 1E21, 'name' => 'zetta' ),
  111. 'E' => array( 'multiplier' => 1E18, 'name' => 'exa' ),
  112. 'P' => array( 'multiplier' => 1E15, 'name' => 'peta' ),
  113. 'T' => array( 'multiplier' => 1E12, 'name' => 'tera' ),
  114. 'G' => array( 'multiplier' => 1E9, 'name' => 'giga' ),
  115. 'M' => array( 'multiplier' => 1E6, 'name' => 'mega' ),
  116. 'k' => array( 'multiplier' => 1E3, 'name' => 'kilo' ),
  117. 'h' => array( 'multiplier' => 1E2, 'name' => 'hecto' ),
  118. 'e' => array( 'multiplier' => 1E1, 'name' => 'deka' ),
  119. 'd' => array( 'multiplier' => 1E-1, 'name' => 'deci' ),
  120. 'c' => array( 'multiplier' => 1E-2, 'name' => 'centi' ),
  121. 'm' => array( 'multiplier' => 1E-3, 'name' => 'milli' ),
  122. 'u' => array( 'multiplier' => 1E-6, 'name' => 'micro' ),
  123. 'n' => array( 'multiplier' => 1E-9, 'name' => 'nano' ),
  124. 'p' => array( 'multiplier' => 1E-12, 'name' => 'pico' ),
  125. 'f' => array( 'multiplier' => 1E-15, 'name' => 'femto' ),
  126. 'a' => array( 'multiplier' => 1E-18, 'name' => 'atto' ),
  127. 'z' => array( 'multiplier' => 1E-21, 'name' => 'zepto' ),
  128. 'y' => array( 'multiplier' => 1E-24, 'name' => 'yocto' )
  129. );
  130. private static $_unitConversions = array( 'Mass' => array( 'g' => array( 'g' => 1.0,
  131. 'sg' => 6.85220500053478E-05,
  132. 'lbm' => 2.20462291469134E-03,
  133. 'u' => 6.02217000000000E+23,
  134. 'ozm' => 3.52739718003627E-02
  135. ),
  136. 'sg' => array( 'g' => 1.45938424189287E+04,
  137. 'sg' => 1.0,
  138. 'lbm' => 3.21739194101647E+01,
  139. 'u' => 8.78866000000000E+27,
  140. 'ozm' => 5.14782785944229E+02
  141. ),
  142. 'lbm' => array( 'g' => 4.5359230974881148E+02,
  143. 'sg' => 3.10810749306493E-02,
  144. 'lbm' => 1.0,
  145. 'u' => 2.73161000000000E+26,
  146. 'ozm' => 1.60000023429410E+01
  147. ),
  148. 'u' => array( 'g' => 1.66053100460465E-24,
  149. 'sg' => 1.13782988532950E-28,
  150. 'lbm' => 3.66084470330684E-27,
  151. 'u' => 1.0,
  152. 'ozm' => 5.85735238300524E-26
  153. ),
  154. 'ozm' => array( 'g' => 2.83495152079732E+01,
  155. 'sg' => 1.94256689870811E-03,
  156. 'lbm' => 6.24999908478882E-02,
  157. 'u' => 1.70725600000000E+25,
  158. 'ozm' => 1.0
  159. )
  160. ),
  161. 'Distance' => array( 'm' => array( 'm' => 1.0,
  162. 'mi' => 6.21371192237334E-04,
  163. 'Nmi' => 5.39956803455724E-04,
  164. 'in' => 3.93700787401575E+01,
  165. 'ft' => 3.28083989501312E+00,
  166. 'yd' => 1.09361329797891E+00,
  167. 'ang' => 1.00000000000000E+10,
  168. 'Pica' => 2.83464566929116E+03
  169. ),
  170. 'mi' => array( 'm' => 1.60934400000000E+03,
  171. 'mi' => 1.0,
  172. 'Nmi' => 8.68976241900648E-01,
  173. 'in' => 6.33600000000000E+04,
  174. 'ft' => 5.28000000000000E+03,
  175. 'yd' => 1.76000000000000E+03,
  176. 'ang' => 1.60934400000000E+13,
  177. 'Pica' => 4.56191999999971E+06
  178. ),
  179. 'Nmi' => array( 'm' => 1.85200000000000E+03,
  180. 'mi' => 1.15077944802354E+00,
  181. 'Nmi' => 1.0,
  182. 'in' => 7.29133858267717E+04,
  183. 'ft' => 6.07611548556430E+03,
  184. 'yd' => 2.02537182785694E+03,
  185. 'ang' => 1.85200000000000E+13,
  186. 'Pica' => 5.24976377952723E+06
  187. ),
  188. 'in' => array( 'm' => 2.54000000000000E-02,
  189. 'mi' => 1.57828282828283E-05,
  190. 'Nmi' => 1.37149028077754E-05,
  191. 'in' => 1.0,
  192. 'ft' => 8.33333333333333E-02,
  193. 'yd' => 2.77777777686643E-02,
  194. 'ang' => 2.54000000000000E+08,
  195. 'Pica' => 7.19999999999955E+01
  196. ),
  197. 'ft' => array( 'm' => 3.04800000000000E-01,
  198. 'mi' => 1.89393939393939E-04,
  199. 'Nmi' => 1.64578833693305E-04,
  200. 'in' => 1.20000000000000E+01,
  201. 'ft' => 1.0,
  202. 'yd' => 3.33333333223972E-01,
  203. 'ang' => 3.04800000000000E+09,
  204. 'Pica' => 8.63999999999946E+02
  205. ),
  206. 'yd' => array( 'm' => 9.14400000300000E-01,
  207. 'mi' => 5.68181818368230E-04,
  208. 'Nmi' => 4.93736501241901E-04,
  209. 'in' => 3.60000000118110E+01,
  210. 'ft' => 3.00000000000000E+00,
  211. 'yd' => 1.0,
  212. 'ang' => 9.14400000300000E+09,
  213. 'Pica' => 2.59200000085023E+03
  214. ),
  215. 'ang' => array( 'm' => 1.00000000000000E-10,
  216. 'mi' => 6.21371192237334E-14,
  217. 'Nmi' => 5.39956803455724E-14,
  218. 'in' => 3.93700787401575E-09,
  219. 'ft' => 3.28083989501312E-10,
  220. 'yd' => 1.09361329797891E-10,
  221. 'ang' => 1.0,
  222. 'Pica' => 2.83464566929116E-07
  223. ),
  224. 'Pica' => array( 'm' => 3.52777777777800E-04,
  225. 'mi' => 2.19205948372629E-07,
  226. 'Nmi' => 1.90484761219114E-07,
  227. 'in' => 1.38888888888898E-02,
  228. 'ft' => 1.15740740740748E-03,
  229. 'yd' => 3.85802469009251E-04,
  230. 'ang' => 3.52777777777800E+06,
  231. 'Pica' => 1.0
  232. )
  233. ),
  234. 'Time' => array( 'yr' => array( 'yr' => 1.0,
  235. 'day' => 365.25,
  236. 'hr' => 8766.0,
  237. 'mn' => 525960.0,
  238. 'sec' => 31557600.0
  239. ),
  240. 'day' => array( 'yr' => 2.73785078713210E-03,
  241. 'day' => 1.0,
  242. 'hr' => 24.0,
  243. 'mn' => 1440.0,
  244. 'sec' => 86400.0
  245. ),
  246. 'hr' => array( 'yr' => 1.14077116130504E-04,
  247. 'day' => 4.16666666666667E-02,
  248. 'hr' => 1.0,
  249. 'mn' => 60.0,
  250. 'sec' => 3600.0
  251. ),
  252. 'mn' => array( 'yr' => 1.90128526884174E-06,
  253. 'day' => 6.94444444444444E-04,
  254. 'hr' => 1.66666666666667E-02,
  255. 'mn' => 1.0,
  256. 'sec' => 60.0
  257. ),
  258. 'sec' => array( 'yr' => 3.16880878140289E-08,
  259. 'day' => 1.15740740740741E-05,
  260. 'hr' => 2.77777777777778E-04,
  261. 'mn' => 1.66666666666667E-02,
  262. 'sec' => 1.0
  263. )
  264. ),
  265. 'Pressure' => array( 'Pa' => array( 'Pa' => 1.0,
  266. 'p' => 1.0,
  267. 'atm' => 9.86923299998193E-06,
  268. 'at' => 9.86923299998193E-06,
  269. 'mmHg' => 7.50061707998627E-03
  270. ),
  271. 'p' => array( 'Pa' => 1.0,
  272. 'p' => 1.0,
  273. 'atm' => 9.86923299998193E-06,
  274. 'at' => 9.86923299998193E-06,
  275. 'mmHg' => 7.50061707998627E-03
  276. ),
  277. 'atm' => array( 'Pa' => 1.01324996583000E+05,
  278. 'p' => 1.01324996583000E+05,
  279. 'atm' => 1.0,
  280. 'at' => 1.0,
  281. 'mmHg' => 760.0
  282. ),
  283. 'at' => array( 'Pa' => 1.01324996583000E+05,
  284. 'p' => 1.01324996583000E+05,
  285. 'atm' => 1.0,
  286. 'at' => 1.0,
  287. 'mmHg' => 760.0
  288. ),
  289. 'mmHg' => array( 'Pa' => 1.33322363925000E+02,
  290. 'p' => 1.33322363925000E+02,
  291. 'atm' => 1.31578947368421E-03,
  292. 'at' => 1.31578947368421E-03,
  293. 'mmHg' => 1.0
  294. )
  295. ),
  296. 'Force' => array( 'N' => array( 'N' => 1.0,
  297. 'dyn' => 1.0E+5,
  298. 'dy' => 1.0E+5,
  299. 'lbf' => 2.24808923655339E-01
  300. ),
  301. 'dyn' => array( 'N' => 1.0E-5,
  302. 'dyn' => 1.0,
  303. 'dy' => 1.0,
  304. 'lbf' => 2.24808923655339E-06
  305. ),
  306. 'dy' => array( 'N' => 1.0E-5,
  307. 'dyn' => 1.0,
  308. 'dy' => 1.0,
  309. 'lbf' => 2.24808923655339E-06
  310. ),
  311. 'lbf' => array( 'N' => 4.448222,
  312. 'dyn' => 4.448222E+5,
  313. 'dy' => 4.448222E+5,
  314. 'lbf' => 1.0
  315. )
  316. ),
  317. 'Energy' => array( 'J' => array( 'J' => 1.0,
  318. 'e' => 9.99999519343231E+06,
  319. 'c' => 2.39006249473467E-01,
  320. 'cal' => 2.38846190642017E-01,
  321. 'eV' => 6.24145700000000E+18,
  322. 'ev' => 6.24145700000000E+18,
  323. 'HPh' => 3.72506430801000E-07,
  324. 'hh' => 3.72506430801000E-07,
  325. 'Wh' => 2.77777916238711E-04,
  326. 'wh' => 2.77777916238711E-04,
  327. 'flb' => 2.37304222192651E+01,
  328. 'BTU' => 9.47815067349015E-04,
  329. 'btu' => 9.47815067349015E-04
  330. ),
  331. 'e' => array( 'J' => 1.00000048065700E-07,
  332. 'e' => 1.0,
  333. 'c' => 2.39006364353494E-08,
  334. 'cal' => 2.38846305445111E-08,
  335. 'eV' => 6.24146000000000E+11,
  336. 'ev' => 6.24146000000000E+11,
  337. 'HPh' => 3.72506609848824E-14,
  338. 'hh' => 3.72506609848824E-14,
  339. 'Wh' => 2.77778049754611E-11,
  340. 'wh' => 2.77778049754611E-11,
  341. 'flb' => 2.37304336254586E-06,
  342. 'BTU' => 9.47815522922962E-11,
  343. 'btu' => 9.47815522922962E-11
  344. ),
  345. 'c' => array( 'J' => 4.18399101363672E+00,
  346. 'e' => 4.18398900257312E+07,
  347. 'c' => 1.0,
  348. 'cal' => 9.99330315287563E-01,
  349. 'eV' => 2.61142000000000E+19,
  350. 'ev' => 2.61142000000000E+19,
  351. 'HPh' => 1.55856355899327E-06,
  352. 'hh' => 1.55856355899327E-06,
  353. 'Wh' => 1.16222030532950E-03,
  354. 'wh' => 1.16222030532950E-03,
  355. 'flb' => 9.92878733152102E+01,
  356. 'BTU' => 3.96564972437776E-03,
  357. 'btu' => 3.96564972437776E-03
  358. ),
  359. 'cal' => array( 'J' => 4.18679484613929E+00,
  360. 'e' => 4.18679283372801E+07,
  361. 'c' => 1.00067013349059E+00,
  362. 'cal' => 1.0,
  363. 'eV' => 2.61317000000000E+19,
  364. 'ev' => 2.61317000000000E+19,
  365. 'HPh' => 1.55960800463137E-06,
  366. 'hh' => 1.55960800463137E-06,
  367. 'Wh' => 1.16299914807955E-03,
  368. 'wh' => 1.16299914807955E-03,
  369. 'flb' => 9.93544094443283E+01,
  370. 'BTU' => 3.96830723907002E-03,
  371. 'btu' => 3.96830723907002E-03
  372. ),
  373. 'eV' => array( 'J' => 1.60219000146921E-19,
  374. 'e' => 1.60218923136574E-12,
  375. 'c' => 3.82933423195043E-20,
  376. 'cal' => 3.82676978535648E-20,
  377. 'eV' => 1.0,
  378. 'ev' => 1.0,
  379. 'HPh' => 5.96826078912344E-26,
  380. 'hh' => 5.96826078912344E-26,
  381. 'Wh' => 4.45053000026614E-23,
  382. 'wh' => 4.45053000026614E-23,
  383. 'flb' => 3.80206452103492E-18,
  384. 'BTU' => 1.51857982414846E-22,
  385. 'btu' => 1.51857982414846E-22
  386. ),
  387. 'ev' => array( 'J' => 1.60219000146921E-19,
  388. 'e' => 1.60218923136574E-12,
  389. 'c' => 3.82933423195043E-20,
  390. 'cal' => 3.82676978535648E-20,
  391. 'eV' => 1.0,
  392. 'ev' => 1.0,
  393. 'HPh' => 5.96826078912344E-26,
  394. 'hh' => 5.96826078912344E-26,
  395. 'Wh' => 4.45053000026614E-23,
  396. 'wh' => 4.45053000026614E-23,
  397. 'flb' => 3.80206452103492E-18,
  398. 'BTU' => 1.51857982414846E-22,
  399. 'btu' => 1.51857982414846E-22
  400. ),
  401. 'HPh' => array( 'J' => 2.68451741316170E+06,
  402. 'e' => 2.68451612283024E+13,
  403. 'c' => 6.41616438565991E+05,
  404. 'cal' => 6.41186757845835E+05,
  405. 'eV' => 1.67553000000000E+25,
  406. 'ev' => 1.67553000000000E+25,
  407. 'HPh' => 1.0,
  408. 'hh' => 1.0,
  409. 'Wh' => 7.45699653134593E+02,
  410. 'wh' => 7.45699653134593E+02,
  411. 'flb' => 6.37047316692964E+07,
  412. 'BTU' => 2.54442605275546E+03,
  413. 'btu' => 2.54442605275546E+03
  414. ),
  415. 'hh' => array( 'J' => 2.68451741316170E+06,
  416. 'e' => 2.68451612283024E+13,
  417. 'c' => 6.41616438565991E+05,
  418. 'cal' => 6.41186757845835E+05,
  419. 'eV' => 1.67553000000000E+25,
  420. 'ev' => 1.67553000000000E+25,
  421. 'HPh' => 1.0,
  422. 'hh' => 1.0,
  423. 'Wh' => 7.45699653134593E+02,
  424. 'wh' => 7.45699653134593E+02,
  425. 'flb' => 6.37047316692964E+07,
  426. 'BTU' => 2.54442605275546E+03,
  427. 'btu' => 2.54442605275546E+03
  428. ),
  429. 'Wh' => array( 'J' => 3.59999820554720E+03,
  430. 'e' => 3.59999647518369E+10,
  431. 'c' => 8.60422069219046E+02,
  432. 'cal' => 8.59845857713046E+02,
  433. 'eV' => 2.24692340000000E+22,
  434. 'ev' => 2.24692340000000E+22,
  435. 'HPh' => 1.34102248243839E-03,
  436. 'hh' => 1.34102248243839E-03,
  437. 'Wh' => 1.0,
  438. 'wh' => 1.0,
  439. 'flb' => 8.54294774062316E+04,
  440. 'BTU' => 3.41213254164705E+00,
  441. 'btu' => 3.41213254164705E+00
  442. ),
  443. 'wh' => array( 'J' => 3.59999820554720E+03,
  444. 'e' => 3.59999647518369E+10,
  445. 'c' => 8.60422069219046E+02,
  446. 'cal' => 8.59845857713046E+02,
  447. 'eV' => 2.24692340000000E+22,
  448. 'ev' => 2.24692340000000E+22,
  449. 'HPh' => 1.34102248243839E-03,
  450. 'hh' => 1.34102248243839E-03,
  451. 'Wh' => 1.0,
  452. 'wh' => 1.0,
  453. 'flb' => 8.54294774062316E+04,
  454. 'BTU' => 3.41213254164705E+00,
  455. 'btu' => 3.41213254164705E+00
  456. ),
  457. 'flb' => array( 'J' => 4.21400003236424E-02,
  458. 'e' => 4.21399800687660E+05,
  459. 'c' => 1.00717234301644E-02,
  460. 'cal' => 1.00649785509554E-02,
  461. 'eV' => 2.63015000000000E+17,
  462. 'ev' => 2.63015000000000E+17,
  463. 'HPh' => 1.56974211145130E-08,
  464. 'hh' => 1.56974211145130E-08,
  465. 'Wh' => 1.17055614802000E-05,
  466. 'wh' => 1.17055614802000E-05,
  467. 'flb' => 1.0,
  468. 'BTU' => 3.99409272448406E-05,
  469. 'btu' => 3.99409272448406E-05
  470. ),
  471. 'BTU' => array( 'J' => 1.05505813786749E+03,
  472. 'e' => 1.05505763074665E+10,
  473. 'c' => 2.52165488508168E+02,
  474. 'cal' => 2.51996617135510E+02,
  475. 'eV' => 6.58510000000000E+21,
  476. 'ev' => 6.58510000000000E+21,
  477. 'HPh' => 3.93015941224568E-04,
  478. 'hh' => 3.93015941224568E-04,
  479. 'Wh' => 2.93071851047526E-01,
  480. 'wh' => 2.93071851047526E-01,
  481. 'flb' => 2.50369750774671E+04,
  482. 'BTU' => 1.0,
  483. 'btu' => 1.0,
  484. ),
  485. 'btu' => array( 'J' => 1.05505813786749E+03,
  486. 'e' => 1.05505763074665E+10,
  487. 'c' => 2.52165488508168E+02,
  488. 'cal' => 2.51996617135510E+02,
  489. 'eV' => 6.58510000000000E+21,
  490. 'ev' => 6.58510000000000E+21,
  491. 'HPh' => 3.93015941224568E-04,
  492. 'hh' => 3.93015941224568E-04,
  493. 'Wh' => 2.93071851047526E-01,
  494. 'wh' => 2.93071851047526E-01,
  495. 'flb' => 2.50369750774671E+04,
  496. 'BTU' => 1.0,
  497. 'btu' => 1.0,
  498. )
  499. ),
  500. 'Power' => array( 'HP' => array( 'HP' => 1.0,
  501. 'h' => 1.0,
  502. 'W' => 7.45701000000000E+02,
  503. 'w' => 7.45701000000000E+02
  504. ),
  505. 'h' => array( 'HP' => 1.0,
  506. 'h' => 1.0,
  507. 'W' => 7.45701000000000E+02,
  508. 'w' => 7.45701000000000E+02
  509. ),
  510. 'W' => array( 'HP' => 1.34102006031908E-03,
  511. 'h' => 1.34102006031908E-03,
  512. 'W' => 1.0,
  513. 'w' => 1.0
  514. ),
  515. 'w' => array( 'HP' => 1.34102006031908E-03,
  516. 'h' => 1.34102006031908E-03,
  517. 'W' => 1.0,
  518. 'w' => 1.0
  519. )
  520. ),
  521. 'Magnetism' => array( 'T' => array( 'T' => 1.0,
  522. 'ga' => 10000.0
  523. ),
  524. 'ga' => array( 'T' => 0.0001,
  525. 'ga' => 1.0
  526. )
  527. ),
  528. 'Liquid' => array( 'tsp' => array( 'tsp' => 1.0,
  529. 'tbs' => 3.33333333333333E-01,
  530. 'oz' => 1.66666666666667E-01,
  531. 'cup' => 2.08333333333333E-02,
  532. 'pt' => 1.04166666666667E-02,
  533. 'us_pt' => 1.04166666666667E-02,
  534. 'uk_pt' => 8.67558516821960E-03,
  535. 'qt' => 5.20833333333333E-03,
  536. 'gal' => 1.30208333333333E-03,
  537. 'l' => 4.92999408400710E-03,
  538. 'lt' => 4.92999408400710E-03
  539. ),
  540. 'tbs' => array( 'tsp' => 3.00000000000000E+00,
  541. 'tbs' => 1.0,
  542. 'oz' => 5.00000000000000E-01,
  543. 'cup' => 6.25000000000000E-02,
  544. 'pt' => 3.12500000000000E-02,
  545. 'us_pt' => 3.12500000000000E-02,
  546. 'uk_pt' => 2.60267555046588E-02,
  547. 'qt' => 1.56250000000000E-02,
  548. 'gal' => 3.90625000000000E-03,
  549. 'l' => 1.47899822520213E-02,
  550. 'lt' => 1.47899822520213E-02
  551. ),
  552. 'oz' => array( 'tsp' => 6.00000000000000E+00,
  553. 'tbs' => 2.00000000000000E+00,
  554. 'oz' => 1.0,
  555. 'cup' => 1.25000000000000E-01,
  556. 'pt' => 6.25000000000000E-02,
  557. 'us_pt' => 6.25000000000000E-02,
  558. 'uk_pt' => 5.20535110093176E-02,
  559. 'qt' => 3.12500000000000E-02,
  560. 'gal' => 7.81250000000000E-03,
  561. 'l' => 2.95799645040426E-02,
  562. 'lt' => 2.95799645040426E-02
  563. ),
  564. 'cup' => array( 'tsp' => 4.80000000000000E+01,
  565. 'tbs' => 1.60000000000000E+01,
  566. 'oz' => 8.00000000000000E+00,
  567. 'cup' => 1.0,
  568. 'pt' => 5.00000000000000E-01,
  569. 'us_pt' => 5.00000000000000E-01,
  570. 'uk_pt' => 4.16428088074541E-01,
  571. 'qt' => 2.50000000000000E-01,
  572. 'gal' => 6.25000000000000E-02,
  573. 'l' => 2.36639716032341E-01,
  574. 'lt' => 2.36639716032341E-01
  575. ),
  576. 'pt' => array( 'tsp' => 9.60000000000000E+01,
  577. 'tbs' => 3.20000000000000E+01,
  578. 'oz' => 1.60000000000000E+01,
  579. 'cup' => 2.00000000000000E+00,
  580. 'pt' => 1.0,
  581. 'us_pt' => 1.0,
  582. 'uk_pt' => 8.32856176149081E-01,
  583. 'qt' => 5.00000000000000E-01,
  584. 'gal' => 1.25000000000000E-01,
  585. 'l' => 4.73279432064682E-01,
  586. 'lt' => 4.73279432064682E-01
  587. ),
  588. 'us_pt' => array( 'tsp' => 9.60000000000000E+01,
  589. 'tbs' => 3.20000000000000E+01,
  590. 'oz' => 1.60000000000000E+01,
  591. 'cup' => 2.00000000000000E+00,
  592. 'pt' => 1.0,
  593. 'us_pt' => 1.0,
  594. 'uk_pt' => 8.32856176149081E-01,
  595. 'qt' => 5.00000000000000E-01,
  596. 'gal' => 1.25000000000000E-01,
  597. 'l' => 4.73279432064682E-01,
  598. 'lt' => 4.73279432064682E-01
  599. ),
  600. 'uk_pt' => array( 'tsp' => 1.15266000000000E+02,
  601. 'tbs' => 3.84220000000000E+01,
  602. 'oz' => 1.92110000000000E+01,
  603. 'cup' => 2.40137500000000E+00,
  604. 'pt' => 1.20068750000000E+00,
  605. 'us_pt' => 1.20068750000000E+00,
  606. 'uk_pt' => 1.0,
  607. 'qt' => 6.00343750000000E-01,
  608. 'gal' => 1.50085937500000E-01,
  609. 'l' => 5.68260698087162E-01,
  610. 'lt' => 5.68260698087162E-01
  611. ),
  612. 'qt' => array( 'tsp' => 1.92000000000000E+02,
  613. 'tbs' => 6.40000000000000E+01,
  614. 'oz' => 3.20000000000000E+01,
  615. 'cup' => 4.00000000000000E+00,
  616. 'pt' => 2.00000000000000E+00,
  617. 'us_pt' => 2.00000000000000E+00,
  618. 'uk_pt' => 1.66571235229816E+00,
  619. 'qt' => 1.0,
  620. 'gal' => 2.50000000000000E-01,
  621. 'l' => 9.46558864129363E-01,
  622. 'lt' => 9.46558864129363E-01
  623. ),
  624. 'gal' => array( 'tsp' => 7.68000000000000E+02,
  625. 'tbs' => 2.56000000000000E+02,
  626. 'oz' => 1.28000000000000E+02,
  627. 'cup' => 1.60000000000000E+01,
  628. 'pt' => 8.00000000000000E+00,
  629. 'us_pt' => 8.00000000000000E+00,
  630. 'uk_pt' => 6.66284940919265E+00,
  631. 'qt' => 4.00000000000000E+00,
  632. 'gal' => 1.0,
  633. 'l' => 3.78623545651745E+00,
  634. 'lt' => 3.78623545651745E+00
  635. ),
  636. 'l' => array( 'tsp' => 2.02840000000000E+02,
  637. 'tbs' => 6.76133333333333E+01,
  638. 'oz' => 3.38066666666667E+01,
  639. 'cup' => 4.22583333333333E+00,
  640. 'pt' => 2.11291666666667E+00,
  641. 'us_pt' => 2.11291666666667E+00,
  642. 'uk_pt' => 1.75975569552166E+00,
  643. 'qt' => 1.05645833333333E+00,
  644. 'gal' => 2.64114583333333E-01,
  645. 'l' => 1.0,
  646. 'lt' => 1.0
  647. ),
  648. 'lt' => array( 'tsp' => 2.02840000000000E+02,
  649. 'tbs' => 6.76133333333333E+01,
  650. 'oz' => 3.38066666666667E+01,
  651. 'cup' => 4.22583333333333E+00,
  652. 'pt' => 2.11291666666667E+00,
  653. 'us_pt' => 2.11291666666667E+00,
  654. 'uk_pt' => 1.75975569552166E+00,
  655. 'qt' => 1.05645833333333E+00,
  656. 'gal' => 2.64114583333333E-01,
  657. 'l' => 1.0,
  658. 'lt' => 1.0
  659. )
  660. )
  661. );
  662. public static function _parseComplex($complexNumber) {
  663. $workString = (string) $complexNumber;
  664. $realNumber = $imaginary = 0;
  665. // Extract the suffix, if there is one
  666. $suffix = substr($workString,-1);
  667. if (!is_numeric($suffix)) {
  668. $workString = substr($workString,0,-1);
  669. } else {
  670. $suffix = '';
  671. }
  672. // Split the input into its Real and Imaginary components
  673. $leadingSign = 0;
  674. if (strlen($workString) > 0) {
  675. $leadingSign = (($workString{0} == '+') || ($workString{0} == '-')) ? 1 : 0;
  676. }
  677. $power = '';
  678. $realNumber = strtok($workString, '+-');
  679. if (strtoupper(substr($realNumber,-1)) == 'E') {
  680. $power = strtok('+-');
  681. ++$leadingSign;
  682. }
  683. $realNumber = substr($workString,0,strlen($realNumber)+strlen($power)+$leadingSign);
  684. if ($suffix != '') {
  685. $imaginary = substr($workString,strlen($realNumber));
  686. if (($imaginary == '') && (($realNumber == '') || ($realNumber == '+') || ($realNumber == '-'))) {
  687. $imaginary = $realNumber.'1';
  688. $realNumber = '0';
  689. } else if ($imaginary == '') {
  690. $imaginary = $realNumber;
  691. $realNumber = '0';
  692. } elseif (($imaginary == '+') || ($imaginary == '-')) {
  693. $imaginary .= '1';
  694. }
  695. }
  696. return array( 'real' => $realNumber,
  697. 'imaginary' => $imaginary,
  698. 'suffix' => $suffix
  699. );
  700. } // function _parseComplex()
  701. private static function _cleanComplex($complexNumber) {
  702. if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1);
  703. if ($complexNumber{0} == '0') $complexNumber = substr($complexNumber,1);
  704. if ($complexNumber{0} == '.') $complexNumber = '0'.$complexNumber;
  705. if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1);
  706. return $complexNumber;
  707. }
  708. private static function _nbrConversionFormat($xVal,$places) {
  709. if (!is_null($places)) {
  710. if (strlen($xVal) <= $places) {
  711. return substr(str_pad($xVal,$places,'0',STR_PAD_LEFT),-10);
  712. } else {
  713. return PHPExcel_Calculation_Functions::NaN();
  714. }
  715. }
  716. return substr($xVal,-10);
  717. } // function _nbrConversionFormat()
  718. /**
  719. * BESSELI
  720. *
  721. * Returns the modified Bessel function, which is equivalent to the Bessel function evaluated for purely imaginary arguments
  722. *
  723. * @param float $x
  724. * @param float $n
  725. * @return int
  726. */
  727. public static function BESSELI($x, $n) {
  728. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  729. $n = (is_null($n)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($n);
  730. if ((is_numeric($x)) && (is_numeric($n))) {
  731. $n = floor($n);
  732. if ($n < 0) {
  733. return PHPExcel_Calculation_Functions::NaN();
  734. }
  735. $f_2_PI = 2 * M_PI;
  736. if (abs($x) <= 30) {
  737. $fTerm = pow($x / 2, $n) / PHPExcel_Calculation_MathTrig::FACT($n);
  738. $nK = 1;
  739. $fResult = $fTerm;
  740. $fSqrX = ($x * $x) / 4;
  741. do {
  742. $fTerm *= $fSqrX;
  743. $fTerm /= ($nK * ($nK + $n));
  744. $fResult += $fTerm;
  745. } while ((abs($fTerm) > 1e-10) && (++$nK < 100));
  746. } else {
  747. $fXAbs = abs($x);
  748. $fResult = exp($fXAbs) / sqrt($f_2_PI * $fXAbs);
  749. if (($n && 1) && ($x < 0)) {
  750. $fResult = -$fResult;
  751. }
  752. }
  753. return $fResult;
  754. }
  755. return PHPExcel_Calculation_Functions::VALUE();
  756. } // function BESSELI()
  757. /**
  758. * BESSELJ
  759. *
  760. * Returns the Bessel function
  761. *
  762. * @param float $x
  763. * @param float $n
  764. * @return int
  765. */
  766. public static function BESSELJ($x, $n) {
  767. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  768. $n = (is_null($n)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($n);
  769. if ((is_numeric($x)) && (is_numeric($n))) {
  770. $n = floor($n);
  771. if ($n < 0) {
  772. return PHPExcel_Calculation_Functions::NaN();
  773. }
  774. $f_PI_DIV_2 = M_PI / 2;
  775. $f_PI_DIV_4 = M_PI / 4;
  776. $fResult = 0;
  777. if (abs($x) <= 30) {
  778. $fTerm = pow($x / 2, $n) / PHPExcel_Calculation_MathTrig::FACT($n);
  779. $nK = 1;
  780. $fResult = $fTerm;
  781. $fSqrX = ($x * $x) / -4;
  782. do {
  783. $fTerm *= $fSqrX;
  784. $fTerm /= ($nK * ($nK + $n));
  785. $fResult += $fTerm;
  786. } while ((abs($fTerm) > 1e-10) && (++$nK < 100));
  787. } else {
  788. $fXAbs = abs($x);
  789. $fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $n * $f_PI_DIV_2 - $f_PI_DIV_4);
  790. if (($n && 1) && ($x < 0)) {
  791. $fResult = -$fResult;
  792. }
  793. }
  794. return $fResult;
  795. }
  796. return PHPExcel_Calculation_Functions::VALUE();
  797. } // function BESSELJ()
  798. private static function _Besselk0($fNum) {
  799. if ($fNum <= 2) {
  800. $fNum2 = $fNum * 0.5;
  801. $y = ($fNum2 * $fNum2);
  802. $fRet = -log($fNum2) * self::BESSELI($fNum, 0) +
  803. (-0.57721566 + $y * (0.42278420 + $y * (0.23069756 + $y * (0.3488590e-1 + $y * (0.262698e-2 + $y *
  804. (0.10750e-3 + $y * 0.74e-5))))));
  805. } else {
  806. $y = 2 / $fNum;
  807. $fRet = exp(-$fNum) / sqrt($fNum) *
  808. (1.25331414 + $y * (-0.7832358e-1 + $y * (0.2189568e-1 + $y * (-0.1062446e-1 + $y *
  809. (0.587872e-2 + $y * (-0.251540e-2 + $y * 0.53208e-3))))));
  810. }
  811. return $fRet;
  812. } // function _Besselk0()
  813. private static function _Besselk1($fNum) {
  814. if ($fNum <= 2) {
  815. $fNum2 = $fNum * 0.5;
  816. $y = ($fNum2 * $fNum2);
  817. $fRet = log($fNum2) * self::BESSELI($fNum, 1) +
  818. (1 + $y * (0.15443144 + $y * (-0.67278579 + $y * (-0.18156897 + $y * (-0.1919402e-1 + $y *
  819. (-0.110404e-2 + $y * (-0.4686e-4))))))) / $fNum;
  820. } else {
  821. $y = 2 / $fNum;
  822. $fRet = exp(-$fNum) / sqrt($fNum) *
  823. (1.25331414 + $y * (0.23498619 + $y * (-0.3655620e-1 + $y * (0.1504268e-1 + $y * (-0.780353e-2 + $y *
  824. (0.325614e-2 + $y * (-0.68245e-3)))))));
  825. }
  826. return $fRet;
  827. } // function _Besselk1()
  828. /**
  829. * BESSELK
  830. *
  831. * Returns the modified Bessel function, which is equivalent to the Bessel functions evaluated for purely imaginary arguments.
  832. *
  833. * @param float $x
  834. * @param float $ord
  835. * @return float
  836. */
  837. public static function BESSELK($x, $ord) {
  838. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  839. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  840. if ((is_numeric($x)) && (is_numeric($ord))) {
  841. if (($ord < 0) || ($x == 0.0)) {
  842. return PHPExcel_Calculation_Functions::NaN();
  843. }
  844. switch(floor($ord)) {
  845. case 0 : return self::_Besselk0($x);
  846. break;
  847. case 1 : return self::_Besselk1($x);
  848. break;
  849. default : $fTox = 2 / $x;
  850. $fBkm = self::_Besselk0($x);
  851. $fBk = self::_Besselk1($x);
  852. for ($n = 1; $n < $ord; ++$n) {
  853. $fBkp = $fBkm + $n * $fTox * $fBk;
  854. $fBkm = $fBk;
  855. $fBk = $fBkp;
  856. }
  857. }
  858. return $fBk;
  859. }
  860. return PHPExcel_Calculation_Functions::VALUE();
  861. } // function BESSELK()
  862. private static function _Bessely0($fNum) {
  863. if ($fNum < 8.0) {
  864. $y = ($fNum * $fNum);
  865. $f1 = -2957821389.0 + $y * (7062834065.0 + $y * (-512359803.6 + $y * (10879881.29 + $y * (-86327.92757 + $y * 228.4622733))));
  866. $f2 = 40076544269.0 + $y * (745249964.8 + $y * (7189466.438 + $y * (47447.26470 + $y * (226.1030244 + $y))));
  867. $fRet = $f1 / $f2 + M_2DIVPI * self::BESSELJ($fNum, 0) * log($fNum);
  868. } else {
  869. $z = 8.0 / $fNum;
  870. $y = ($z * $z);
  871. $xx = $fNum - 0.785398164;
  872. $f1 = 1 + $y * (-0.1098628627e-2 + $y * (0.2734510407e-4 + $y * (-0.2073370639e-5 + $y * 0.2093887211e-6)));
  873. $f2 = -0.1562499995e-1 + $y * (0.1430488765e-3 + $y * (-0.6911147651e-5 + $y * (0.7621095161e-6 + $y * (-0.934945152e-7))));
  874. $fRet = sqrt(M_2DIVPI / $fNum) * (sin($xx) * $f1 + $z * cos($xx) * $f2);
  875. }
  876. return $fRet;
  877. } // function _Bessely0()
  878. private static function _Bessely1($fNum) {
  879. if ($fNum < 8.0) {
  880. $y = ($fNum * $fNum);
  881. $f1 = $fNum * (-0.4900604943e13 + $y * (0.1275274390e13 + $y * (-0.5153438139e11 + $y * (0.7349264551e9 + $y *
  882. (-0.4237922726e7 + $y * 0.8511937935e4)))));
  883. $f2 = 0.2499580570e14 + $y * (0.4244419664e12 + $y * (0.3733650367e10 + $y * (0.2245904002e8 + $y *
  884. (0.1020426050e6 + $y * (0.3549632885e3 + $y)))));
  885. $fRet = $f1 / $f2 + M_2DIVPI * ( self::BESSELJ($fNum, 1) * log($fNum) - 1 / $fNum);
  886. } else {
  887. $z = 8.0 / $fNum;
  888. $y = ($z * $z);
  889. $xx = $fNum - 2.356194491;
  890. $f1 = 1 + $y * (0.183105e-2 + $y * (-0.3516396496e-4 + $y * (0.2457520174e-5 + $y * (-0.240337019e6))));
  891. $f2 = 0.04687499995 + $y * (-0.2002690873e-3 + $y * (0.8449199096e-5 + $y * (-0.88228987e-6 + $y * 0.105787412e-6)));
  892. $fRet = sqrt(M_2DIVPI / $fNum) * (sin($xx) * $f1 + $z * cos($xx) * $f2);
  893. #i12430# ...but this seems to work much better.
  894. // $fRet = sqrt(M_2DIVPI / $fNum) * sin($fNum - 2.356194491);
  895. }
  896. return $fRet;
  897. } // function _Bessely1()
  898. /**
  899. * BESSELY
  900. *
  901. * Returns the Bessel function, which is also called the Weber function or the Neumann function.
  902. *
  903. * @param float $x
  904. * @param float $n
  905. * @return int
  906. */
  907. public static function BESSELY($x, $ord) {
  908. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  909. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  910. if ((is_numeric($x)) && (is_numeric($ord))) {
  911. if (($ord < 0) || ($x == 0.0)) {
  912. return PHPExcel_Calculation_Functions::NaN();
  913. }
  914. switch(floor($ord)) {
  915. case 0 : return self::_Bessely0($x);
  916. break;
  917. case 1 : return self::_Bessely1($x);
  918. break;
  919. default: $fTox = 2 / $x;
  920. $fBym = self::_Bessely0($x);
  921. $fBy = self::_Bessely1($x);
  922. for ($n = 1; $n < $ord; ++$n) {
  923. $fByp = $n * $fTox * $fBy - $fBym;
  924. $fBym = $fBy;
  925. $fBy = $fByp;
  926. }
  927. }
  928. return $fBy;
  929. }
  930. return PHPExcel_Calculation_Functions::VALUE();
  931. } // function BESSELY()
  932. /**
  933. * BINTODEC
  934. *
  935. * Return a binary value as Decimal.
  936. *
  937. * @param string $x
  938. * @return string
  939. */
  940. public static function BINTODEC($x) {
  941. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  942. if (is_bool($x)) {
  943. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  944. $x = (int) $x;
  945. } else {
  946. return PHPExcel_Calculation_Functions::VALUE();
  947. }
  948. }
  949. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  950. $x = floor($x);
  951. }
  952. $x = (string) $x;
  953. if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
  954. return PHPExcel_Calculation_Functions::NaN();
  955. }
  956. if (strlen($x) > 10) {
  957. return PHPExcel_Calculation_Functions::NaN();
  958. } elseif (strlen($x) == 10) {
  959. // Two's Complement
  960. $x = substr($x,-9);
  961. return '-'.(512-bindec($x));
  962. }
  963. return bindec($x);
  964. } // function BINTODEC()
  965. /**
  966. * BINTOHEX
  967. *
  968. * Return a binary value as Hex.
  969. *
  970. * @param string $x
  971. * @return string
  972. */
  973. public static function BINTOHEX($x, $places=null) {
  974. $x = floor(PHPExcel_Calculation_Functions::flattenSingleValue($x));
  975. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  976. if (is_bool($x)) {
  977. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  978. $x = (int) $x;
  979. } else {
  980. return PHPExcel_Calculation_Functions::VALUE();
  981. }
  982. }
  983. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  984. $x = floor($x);
  985. }
  986. $x = (string) $x;
  987. if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
  988. return PHPExcel_Calculation_Functions::NaN();
  989. }
  990. if (strlen($x) > 10) {
  991. return PHPExcel_Calculation_Functions::NaN();
  992. } elseif (strlen($x) == 10) {
  993. // Two's Complement
  994. return str_repeat('F',8).substr(strtoupper(dechex(bindec(substr($x,-9)))),-2);
  995. }
  996. $hexVal = (string) strtoupper(dechex(bindec($x)));
  997. return self::_nbrConversionFormat($hexVal,$places);
  998. } // function BINTOHEX()
  999. /**
  1000. * BINTOOCT
  1001. *
  1002. * Return a binary value as Octal.
  1003. *
  1004. * @param string $x
  1005. * @return string
  1006. */
  1007. public static function BINTOOCT($x, $places=null) {
  1008. $x = floor(PHPExcel_Calculation_Functions::flattenSingleValue($x));
  1009. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1010. if (is_bool($x)) {
  1011. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1012. $x = (int) $x;
  1013. } else {
  1014. return PHPExcel_Calculation_Functions::VALUE();
  1015. }
  1016. }
  1017. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  1018. $x = floor($x);
  1019. }
  1020. $x = (string) $x;
  1021. if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
  1022. return PHPExcel_Calculation_Functions::NaN();
  1023. }
  1024. if (strlen($x) > 10) {
  1025. return PHPExcel_Calculation_Functions::NaN();
  1026. } elseif (strlen($x) == 10) {
  1027. // Two's Complement
  1028. return str_repeat('7',7).substr(strtoupper(decoct(bindec(substr($x,-9)))),-3);
  1029. }
  1030. $octVal = (string) decoct(bindec($x));
  1031. return self::_nbrConversionFormat($octVal,$places);
  1032. } // function BINTOOCT()
  1033. /**
  1034. * DECTOBIN
  1035. *
  1036. * Return an octal value as binary.
  1037. *
  1038. * @param string $x
  1039. * @return string
  1040. */
  1041. public static function DECTOBIN($x, $places=null) {
  1042. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1043. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1044. if (is_bool($x)) {
  1045. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1046. $x = (int) $x;
  1047. } else {
  1048. return PHPExcel_Calculation_Functions::VALUE();
  1049. }
  1050. }
  1051. $x = (string) $x;
  1052. if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) {
  1053. return PHPExcel_Calculation_Functions::VALUE();
  1054. }
  1055. $x = (string) floor($x);
  1056. $r = decbin($x);
  1057. if (strlen($r) == 32) {
  1058. // Two's Complement
  1059. $r = substr($r,-10);
  1060. } elseif (strlen($r) > 11) {
  1061. return PHPExcel_Calculation_Functions::NaN();
  1062. }
  1063. return self::_nbrConversionFormat($r,$places);
  1064. } // function DECTOBIN()
  1065. /**
  1066. * DECTOHEX
  1067. *
  1068. * Return an octal value as binary.
  1069. *
  1070. * @param string $x
  1071. * @return string
  1072. */
  1073. public static function DECTOHEX($x, $places=null) {
  1074. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1075. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1076. if (is_bool($x)) {
  1077. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1078. $x = (int) $x;
  1079. } else {
  1080. return PHPExcel_Calculation_Functions::VALUE();
  1081. }
  1082. }
  1083. $x = (string) $x;
  1084. if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) {
  1085. return PHPExcel_Calculation_Functions::VALUE();
  1086. }
  1087. $x = (string) floor($x);
  1088. $r = strtoupper(dechex($x));
  1089. if (strlen($r) == 8) {
  1090. // Two's Complement
  1091. $r = 'FF'.$r;
  1092. }
  1093. return self::_nbrConversionFormat($r,$places);
  1094. } // function DECTOHEX()
  1095. /**
  1096. * DECTOOCT
  1097. *
  1098. * Return an octal value as binary.
  1099. *
  1100. * @param string $x
  1101. * @return string
  1102. */
  1103. public static function DECTOOCT($x, $places=null) {
  1104. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1105. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1106. if (is_bool($x)) {
  1107. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1108. $x = (int) $x;
  1109. } else {
  1110. return PHPExcel_Calculation_Functions::VALUE();
  1111. }
  1112. }
  1113. $x = (string) $x;
  1114. if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) {
  1115. return PHPExcel_Calculation_Functions::VALUE();
  1116. }
  1117. $x = (string) floor($x);
  1118. $r = decoct($x);
  1119. if (strlen($r) == 11) {
  1120. // Two's Complement
  1121. $r = substr($r,-10);
  1122. }
  1123. return self::_nbrConversionFormat($r,$places);
  1124. } // function DECTOOCT()
  1125. /**
  1126. * HEXTOBIN
  1127. *
  1128. * Return a hex value as binary.
  1129. *
  1130. * @param string $x
  1131. * @return string
  1132. */
  1133. public static function HEXTOBIN($x, $places=null) {
  1134. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1135. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1136. if (is_bool($x)) {
  1137. return PHPExcel_Calculation_Functions::VALUE();
  1138. }
  1139. $x = (string) $x;
  1140. if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) {
  1141. return PHPExcel_Calculation_Functions::NaN();
  1142. }
  1143. $binVal = decbin(hexdec($x));
  1144. return substr(self::_nbrConversionFormat($binVal,$places),-10);
  1145. } // function HEXTOBIN()
  1146. /**
  1147. * HEXTODEC
  1148. *
  1149. * Return a hex value as octal.
  1150. *
  1151. * @param string $x
  1152. * @return string
  1153. */
  1154. public static function HEXTODEC($x) {
  1155. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1156. if (is_bool($x)) {
  1157. return PHPExcel_Calculation_Functions::VALUE();
  1158. }
  1159. $x = (string) $x;
  1160. if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) {
  1161. return PHPExcel_Calculation_Functions::NaN();
  1162. }
  1163. return hexdec($x);
  1164. } // function HEXTODEC()
  1165. /**
  1166. * HEXTOOCT
  1167. *
  1168. * Return a hex value as octal.
  1169. *
  1170. * @param string $x
  1171. * @return string
  1172. */
  1173. public static function HEXTOOCT($x, $places=null) {
  1174. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1175. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1176. if (is_bool($x)) {
  1177. return PHPExcel_Calculation_Functions::VALUE();
  1178. }
  1179. $x = (string) $x;
  1180. if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) {
  1181. return PHPExcel_Calculation_Functions::NaN();
  1182. }
  1183. $octVal = decoct(hexdec($x));
  1184. return self::_nbrConversionFormat($octVal,$places);
  1185. } // function HEXTOOCT()
  1186. /**
  1187. * OCTTOBIN
  1188. *
  1189. * Return an octal value as binary.
  1190. *
  1191. * @param string $x
  1192. * @return string
  1193. */
  1194. public static function OCTTOBIN($x, $places=null) {
  1195. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1196. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1197. if (is_bool($x)) {
  1198. return PHPExcel_Calculation_Functions::VALUE();
  1199. }
  1200. $x = (string) $x;
  1201. if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) {
  1202. return PHPExcel_Calculation_Functions::NaN();
  1203. }
  1204. $r = decbin(octdec($x));
  1205. return self::_nbrConversionFormat($r,$places);
  1206. } // function OCTTOBIN()
  1207. /**
  1208. * OCTTODEC
  1209. *
  1210. * Return an octal value as binary.
  1211. *
  1212. * @param string $x
  1213. * @return string
  1214. */
  1215. public static function OCTTODEC($x) {
  1216. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1217. if (is_bool($x)) {
  1218. return PHPExcel_Calculation_Functions::VALUE();
  1219. }
  1220. $x = (string) $x;
  1221. if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) {
  1222. return PHPExcel_Calculation_Functions::NaN();
  1223. }
  1224. return octdec($x);
  1225. } // function OCTTODEC()
  1226. /**
  1227. * OCTTOHEX
  1228. *
  1229. * Return an octal value as hex.
  1230. *
  1231. * @param string $x
  1232. * @return string
  1233. */
  1234. public static function OCTTOHEX($x, $places=null) {
  1235. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1236. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1237. if (is_bool($x)) {
  1238. return PHPExcel_Calculation_Functions::VALUE();
  1239. }
  1240. $x = (string) $x;
  1241. if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) {
  1242. return PHPExcel_Calculation_Functions::NaN();
  1243. }
  1244. $hexVal = strtoupper(dechex(octdec($x)));
  1245. return self::_nbrConversionFormat($hexVal,$places);
  1246. } // function OCTTOHEX()
  1247. /**
  1248. * COMPLEX
  1249. *
  1250. * returns a complex number of the form x + yi or x + yj.
  1251. *
  1252. * @param float $realNumber
  1253. * @param float $imaginary
  1254. * @param string $suffix
  1255. * @return string
  1256. */
  1257. public static function COMPLEX($realNumber=0.0, $imaginary=0.0, $suffix='i') {
  1258. $realNumber = (is_null($realNumber)) ? 0.0 : (float) PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
  1259. $imaginary = (is_null($imaginary)) ? 0.0 : (float) PHPExcel_Calculation_Functions::flattenSingleValue($imaginary);
  1260. $suffix = (is_null($suffix)) ? 'i' : PHPExcel_Calculation_Functions::flattenSingleValue($suffix);
  1261. if (((is_numeric($realNumber)) && (is_numeric($imaginary))) &&
  1262. (($suffix == 'i') || ($suffix == 'j') || ($suffix == ''))) {
  1263. if ($suffix == '') $suffix = 'i';
  1264. if ($realNumber == 0.0) {
  1265. if ($imaginary == 0.0) {
  1266. return (string) '0';
  1267. } elseif ($imaginary == 1.0) {
  1268. return (string) $suffix;
  1269. } elseif ($imaginary == -1.0) {
  1270. return (string) '-'.$suffix;
  1271. }
  1272. return (string) $imaginary.$suffix;
  1273. } elseif ($imaginary == 0.0) {
  1274. return (string) $realNumber;
  1275. } elseif ($imaginary == 1.0) {
  1276. return (string) $realNumber.'+'.$suffix;
  1277. } elseif ($imaginary == -1.0) {
  1278. return (string) $realNumber.'-'.$suffix;
  1279. }
  1280. if ($imaginary > 0) { $imaginary = (string) '+'.$imaginary; }
  1281. return (string) $realNumber.$imaginary.$suffix;
  1282. }
  1283. return PHPExcel_Calculation_Functions::VALUE();
  1284. } // function COMPLEX()
  1285. /**
  1286. * IMAGINARY
  1287. *
  1288. * Returns the imaginary coefficient of a complex number in x + yi or x + yj text format.
  1289. *
  1290. * @param string $complexNumber
  1291. * @return real
  1292. */
  1293. public static function IMAGINARY($complexNumber) {
  1294. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1295. $parsedComplex = self::_parseComplex($complexNumber);
  1296. if (!is_array($parsedComplex)) {
  1297. return $parsedComplex;
  1298. }
  1299. return $parsedComplex['imaginary'];
  1300. } // function IMAGINARY()
  1301. /**
  1302. * IMREAL
  1303. *
  1304. * Returns the real coefficient of a complex number in x + yi or x + yj text format.
  1305. *
  1306. * @param string $complexNumber
  1307. * @return real
  1308. */
  1309. public static function IMREAL($complexNumber) {
  1310. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1311. $parsedComplex = self::_parseComplex($complexNumber);
  1312. if (!is_array($parsedComplex)) {
  1313. return $parsedComplex;
  1314. }
  1315. return $parsedComplex['real'];
  1316. } // function IMREAL()
  1317. /**
  1318. * IMABS
  1319. *
  1320. * Returns the absolute value (modulus) of a complex number in x + yi or x + yj text format.
  1321. *
  1322. * @param string $complexNumber
  1323. * @return real
  1324. */
  1325. public static function IMABS($complexNumber) {
  1326. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1327. $parsedComplex = self::_parseComplex($complexNumber);
  1328. if (!is_array($parsedComplex)) {
  1329. return $parsedComplex;
  1330. }
  1331. return sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']));
  1332. } // function IMABS()
  1333. /**
  1334. * IMARGUMENT
  1335. *
  1336. * Returns the argument theta of a complex number, i.e. the angle in radians from the real axis to the representation of the number in polar coordinates.
  1337. *
  1338. * @param string $complexNumber
  1339. * @return string
  1340. */
  1341. public static function IMARGUMENT($complexNumber) {
  1342. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1343. $parsedComplex = self::_parseComplex($complexNumber);
  1344. if (!is_array($parsedComplex)) {
  1345. return $parsedComplex;
  1346. }
  1347. if ($parsedComplex['real'] == 0.0) {
  1348. if ($parsedComplex['imaginary'] == 0.0) {
  1349. return 0.0;
  1350. } elseif($parsedComplex['imaginary'] < 0.0) {
  1351. return M_PI / -2;
  1352. } else {
  1353. return M_PI / 2;
  1354. }
  1355. } elseif ($parsedComplex['real'] > 0.0) {
  1356. return atan($parsedComplex['imaginary'] / $parsedComplex['real']);
  1357. } elseif ($parsedComplex['imaginary'] < 0.0) {
  1358. return 0 - (M_PI - atan(abs($parsedComplex['imaginary']) / abs($parsedComplex['real'])));
  1359. } else {
  1360. return M_PI - atan($parsedComplex['imaginary'] / abs($parsedComplex['real']));
  1361. }
  1362. } // function IMARGUMENT()
  1363. /**
  1364. * IMCONJUGATE
  1365. *
  1366. * Returns the complex conjugate of a complex number in x + yi or x + yj text format.
  1367. *
  1368. * @param string $complexNumber
  1369. * @return string
  1370. */
  1371. public static function IMCONJUGATE($complexNumber) {
  1372. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1373. $parsedComplex = self::_parseComplex($complexNumber);
  1374. if (!is_array($parsedComplex)) {
  1375. return $parsedComplex;
  1376. }
  1377. if ($parsedComplex['imaginary'] == 0.0) {
  1378. return $parsedComplex['real'];
  1379. } else {
  1380. return self::_cleanComplex(self::COMPLEX($parsedComplex['real'], 0 - $parsedComplex['imaginary'], $parsedComplex['suffix']));
  1381. }
  1382. } // function IMCONJUGATE()
  1383. /**
  1384. * IMCOS
  1385. *
  1386. * Returns the cosine of a complex number in x + yi or x + yj text format.
  1387. *
  1388. * @param string $complexNumber
  1389. * @return string
  1390. */
  1391. public static function IMCOS($complexNumber) {
  1392. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1393. $parsedComplex = self::_parseComplex($complexNumber);
  1394. if (!is_array($parsedComplex)) {
  1395. return $parsedComplex;
  1396. }
  1397. if ($parsedComplex['imaginary'] == 0.0) {
  1398. return cos($parsedComplex['real']);
  1399. } else {
  1400. return self::IMCONJUGATE(self::COMPLEX(cos($parsedComplex['real']) * cosh($parsedComplex['imaginary']),sin($parsedComplex['real']) * sinh($parsedComplex['imaginary']),$parsedComplex['suffix']));
  1401. }
  1402. } // function IMCOS()
  1403. /**
  1404. * IMSIN
  1405. *
  1406. * Returns the sine of a complex number in x + yi or x + yj text format.
  1407. *
  1408. * @param string $complexNumber
  1409. * @return string
  1410. */
  1411. public static function IMSIN($complexNumber) {
  1412. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1413. $parsedComplex = self::_parseComplex($complexNumber);
  1414. if (!is_array($parsedComplex)) {
  1415. return $parsedComplex;
  1416. }
  1417. if ($parsedComplex['imaginary'] == 0.0) {
  1418. return sin($parsedComplex['real']);
  1419. } else {
  1420. return self::COMPLEX(sin($parsedComplex['real']) * cosh($parsedComplex['imaginary']),cos($parsedComplex['real']) * sinh($parsedComplex['imaginary']),$parsedComplex['suffix']);
  1421. }
  1422. } // function IMSIN()
  1423. /**
  1424. * IMSQRT
  1425. *
  1426. * Returns the square root of a complex number in x + yi or x + yj text format.
  1427. *
  1428. * @param string $complexNumber
  1429. * @return string
  1430. */
  1431. public static function IMSQRT($complexNumber) {
  1432. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1433. $parsedComplex = self::_parseComplex($complexNumber);
  1434. if (!is_array($parsedComplex)) {
  1435. return $parsedComplex;
  1436. }
  1437. $theta = self::IMARGUMENT($complexNumber);
  1438. $d1 = cos($theta / 2);
  1439. $d2 = sin($theta / 2);
  1440. $r = sqrt(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
  1441. if ($parsedComplex['suffix'] == '') {
  1442. return self::COMPLEX($d1 * $r,$d2 * $r);
  1443. } else {
  1444. return self::COMPLEX($d1 * $r,$d2 * $r,$parsedComplex['suffix']);
  1445. }
  1446. } // function IMSQRT()
  1447. /**
  1448. * IMLN
  1449. *
  1450. * Returns the natural logarithm of a complex number in x + yi or x + yj text format.
  1451. *
  1452. * @param string $complexNumber
  1453. * @return string
  1454. */
  1455. public static function IMLN($complexNumber) {
  1456. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1457. $parsedComplex = self::_parseComplex($complexNumber);
  1458. if (!is_array($parsedComplex)) {
  1459. return $parsedComplex;
  1460. }
  1461. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1462. return PHPExcel_Calculation_Functions::NaN();
  1463. }
  1464. $logR = log(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
  1465. $t = self::IMARGUMENT($complexNumber);
  1466. if ($parsedComplex['suffix'] == '') {
  1467. return self::COMPLEX($logR,$t);
  1468. } else {
  1469. return self::COMPLEX($logR,$t,$parsedComplex['suffix']);
  1470. }
  1471. } // function IMLN()
  1472. /**
  1473. * IMLOG10
  1474. *
  1475. * Returns the common logarithm (base 10) of a complex number in x + yi or x + yj text format.
  1476. *
  1477. * @param string $complexNumber
  1478. * @return string
  1479. */
  1480. public static function IMLOG10($complexNumber) {
  1481. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1482. $parsedComplex = self::_parseComplex($complexNumber);
  1483. if (!is_array($parsedComplex)) {
  1484. return $parsedComplex;
  1485. }
  1486. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1487. return PHPExcel_Calculation_Functions::NaN();
  1488. } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1489. return log10($parsedComplex['real']);
  1490. }
  1491. return self::IMPRODUCT(log10(EULER),self::IMLN($complexNumber));
  1492. } // function IMLOG10()
  1493. /**
  1494. * IMLOG2
  1495. *
  1496. * Returns the common logarithm (base 10) of a complex number in x + yi or x + yj text format.
  1497. *
  1498. * @param string $complexNumber
  1499. * @return string
  1500. */
  1501. public static function IMLOG2($complexNumber) {
  1502. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1503. $parsedComplex = self::_parseComplex($complexNumber);
  1504. if (!is_array($parsedComplex)) {
  1505. return $parsedComplex;
  1506. }
  1507. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1508. return PHPExcel_Calculation_Functions::NaN();
  1509. } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1510. return log($parsedComplex['real'],2);
  1511. }
  1512. return self::IMPRODUCT(log(EULER,2),self::IMLN($complexNumber));
  1513. } // function IMLOG2()
  1514. /**
  1515. * IMEXP
  1516. *
  1517. * Returns the exponential of a complex number in x + yi or x + yj text format.
  1518. *
  1519. * @param string $complexNumber
  1520. * @return string
  1521. */
  1522. public static function IMEXP($complexNumber) {
  1523. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1524. $parsedComplex = self::_parseComplex($complexNumber);
  1525. if (!is_array($parsedComplex)) {
  1526. return $parsedComplex;
  1527. }
  1528. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1529. return '1';
  1530. }
  1531. $e = exp($parsedComplex['real']);
  1532. $eX = $e * cos($parsedComplex['imaginary']);
  1533. $eY = $e * sin($parsedComplex['imaginary']);
  1534. if ($parsedComplex['suffix'] == '') {
  1535. return self::COMPLEX($eX,$eY);
  1536. } else {
  1537. return self::COMPLEX($eX,$eY,$parsedComplex['suffix']);
  1538. }
  1539. } // function IMEXP()
  1540. /**
  1541. * IMPOWER
  1542. *
  1543. * Returns a complex number in x + yi or x + yj text format raised to a power.
  1544. *
  1545. * @param string $complexNumber
  1546. * @return string
  1547. */
  1548. public static function IMPOWER($complexNumber,$realNumber) {
  1549. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1550. $realNumber = PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
  1551. if (!is_numeric($realNumber)) {
  1552. return PHPExcel_Calculation_Functions::VALUE();
  1553. }
  1554. $parsedComplex = self::_parseComplex($complexNumber);
  1555. if (!is_array($parsedComplex)) {
  1556. return $parsedComplex;
  1557. }
  1558. $r = sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']));
  1559. $rPower = pow($r,$realNumber);
  1560. $theta = self::IMARGUMENT($complexNumber) * $realNumber;
  1561. if ($theta == 0) {
  1562. return 1;
  1563. } elseif ($parsedComplex['imaginary'] == 0.0) {
  1564. return self::COMPLEX($rPower * cos($theta),$rPower * sin($theta),$parsedComplex['suffix']);
  1565. } else {
  1566. return self::COMPLEX($rPower * cos($theta),$rPower * sin($theta),$parsedComplex['suffix']);
  1567. }
  1568. } // function IMPOWER()
  1569. /**
  1570. * IMDIV
  1571. *
  1572. * Returns the quotient of two complex numbers in x + yi or x + yj text format.
  1573. *
  1574. * @param string $complexDividend
  1575. * @param string $complexDivisor
  1576. * @return real
  1577. */
  1578. public static function IMDIV($complexDividend,$complexDivisor) {
  1579. $complexDividend = PHPExcel_Calculation_Functions::flattenSingleValue($complexDividend);
  1580. $complexDivisor = PHPExcel_Calculation_Functions::flattenSingleValue($complexDivisor);
  1581. $parsedComplexDividend = self::_parseComplex($complexDividend);
  1582. if (!is_array($parsedComplexDividend)) {
  1583. return $parsedComplexDividend;
  1584. }
  1585. $parsedComplexDivisor = self::_parseComplex($complexDivisor);
  1586. if (!is_array($parsedComplexDivisor)) {
  1587. return $parsedComplexDividend;
  1588. }
  1589. if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') &&
  1590. ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) {
  1591. return PHPExcel_Calculation_Functions::NaN();
  1592. }
  1593. if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] == '')) {
  1594. $parsedComplexDivisor['suffix'] = $parsedComplexDividend['suffix'];
  1595. }
  1596. $d1 = ($parsedComplexDividend['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['imaginary']);
  1597. $d2 = ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['real']) - ($parsedComplexDividend['real'] * $parsedComplexDivisor['imaginary']);
  1598. $d3 = ($parsedComplexDivisor['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDivisor['imaginary'] * $parsedComplexDivisor['imaginary']);
  1599. $r = $d1/$d3;
  1600. $i = $d2/$d3;
  1601. if ($i > 0.0) {
  1602. return self::_cleanComplex($r.'+'.$i.$parsedComplexDivisor['suffix']);
  1603. } elseif ($i < 0.0) {
  1604. return self::_cleanComplex($r.$i.$parsedComplexDivisor['suffix']);
  1605. } else {
  1606. return $r;
  1607. }
  1608. } // function IMDIV()
  1609. /**
  1610. * IMSUB
  1611. *
  1612. * Returns the difference of two complex numbers in x + yi or x + yj text format.
  1613. *
  1614. * @param string $complexNumber1
  1615. * @param string $complexNumber2
  1616. * @return real
  1617. */
  1618. public static function IMSUB($complexNumber1,$complexNumber2) {
  1619. $complexNumber1 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber1);
  1620. $complexNumber2 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber2);
  1621. $parsedComplex1 = self::_parseComplex($complexNumber1);
  1622. if (!is_array($parsedComplex1)) {
  1623. return $parsedComplex1;
  1624. }
  1625. $parsedComplex2 = self::_parseComplex($complexNumber2);
  1626. if (!is_array($parsedComplex2)) {
  1627. return $parsedComplex2;
  1628. }
  1629. if ((($parsedComplex1['suffix'] != '') && ($parsedComplex2['suffix'] != '')) &&
  1630. ($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) {
  1631. return PHPExcel_Calculation_Functions::NaN();
  1632. } elseif (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) {
  1633. $parsedComplex1['suffix'] = $parsedComplex2['suffix'];
  1634. }
  1635. $d1 = $parsedComplex1['real'] - $parsedComplex2['real'];
  1636. $d2 = $parsedComplex1['imaginary'] - $parsedComplex2['imaginary'];
  1637. return self::COMPLEX($d1,$d2,$parsedComplex1['suffix']);
  1638. } // function IMSUB()
  1639. /**
  1640. * IMSUM
  1641. *
  1642. * Returns the sum of two or more complex numbers in x + yi or x + yj text format.
  1643. *
  1644. * @param array of mixed Data Series
  1645. * @return real
  1646. */
  1647. public static function IMSUM() {
  1648. // Return value
  1649. $returnValue = self::_parseComplex('0');
  1650. $activeSuffix = '';
  1651. // Loop through the arguments
  1652. $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
  1653. foreach ($aArgs as $arg) {
  1654. $parsedComplex = self::_parseComplex($arg);
  1655. if (!is_array($parsedComplex)) {
  1656. return $parsedComplex;
  1657. }
  1658. if ($activeSuffix == '') {
  1659. $activeSuffix = $parsedComplex['suffix'];
  1660. } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
  1661. return PHPExcel_Calculation_Functions::VALUE();
  1662. }
  1663. $returnValue['real'] += $parsedComplex['real'];
  1664. $returnValue['imaginary'] += $parsedComplex['imaginary'];
  1665. }
  1666. if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; }
  1667. return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix);
  1668. } // function IMSUM()
  1669. /**
  1670. * IMPRODUCT
  1671. *
  1672. * Returns the product of two or more complex numbers in x + yi or x + yj text format.
  1673. *
  1674. * @param array of mixed Data Series
  1675. * @return real
  1676. */
  1677. public static function IMPRODUCT() {
  1678. // Return value
  1679. $returnValue = self::_parseComplex('1');
  1680. $activeSuffix = '';
  1681. // Loop through the arguments
  1682. $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
  1683. foreach ($aArgs as $arg) {
  1684. $parsedComplex = self::_parseComplex($arg);
  1685. if (!is_array($parsedComplex)) {
  1686. return $parsedComplex;
  1687. }
  1688. $workValue = $returnValue;
  1689. if (($parsedComplex['suffix'] != '') && ($activeSuffix == '')) {
  1690. $activeSuffix = $parsedComplex['suffix'];
  1691. } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
  1692. return PHPExcel_Calculation_Functions::NaN();
  1693. }
  1694. $returnValue['real'] = ($workValue['real'] * $parsedComplex['real']) - ($workValue['imaginary'] * $parsedComplex['imaginary']);
  1695. $returnValue['imaginary'] = ($workValue['real'] * $parsedComplex['imaginary']) + ($workValue['imaginary'] * $parsedComplex['real']);
  1696. }
  1697. if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; }
  1698. return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix);
  1699. } // function IMPRODUCT()
  1700. /**
  1701. * DELTA
  1702. *
  1703. * Tests whether two values are equal. Returns 1 if number1 = number2; returns 0 otherwise.
  1704. *
  1705. * @param float $a
  1706. * @param float $b
  1707. * @return int
  1708. */
  1709. public static function DELTA($a, $b=0) {
  1710. $a = PHPExcel_Calculation_Functions::flattenSingleValue($a);
  1711. $b = PHPExcel_Calculation_Functions::flattenSingleValue($b);
  1712. return (int) ($a == $b);
  1713. } // function DELTA()
  1714. /**
  1715. * GESTEP
  1716. *
  1717. * Returns 1 if number = step; returns 0 (zero) otherwise
  1718. *
  1719. * @param float $number
  1720. * @param float $step
  1721. * @return int
  1722. */
  1723. public static function GESTEP($number, $step=0) {
  1724. $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
  1725. $step = PHPExcel_Calculation_Functions::flattenSingleValue($step);
  1726. return (int) ($number >= $step);
  1727. } // function GESTEP()
  1728. //
  1729. // Private method to calculate the erf value
  1730. //
  1731. private static $_two_sqrtpi = 1.128379167095512574;
  1732. public static function _erfVal($x) {
  1733. if (abs($x) > 2.2) {
  1734. return 1 - self::_erfcVal($x);
  1735. }
  1736. $sum = $term = $x;
  1737. $xsqr = ($x * $x);
  1738. $j = 1;
  1739. do {
  1740. $term *= $xsqr / $j;
  1741. $sum -= $term / (2 * $j + 1);
  1742. ++$j;
  1743. $term *= $xsqr / $j;
  1744. $sum += $term / (2 * $j + 1);
  1745. ++$j;
  1746. if ($sum == 0.0) {
  1747. break;
  1748. }
  1749. } while (abs($term / $sum) > PRECISION);
  1750. return self::$_two_sqrtpi * $sum;
  1751. } // function _erfVal()
  1752. /**
  1753. * ERF
  1754. *
  1755. * Returns the error function integrated between lower_limit and upper_limit
  1756. *
  1757. * @param float $lower lower bound for integrating ERF
  1758. * @param float $upper upper bound for integrating ERF.
  1759. * If omitted, ERF integrates between zero and lower_limit
  1760. * @return int
  1761. */
  1762. public static function ERF($lower, $upper = null) {
  1763. $lower = PHPExcel_Calculation_Functions::flattenSingleValue($lower);
  1764. $upper = PHPExcel_Calculation_Functions::flattenSingleValue($upper);
  1765. if (is_numeric($lower)) {
  1766. if ($lower < 0) {
  1767. return PHPExcel_Calculation_Functions::NaN();
  1768. }
  1769. if (is_null($upper)) {
  1770. return self::_erfVal($lower);
  1771. }
  1772. if (is_numeric($upper)) {
  1773. if ($upper < 0) {
  1774. return PHPExcel_Calculation_Functions::NaN();
  1775. }
  1776. return self::_erfVal($upper) - self::_erfVal($lower);
  1777. }
  1778. }
  1779. return PHPExcel_Calculation_Functions::VALUE();
  1780. } // function ERF()
  1781. //
  1782. // Private method to calculate the erfc value
  1783. //
  1784. private static $_one_sqrtpi = 0.564189583547756287;
  1785. private static function _erfcVal($x) {
  1786. if (abs($x) < 2.2) {
  1787. return 1 - self::_erfVal($x);
  1788. }
  1789. if ($x < 0) {
  1790. return 2 - self::ERFC(-$x);
  1791. }
  1792. $a = $n = 1;
  1793. $b = $c = $x;
  1794. $d = ($x * $x) + 0.5;
  1795. $q1 = $q2 = $b / $d;
  1796. $t = 0;
  1797. do {
  1798. $t = $a * $n + $b * $x;
  1799. $a = $b;
  1800. $b = $t;
  1801. $t = $c * $n + $d * $x;
  1802. $c = $d;
  1803. $d = $t;
  1804. $n += 0.5;
  1805. $q1 = $q2;
  1806. $q2 = $b / $d;
  1807. } while ((abs($q1 - $q2) / $q2) > PRECISION);
  1808. return self::$_one_sqrtpi * exp(-$x * $x) * $q2;
  1809. } // function _erfcVal()
  1810. /**
  1811. * ERFC
  1812. *
  1813. * Returns the complementary ERF function integrated between x and infinity
  1814. *
  1815. * @param float $x The lower bound for integrating ERF
  1816. * @return int
  1817. */
  1818. public static function ERFC($x) {
  1819. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1820. if (is_numeric($x)) {
  1821. if ($x < 0) {
  1822. return PHPExcel_Calculation_Functions::NaN();
  1823. }
  1824. return self::_erfcVal($x);
  1825. }
  1826. return PHPExcel_Calculation_Functions::VALUE();
  1827. } // function ERFC()
  1828. /**
  1829. * getConversionGroups
  1830. *
  1831. * @return array
  1832. */
  1833. public static function getConversionGroups() {
  1834. $conversionGroups = array();
  1835. foreach(self::$_conversionUnits as $conversionUnit) {
  1836. $conversionGroups[] = $conversionUnit['Group'];
  1837. }
  1838. return array_merge(array_unique($conversionGroups));
  1839. } // function getConversionGroups()
  1840. /**
  1841. * getConversionGroupUnits
  1842. *
  1843. * @return array
  1844. */
  1845. public static function getConversionGroupUnits($group = NULL) {
  1846. $conversionGroups = array();
  1847. foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) {
  1848. if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
  1849. $conversionGroups[$conversionGroup['Group']][] = $conversionUnit;
  1850. }
  1851. }
  1852. return $conversionGroups;
  1853. } // function getConversionGroupUnits()
  1854. /**
  1855. * getConversionGroupUnitDetails
  1856. *
  1857. * @return array
  1858. */
  1859. public static function getConversionGroupUnitDetails($group = NULL) {
  1860. $conversionGroups = array();
  1861. foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) {
  1862. if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
  1863. $conversionGroups[$conversionGroup['Group']][] = array( 'unit' => $conversionUnit,
  1864. 'description' => $conversionGroup['Unit Name']
  1865. );
  1866. }
  1867. }
  1868. return $conversionGroups;
  1869. } // function getConversionGroupUnitDetails()
  1870. /**
  1871. * getConversionGroups
  1872. *
  1873. * @return array
  1874. */
  1875. public static function getConversionMultipliers() {
  1876. return self::$_conversionMultipliers;
  1877. } // function getConversionGroups()
  1878. /**
  1879. * CONVERTUOM
  1880. *
  1881. * @param float $value
  1882. * @param string $fromUOM
  1883. * @param string $toUOM
  1884. * @return float
  1885. */
  1886. public static function CONVERTUOM($value, $fromUOM, $toUOM) {
  1887. $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
  1888. $fromUOM = PHPExcel_Calculation_Functions::flattenSingleValue($fromUOM);
  1889. $toUOM = PHPExcel_Calculation_Functions::flattenSingleValue($toUOM);
  1890. if (!is_numeric($value)) {
  1891. return PHPExcel_Calculation_Functions::VALUE();
  1892. }
  1893. $fromMultiplier = 1;
  1894. if (isset(self::$_conversionUnits[$fromUOM])) {
  1895. $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group'];
  1896. } else {
  1897. $fromMultiplier = substr($fromUOM,0,1);
  1898. $fromUOM = substr($fromUOM,1);
  1899. if (isset(self::$_conversionMultipliers[$fromMultiplier])) {
  1900. $fromMultiplier = self::$_conversionMultipliers[$fromMultiplier]['multiplier'];
  1901. } else {
  1902. return PHPExcel_Calculation_Functions::NA();
  1903. }
  1904. if ((isset(self::$_conversionUnits[$fromUOM])) && (self::$_conversionUnits[$fromUOM]['AllowPrefix'])) {
  1905. $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group'];
  1906. } else {
  1907. return PHPExcel_Calculation_Functions::NA();
  1908. }
  1909. }
  1910. $value *= $fromMultiplier;
  1911. $toMultiplier = 1;
  1912. if (isset(self::$_conversionUnits[$toUOM])) {
  1913. $unitGroup2 = self::$_conversionUnits[$toUOM]['Group'];
  1914. } else {
  1915. $toMultiplier = substr($toUOM,0,1);
  1916. $toUOM = substr($toUOM,1);
  1917. if (isset(self::$_conversionMultipliers[$toMultiplier])) {
  1918. $toMultiplier = self::$_conversionMultipliers[$toMultiplier]['multiplier'];
  1919. } else {
  1920. return PHPExcel_Calculation_Functions::NA();
  1921. }
  1922. if ((isset(self::$_conversionUnits[$toUOM])) && (self::$_conversionUnits[$toUOM]['AllowPrefix'])) {
  1923. $unitGroup2 = self::$_conversionUnits[$toUOM]['Group'];
  1924. } else {
  1925. return PHPExcel_Calculation_Functions::NA();
  1926. }
  1927. }
  1928. if ($unitGroup1 != $unitGroup2) {
  1929. return PHPExcel_Calculation_Functions::NA();
  1930. }
  1931. if ($fromUOM == $toUOM) {
  1932. return 1.0;
  1933. } elseif ($unitGroup1 == 'Temperature') {
  1934. if (($fromUOM == 'F') || ($fromUOM == 'fah')) {
  1935. if (($toUOM == 'F') || ($toUOM == 'fah')) {
  1936. return 1.0;
  1937. } else {
  1938. $value = (($value - 32) / 1.8);
  1939. if (($toUOM == 'K') || ($toUOM == 'kel')) {
  1940. $value += 273.15;
  1941. }
  1942. return $value;
  1943. }
  1944. } elseif ((($fromUOM == 'K') || ($fromUOM == 'kel')) &&
  1945. (($toUOM == 'K') || ($toUOM == 'kel'))) {
  1946. return 1.0;
  1947. } elseif ((($fromUOM == 'C') || ($fromUOM == 'cel')) &&
  1948. (($toUOM == 'C') || ($toUOM == 'cel'))) {
  1949. return 1.0;
  1950. }
  1951. if (($toUOM == 'F') || ($toUOM == 'fah')) {
  1952. if (($fromUOM == 'K') || ($fromUOM == 'kel')) {
  1953. $value -= 273.15;
  1954. }
  1955. return ($value * 1.8) + 32;
  1956. }
  1957. if (($toUOM == 'C') || ($toUOM == 'cel')) {
  1958. return $value - 273.15;
  1959. }
  1960. return $value + 273.15;
  1961. }
  1962. return ($value * self::$_unitConversions[$unitGroup1][$fromUOM][$toUOM]) / $toMultiplier;
  1963. } // function CONVERTUOM()
  1964. } // class PHPExcel_Calculation_Engineering