PageRenderTime 69ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/libraries/PHPExcel/PHPExcel/Calculation/Engineering.php

https://bitbucket.org/thomashii/vtigercrm-6-for-postgresql
PHP | 2509 lines | 1505 code | 212 blank | 792 comment | 320 complexity | 858d083f65fc584cb91bfb0087335e9a MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-2.0, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2012 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 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.7, 2012-05-19
  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 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  43. */
  44. class PHPExcel_Calculation_Engineering {
  45. /**
  46. * Details of the Units of measure that can be used in CONVERTUOM()
  47. *
  48. * @var mixed[]
  49. */
  50. private static $_conversionUnits = array( 'g' => array( 'Group' => 'Mass', 'Unit Name' => 'Gram', 'AllowPrefix' => True ),
  51. 'sg' => array( 'Group' => 'Mass', 'Unit Name' => 'Slug', 'AllowPrefix' => False ),
  52. 'lbm' => array( 'Group' => 'Mass', 'Unit Name' => 'Pound mass (avoirdupois)', 'AllowPrefix' => False ),
  53. 'u' => array( 'Group' => 'Mass', 'Unit Name' => 'U (atomic mass unit)', 'AllowPrefix' => True ),
  54. 'ozm' => array( 'Group' => 'Mass', 'Unit Name' => 'Ounce mass (avoirdupois)', 'AllowPrefix' => False ),
  55. 'm' => array( 'Group' => 'Distance', 'Unit Name' => 'Meter', 'AllowPrefix' => True ),
  56. 'mi' => array( 'Group' => 'Distance', 'Unit Name' => 'Statute mile', 'AllowPrefix' => False ),
  57. 'Nmi' => array( 'Group' => 'Distance', 'Unit Name' => 'Nautical mile', 'AllowPrefix' => False ),
  58. 'in' => array( 'Group' => 'Distance', 'Unit Name' => 'Inch', 'AllowPrefix' => False ),
  59. 'ft' => array( 'Group' => 'Distance', 'Unit Name' => 'Foot', 'AllowPrefix' => False ),
  60. 'yd' => array( 'Group' => 'Distance', 'Unit Name' => 'Yard', 'AllowPrefix' => False ),
  61. 'ang' => array( 'Group' => 'Distance', 'Unit Name' => 'Angstrom', 'AllowPrefix' => True ),
  62. 'Pica' => array( 'Group' => 'Distance', 'Unit Name' => 'Pica (1/72 in)', 'AllowPrefix' => False ),
  63. 'yr' => array( 'Group' => 'Time', 'Unit Name' => 'Year', 'AllowPrefix' => False ),
  64. 'day' => array( 'Group' => 'Time', 'Unit Name' => 'Day', 'AllowPrefix' => False ),
  65. 'hr' => array( 'Group' => 'Time', 'Unit Name' => 'Hour', 'AllowPrefix' => False ),
  66. 'mn' => array( 'Group' => 'Time', 'Unit Name' => 'Minute', 'AllowPrefix' => False ),
  67. 'sec' => array( 'Group' => 'Time', 'Unit Name' => 'Second', 'AllowPrefix' => True ),
  68. 'Pa' => array( 'Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => True ),
  69. 'p' => array( 'Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => True ),
  70. 'atm' => array( 'Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => True ),
  71. 'at' => array( 'Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => True ),
  72. 'mmHg' => array( 'Group' => 'Pressure', 'Unit Name' => 'mm of Mercury', 'AllowPrefix' => True ),
  73. 'N' => array( 'Group' => 'Force', 'Unit Name' => 'Newton', 'AllowPrefix' => True ),
  74. 'dyn' => array( 'Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => True ),
  75. 'dy' => array( 'Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => True ),
  76. 'lbf' => array( 'Group' => 'Force', 'Unit Name' => 'Pound force', 'AllowPrefix' => False ),
  77. 'J' => array( 'Group' => 'Energy', 'Unit Name' => 'Joule', 'AllowPrefix' => True ),
  78. 'e' => array( 'Group' => 'Energy', 'Unit Name' => 'Erg', 'AllowPrefix' => True ),
  79. 'c' => array( 'Group' => 'Energy', 'Unit Name' => 'Thermodynamic calorie', 'AllowPrefix' => True ),
  80. 'cal' => array( 'Group' => 'Energy', 'Unit Name' => 'IT calorie', 'AllowPrefix' => True ),
  81. 'eV' => array( 'Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => True ),
  82. 'ev' => array( 'Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => True ),
  83. 'HPh' => array( 'Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => False ),
  84. 'hh' => array( 'Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => False ),
  85. 'Wh' => array( 'Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => True ),
  86. 'wh' => array( 'Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => True ),
  87. 'flb' => array( 'Group' => 'Energy', 'Unit Name' => 'Foot-pound', 'AllowPrefix' => False ),
  88. 'BTU' => array( 'Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => False ),
  89. 'btu' => array( 'Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => False ),
  90. 'HP' => array( 'Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => False ),
  91. 'h' => array( 'Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => False ),
  92. 'W' => array( 'Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => True ),
  93. 'w' => array( 'Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => True ),
  94. 'T' => array( 'Group' => 'Magnetism', 'Unit Name' => 'Tesla', 'AllowPrefix' => True ),
  95. 'ga' => array( 'Group' => 'Magnetism', 'Unit Name' => 'Gauss', 'AllowPrefix' => True ),
  96. 'C' => array( 'Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => False ),
  97. 'cel' => array( 'Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => False ),
  98. 'F' => array( 'Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => False ),
  99. 'fah' => array( 'Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => False ),
  100. 'K' => array( 'Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => False ),
  101. 'kel' => array( 'Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => False ),
  102. 'tsp' => array( 'Group' => 'Liquid', 'Unit Name' => 'Teaspoon', 'AllowPrefix' => False ),
  103. 'tbs' => array( 'Group' => 'Liquid', 'Unit Name' => 'Tablespoon', 'AllowPrefix' => False ),
  104. 'oz' => array( 'Group' => 'Liquid', 'Unit Name' => 'Fluid Ounce', 'AllowPrefix' => False ),
  105. 'cup' => array( 'Group' => 'Liquid', 'Unit Name' => 'Cup', 'AllowPrefix' => False ),
  106. 'pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => False ),
  107. 'us_pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => False ),
  108. 'uk_pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.K. Pint', 'AllowPrefix' => False ),
  109. 'qt' => array( 'Group' => 'Liquid', 'Unit Name' => 'Quart', 'AllowPrefix' => False ),
  110. 'gal' => array( 'Group' => 'Liquid', 'Unit Name' => 'Gallon', 'AllowPrefix' => False ),
  111. 'l' => array( 'Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => True ),
  112. 'lt' => array( 'Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => True )
  113. );
  114. /**
  115. * Details of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM()
  116. *
  117. * @var mixed[]
  118. */
  119. private static $_conversionMultipliers = array( 'Y' => array( 'multiplier' => 1E24, 'name' => 'yotta' ),
  120. 'Z' => array( 'multiplier' => 1E21, 'name' => 'zetta' ),
  121. 'E' => array( 'multiplier' => 1E18, 'name' => 'exa' ),
  122. 'P' => array( 'multiplier' => 1E15, 'name' => 'peta' ),
  123. 'T' => array( 'multiplier' => 1E12, 'name' => 'tera' ),
  124. 'G' => array( 'multiplier' => 1E9, 'name' => 'giga' ),
  125. 'M' => array( 'multiplier' => 1E6, 'name' => 'mega' ),
  126. 'k' => array( 'multiplier' => 1E3, 'name' => 'kilo' ),
  127. 'h' => array( 'multiplier' => 1E2, 'name' => 'hecto' ),
  128. 'e' => array( 'multiplier' => 1E1, 'name' => 'deka' ),
  129. 'd' => array( 'multiplier' => 1E-1, 'name' => 'deci' ),
  130. 'c' => array( 'multiplier' => 1E-2, 'name' => 'centi' ),
  131. 'm' => array( 'multiplier' => 1E-3, 'name' => 'milli' ),
  132. 'u' => array( 'multiplier' => 1E-6, 'name' => 'micro' ),
  133. 'n' => array( 'multiplier' => 1E-9, 'name' => 'nano' ),
  134. 'p' => array( 'multiplier' => 1E-12, 'name' => 'pico' ),
  135. 'f' => array( 'multiplier' => 1E-15, 'name' => 'femto' ),
  136. 'a' => array( 'multiplier' => 1E-18, 'name' => 'atto' ),
  137. 'z' => array( 'multiplier' => 1E-21, 'name' => 'zepto' ),
  138. 'y' => array( 'multiplier' => 1E-24, 'name' => 'yocto' )
  139. );
  140. /**
  141. * Details of the Units of measure conversion factors, organised by group
  142. *
  143. * @var mixed[]
  144. */
  145. private static $_unitConversions = array( 'Mass' => array( 'g' => array( 'g' => 1.0,
  146. 'sg' => 6.85220500053478E-05,
  147. 'lbm' => 2.20462291469134E-03,
  148. 'u' => 6.02217000000000E+23,
  149. 'ozm' => 3.52739718003627E-02
  150. ),
  151. 'sg' => array( 'g' => 1.45938424189287E+04,
  152. 'sg' => 1.0,
  153. 'lbm' => 3.21739194101647E+01,
  154. 'u' => 8.78866000000000E+27,
  155. 'ozm' => 5.14782785944229E+02
  156. ),
  157. 'lbm' => array( 'g' => 4.5359230974881148E+02,
  158. 'sg' => 3.10810749306493E-02,
  159. 'lbm' => 1.0,
  160. 'u' => 2.73161000000000E+26,
  161. 'ozm' => 1.60000023429410E+01
  162. ),
  163. 'u' => array( 'g' => 1.66053100460465E-24,
  164. 'sg' => 1.13782988532950E-28,
  165. 'lbm' => 3.66084470330684E-27,
  166. 'u' => 1.0,
  167. 'ozm' => 5.85735238300524E-26
  168. ),
  169. 'ozm' => array( 'g' => 2.83495152079732E+01,
  170. 'sg' => 1.94256689870811E-03,
  171. 'lbm' => 6.24999908478882E-02,
  172. 'u' => 1.70725600000000E+25,
  173. 'ozm' => 1.0
  174. )
  175. ),
  176. 'Distance' => array( 'm' => array( 'm' => 1.0,
  177. 'mi' => 6.21371192237334E-04,
  178. 'Nmi' => 5.39956803455724E-04,
  179. 'in' => 3.93700787401575E+01,
  180. 'ft' => 3.28083989501312E+00,
  181. 'yd' => 1.09361329797891E+00,
  182. 'ang' => 1.00000000000000E+10,
  183. 'Pica' => 2.83464566929116E+03
  184. ),
  185. 'mi' => array( 'm' => 1.60934400000000E+03,
  186. 'mi' => 1.0,
  187. 'Nmi' => 8.68976241900648E-01,
  188. 'in' => 6.33600000000000E+04,
  189. 'ft' => 5.28000000000000E+03,
  190. 'yd' => 1.76000000000000E+03,
  191. 'ang' => 1.60934400000000E+13,
  192. 'Pica' => 4.56191999999971E+06
  193. ),
  194. 'Nmi' => array( 'm' => 1.85200000000000E+03,
  195. 'mi' => 1.15077944802354E+00,
  196. 'Nmi' => 1.0,
  197. 'in' => 7.29133858267717E+04,
  198. 'ft' => 6.07611548556430E+03,
  199. 'yd' => 2.02537182785694E+03,
  200. 'ang' => 1.85200000000000E+13,
  201. 'Pica' => 5.24976377952723E+06
  202. ),
  203. 'in' => array( 'm' => 2.54000000000000E-02,
  204. 'mi' => 1.57828282828283E-05,
  205. 'Nmi' => 1.37149028077754E-05,
  206. 'in' => 1.0,
  207. 'ft' => 8.33333333333333E-02,
  208. 'yd' => 2.77777777686643E-02,
  209. 'ang' => 2.54000000000000E+08,
  210. 'Pica' => 7.19999999999955E+01
  211. ),
  212. 'ft' => array( 'm' => 3.04800000000000E-01,
  213. 'mi' => 1.89393939393939E-04,
  214. 'Nmi' => 1.64578833693305E-04,
  215. 'in' => 1.20000000000000E+01,
  216. 'ft' => 1.0,
  217. 'yd' => 3.33333333223972E-01,
  218. 'ang' => 3.04800000000000E+09,
  219. 'Pica' => 8.63999999999946E+02
  220. ),
  221. 'yd' => array( 'm' => 9.14400000300000E-01,
  222. 'mi' => 5.68181818368230E-04,
  223. 'Nmi' => 4.93736501241901E-04,
  224. 'in' => 3.60000000118110E+01,
  225. 'ft' => 3.00000000000000E+00,
  226. 'yd' => 1.0,
  227. 'ang' => 9.14400000300000E+09,
  228. 'Pica' => 2.59200000085023E+03
  229. ),
  230. 'ang' => array( 'm' => 1.00000000000000E-10,
  231. 'mi' => 6.21371192237334E-14,
  232. 'Nmi' => 5.39956803455724E-14,
  233. 'in' => 3.93700787401575E-09,
  234. 'ft' => 3.28083989501312E-10,
  235. 'yd' => 1.09361329797891E-10,
  236. 'ang' => 1.0,
  237. 'Pica' => 2.83464566929116E-07
  238. ),
  239. 'Pica' => array( 'm' => 3.52777777777800E-04,
  240. 'mi' => 2.19205948372629E-07,
  241. 'Nmi' => 1.90484761219114E-07,
  242. 'in' => 1.38888888888898E-02,
  243. 'ft' => 1.15740740740748E-03,
  244. 'yd' => 3.85802469009251E-04,
  245. 'ang' => 3.52777777777800E+06,
  246. 'Pica' => 1.0
  247. )
  248. ),
  249. 'Time' => array( 'yr' => array( 'yr' => 1.0,
  250. 'day' => 365.25,
  251. 'hr' => 8766.0,
  252. 'mn' => 525960.0,
  253. 'sec' => 31557600.0
  254. ),
  255. 'day' => array( 'yr' => 2.73785078713210E-03,
  256. 'day' => 1.0,
  257. 'hr' => 24.0,
  258. 'mn' => 1440.0,
  259. 'sec' => 86400.0
  260. ),
  261. 'hr' => array( 'yr' => 1.14077116130504E-04,
  262. 'day' => 4.16666666666667E-02,
  263. 'hr' => 1.0,
  264. 'mn' => 60.0,
  265. 'sec' => 3600.0
  266. ),
  267. 'mn' => array( 'yr' => 1.90128526884174E-06,
  268. 'day' => 6.94444444444444E-04,
  269. 'hr' => 1.66666666666667E-02,
  270. 'mn' => 1.0,
  271. 'sec' => 60.0
  272. ),
  273. 'sec' => array( 'yr' => 3.16880878140289E-08,
  274. 'day' => 1.15740740740741E-05,
  275. 'hr' => 2.77777777777778E-04,
  276. 'mn' => 1.66666666666667E-02,
  277. 'sec' => 1.0
  278. )
  279. ),
  280. 'Pressure' => array( 'Pa' => array( 'Pa' => 1.0,
  281. 'p' => 1.0,
  282. 'atm' => 9.86923299998193E-06,
  283. 'at' => 9.86923299998193E-06,
  284. 'mmHg' => 7.50061707998627E-03
  285. ),
  286. 'p' => array( 'Pa' => 1.0,
  287. 'p' => 1.0,
  288. 'atm' => 9.86923299998193E-06,
  289. 'at' => 9.86923299998193E-06,
  290. 'mmHg' => 7.50061707998627E-03
  291. ),
  292. 'atm' => array( 'Pa' => 1.01324996583000E+05,
  293. 'p' => 1.01324996583000E+05,
  294. 'atm' => 1.0,
  295. 'at' => 1.0,
  296. 'mmHg' => 760.0
  297. ),
  298. 'at' => array( 'Pa' => 1.01324996583000E+05,
  299. 'p' => 1.01324996583000E+05,
  300. 'atm' => 1.0,
  301. 'at' => 1.0,
  302. 'mmHg' => 760.0
  303. ),
  304. 'mmHg' => array( 'Pa' => 1.33322363925000E+02,
  305. 'p' => 1.33322363925000E+02,
  306. 'atm' => 1.31578947368421E-03,
  307. 'at' => 1.31578947368421E-03,
  308. 'mmHg' => 1.0
  309. )
  310. ),
  311. 'Force' => array( 'N' => array( 'N' => 1.0,
  312. 'dyn' => 1.0E+5,
  313. 'dy' => 1.0E+5,
  314. 'lbf' => 2.24808923655339E-01
  315. ),
  316. 'dyn' => array( 'N' => 1.0E-5,
  317. 'dyn' => 1.0,
  318. 'dy' => 1.0,
  319. 'lbf' => 2.24808923655339E-06
  320. ),
  321. 'dy' => array( 'N' => 1.0E-5,
  322. 'dyn' => 1.0,
  323. 'dy' => 1.0,
  324. 'lbf' => 2.24808923655339E-06
  325. ),
  326. 'lbf' => array( 'N' => 4.448222,
  327. 'dyn' => 4.448222E+5,
  328. 'dy' => 4.448222E+5,
  329. 'lbf' => 1.0
  330. )
  331. ),
  332. 'Energy' => array( 'J' => array( 'J' => 1.0,
  333. 'e' => 9.99999519343231E+06,
  334. 'c' => 2.39006249473467E-01,
  335. 'cal' => 2.38846190642017E-01,
  336. 'eV' => 6.24145700000000E+18,
  337. 'ev' => 6.24145700000000E+18,
  338. 'HPh' => 3.72506430801000E-07,
  339. 'hh' => 3.72506430801000E-07,
  340. 'Wh' => 2.77777916238711E-04,
  341. 'wh' => 2.77777916238711E-04,
  342. 'flb' => 2.37304222192651E+01,
  343. 'BTU' => 9.47815067349015E-04,
  344. 'btu' => 9.47815067349015E-04
  345. ),
  346. 'e' => array( 'J' => 1.00000048065700E-07,
  347. 'e' => 1.0,
  348. 'c' => 2.39006364353494E-08,
  349. 'cal' => 2.38846305445111E-08,
  350. 'eV' => 6.24146000000000E+11,
  351. 'ev' => 6.24146000000000E+11,
  352. 'HPh' => 3.72506609848824E-14,
  353. 'hh' => 3.72506609848824E-14,
  354. 'Wh' => 2.77778049754611E-11,
  355. 'wh' => 2.77778049754611E-11,
  356. 'flb' => 2.37304336254586E-06,
  357. 'BTU' => 9.47815522922962E-11,
  358. 'btu' => 9.47815522922962E-11
  359. ),
  360. 'c' => array( 'J' => 4.18399101363672E+00,
  361. 'e' => 4.18398900257312E+07,
  362. 'c' => 1.0,
  363. 'cal' => 9.99330315287563E-01,
  364. 'eV' => 2.61142000000000E+19,
  365. 'ev' => 2.61142000000000E+19,
  366. 'HPh' => 1.55856355899327E-06,
  367. 'hh' => 1.55856355899327E-06,
  368. 'Wh' => 1.16222030532950E-03,
  369. 'wh' => 1.16222030532950E-03,
  370. 'flb' => 9.92878733152102E+01,
  371. 'BTU' => 3.96564972437776E-03,
  372. 'btu' => 3.96564972437776E-03
  373. ),
  374. 'cal' => array( 'J' => 4.18679484613929E+00,
  375. 'e' => 4.18679283372801E+07,
  376. 'c' => 1.00067013349059E+00,
  377. 'cal' => 1.0,
  378. 'eV' => 2.61317000000000E+19,
  379. 'ev' => 2.61317000000000E+19,
  380. 'HPh' => 1.55960800463137E-06,
  381. 'hh' => 1.55960800463137E-06,
  382. 'Wh' => 1.16299914807955E-03,
  383. 'wh' => 1.16299914807955E-03,
  384. 'flb' => 9.93544094443283E+01,
  385. 'BTU' => 3.96830723907002E-03,
  386. 'btu' => 3.96830723907002E-03
  387. ),
  388. 'eV' => array( 'J' => 1.60219000146921E-19,
  389. 'e' => 1.60218923136574E-12,
  390. 'c' => 3.82933423195043E-20,
  391. 'cal' => 3.82676978535648E-20,
  392. 'eV' => 1.0,
  393. 'ev' => 1.0,
  394. 'HPh' => 5.96826078912344E-26,
  395. 'hh' => 5.96826078912344E-26,
  396. 'Wh' => 4.45053000026614E-23,
  397. 'wh' => 4.45053000026614E-23,
  398. 'flb' => 3.80206452103492E-18,
  399. 'BTU' => 1.51857982414846E-22,
  400. 'btu' => 1.51857982414846E-22
  401. ),
  402. 'ev' => array( 'J' => 1.60219000146921E-19,
  403. 'e' => 1.60218923136574E-12,
  404. 'c' => 3.82933423195043E-20,
  405. 'cal' => 3.82676978535648E-20,
  406. 'eV' => 1.0,
  407. 'ev' => 1.0,
  408. 'HPh' => 5.96826078912344E-26,
  409. 'hh' => 5.96826078912344E-26,
  410. 'Wh' => 4.45053000026614E-23,
  411. 'wh' => 4.45053000026614E-23,
  412. 'flb' => 3.80206452103492E-18,
  413. 'BTU' => 1.51857982414846E-22,
  414. 'btu' => 1.51857982414846E-22
  415. ),
  416. 'HPh' => array( 'J' => 2.68451741316170E+06,
  417. 'e' => 2.68451612283024E+13,
  418. 'c' => 6.41616438565991E+05,
  419. 'cal' => 6.41186757845835E+05,
  420. 'eV' => 1.67553000000000E+25,
  421. 'ev' => 1.67553000000000E+25,
  422. 'HPh' => 1.0,
  423. 'hh' => 1.0,
  424. 'Wh' => 7.45699653134593E+02,
  425. 'wh' => 7.45699653134593E+02,
  426. 'flb' => 6.37047316692964E+07,
  427. 'BTU' => 2.54442605275546E+03,
  428. 'btu' => 2.54442605275546E+03
  429. ),
  430. 'hh' => array( 'J' => 2.68451741316170E+06,
  431. 'e' => 2.68451612283024E+13,
  432. 'c' => 6.41616438565991E+05,
  433. 'cal' => 6.41186757845835E+05,
  434. 'eV' => 1.67553000000000E+25,
  435. 'ev' => 1.67553000000000E+25,
  436. 'HPh' => 1.0,
  437. 'hh' => 1.0,
  438. 'Wh' => 7.45699653134593E+02,
  439. 'wh' => 7.45699653134593E+02,
  440. 'flb' => 6.37047316692964E+07,
  441. 'BTU' => 2.54442605275546E+03,
  442. 'btu' => 2.54442605275546E+03
  443. ),
  444. 'Wh' => array( 'J' => 3.59999820554720E+03,
  445. 'e' => 3.59999647518369E+10,
  446. 'c' => 8.60422069219046E+02,
  447. 'cal' => 8.59845857713046E+02,
  448. 'eV' => 2.24692340000000E+22,
  449. 'ev' => 2.24692340000000E+22,
  450. 'HPh' => 1.34102248243839E-03,
  451. 'hh' => 1.34102248243839E-03,
  452. 'Wh' => 1.0,
  453. 'wh' => 1.0,
  454. 'flb' => 8.54294774062316E+04,
  455. 'BTU' => 3.41213254164705E+00,
  456. 'btu' => 3.41213254164705E+00
  457. ),
  458. 'wh' => array( 'J' => 3.59999820554720E+03,
  459. 'e' => 3.59999647518369E+10,
  460. 'c' => 8.60422069219046E+02,
  461. 'cal' => 8.59845857713046E+02,
  462. 'eV' => 2.24692340000000E+22,
  463. 'ev' => 2.24692340000000E+22,
  464. 'HPh' => 1.34102248243839E-03,
  465. 'hh' => 1.34102248243839E-03,
  466. 'Wh' => 1.0,
  467. 'wh' => 1.0,
  468. 'flb' => 8.54294774062316E+04,
  469. 'BTU' => 3.41213254164705E+00,
  470. 'btu' => 3.41213254164705E+00
  471. ),
  472. 'flb' => array( 'J' => 4.21400003236424E-02,
  473. 'e' => 4.21399800687660E+05,
  474. 'c' => 1.00717234301644E-02,
  475. 'cal' => 1.00649785509554E-02,
  476. 'eV' => 2.63015000000000E+17,
  477. 'ev' => 2.63015000000000E+17,
  478. 'HPh' => 1.56974211145130E-08,
  479. 'hh' => 1.56974211145130E-08,
  480. 'Wh' => 1.17055614802000E-05,
  481. 'wh' => 1.17055614802000E-05,
  482. 'flb' => 1.0,
  483. 'BTU' => 3.99409272448406E-05,
  484. 'btu' => 3.99409272448406E-05
  485. ),
  486. 'BTU' => array( 'J' => 1.05505813786749E+03,
  487. 'e' => 1.05505763074665E+10,
  488. 'c' => 2.52165488508168E+02,
  489. 'cal' => 2.51996617135510E+02,
  490. 'eV' => 6.58510000000000E+21,
  491. 'ev' => 6.58510000000000E+21,
  492. 'HPh' => 3.93015941224568E-04,
  493. 'hh' => 3.93015941224568E-04,
  494. 'Wh' => 2.93071851047526E-01,
  495. 'wh' => 2.93071851047526E-01,
  496. 'flb' => 2.50369750774671E+04,
  497. 'BTU' => 1.0,
  498. 'btu' => 1.0,
  499. ),
  500. 'btu' => array( 'J' => 1.05505813786749E+03,
  501. 'e' => 1.05505763074665E+10,
  502. 'c' => 2.52165488508168E+02,
  503. 'cal' => 2.51996617135510E+02,
  504. 'eV' => 6.58510000000000E+21,
  505. 'ev' => 6.58510000000000E+21,
  506. 'HPh' => 3.93015941224568E-04,
  507. 'hh' => 3.93015941224568E-04,
  508. 'Wh' => 2.93071851047526E-01,
  509. 'wh' => 2.93071851047526E-01,
  510. 'flb' => 2.50369750774671E+04,
  511. 'BTU' => 1.0,
  512. 'btu' => 1.0,
  513. )
  514. ),
  515. 'Power' => array( 'HP' => array( 'HP' => 1.0,
  516. 'h' => 1.0,
  517. 'W' => 7.45701000000000E+02,
  518. 'w' => 7.45701000000000E+02
  519. ),
  520. 'h' => array( 'HP' => 1.0,
  521. 'h' => 1.0,
  522. 'W' => 7.45701000000000E+02,
  523. 'w' => 7.45701000000000E+02
  524. ),
  525. 'W' => array( 'HP' => 1.34102006031908E-03,
  526. 'h' => 1.34102006031908E-03,
  527. 'W' => 1.0,
  528. 'w' => 1.0
  529. ),
  530. 'w' => array( 'HP' => 1.34102006031908E-03,
  531. 'h' => 1.34102006031908E-03,
  532. 'W' => 1.0,
  533. 'w' => 1.0
  534. )
  535. ),
  536. 'Magnetism' => array( 'T' => array( 'T' => 1.0,
  537. 'ga' => 10000.0
  538. ),
  539. 'ga' => array( 'T' => 0.0001,
  540. 'ga' => 1.0
  541. )
  542. ),
  543. 'Liquid' => array( 'tsp' => array( 'tsp' => 1.0,
  544. 'tbs' => 3.33333333333333E-01,
  545. 'oz' => 1.66666666666667E-01,
  546. 'cup' => 2.08333333333333E-02,
  547. 'pt' => 1.04166666666667E-02,
  548. 'us_pt' => 1.04166666666667E-02,
  549. 'uk_pt' => 8.67558516821960E-03,
  550. 'qt' => 5.20833333333333E-03,
  551. 'gal' => 1.30208333333333E-03,
  552. 'l' => 4.92999408400710E-03,
  553. 'lt' => 4.92999408400710E-03
  554. ),
  555. 'tbs' => array( 'tsp' => 3.00000000000000E+00,
  556. 'tbs' => 1.0,
  557. 'oz' => 5.00000000000000E-01,
  558. 'cup' => 6.25000000000000E-02,
  559. 'pt' => 3.12500000000000E-02,
  560. 'us_pt' => 3.12500000000000E-02,
  561. 'uk_pt' => 2.60267555046588E-02,
  562. 'qt' => 1.56250000000000E-02,
  563. 'gal' => 3.90625000000000E-03,
  564. 'l' => 1.47899822520213E-02,
  565. 'lt' => 1.47899822520213E-02
  566. ),
  567. 'oz' => array( 'tsp' => 6.00000000000000E+00,
  568. 'tbs' => 2.00000000000000E+00,
  569. 'oz' => 1.0,
  570. 'cup' => 1.25000000000000E-01,
  571. 'pt' => 6.25000000000000E-02,
  572. 'us_pt' => 6.25000000000000E-02,
  573. 'uk_pt' => 5.20535110093176E-02,
  574. 'qt' => 3.12500000000000E-02,
  575. 'gal' => 7.81250000000000E-03,
  576. 'l' => 2.95799645040426E-02,
  577. 'lt' => 2.95799645040426E-02
  578. ),
  579. 'cup' => array( 'tsp' => 4.80000000000000E+01,
  580. 'tbs' => 1.60000000000000E+01,
  581. 'oz' => 8.00000000000000E+00,
  582. 'cup' => 1.0,
  583. 'pt' => 5.00000000000000E-01,
  584. 'us_pt' => 5.00000000000000E-01,
  585. 'uk_pt' => 4.16428088074541E-01,
  586. 'qt' => 2.50000000000000E-01,
  587. 'gal' => 6.25000000000000E-02,
  588. 'l' => 2.36639716032341E-01,
  589. 'lt' => 2.36639716032341E-01
  590. ),
  591. 'pt' => array( 'tsp' => 9.60000000000000E+01,
  592. 'tbs' => 3.20000000000000E+01,
  593. 'oz' => 1.60000000000000E+01,
  594. 'cup' => 2.00000000000000E+00,
  595. 'pt' => 1.0,
  596. 'us_pt' => 1.0,
  597. 'uk_pt' => 8.32856176149081E-01,
  598. 'qt' => 5.00000000000000E-01,
  599. 'gal' => 1.25000000000000E-01,
  600. 'l' => 4.73279432064682E-01,
  601. 'lt' => 4.73279432064682E-01
  602. ),
  603. 'us_pt' => array( 'tsp' => 9.60000000000000E+01,
  604. 'tbs' => 3.20000000000000E+01,
  605. 'oz' => 1.60000000000000E+01,
  606. 'cup' => 2.00000000000000E+00,
  607. 'pt' => 1.0,
  608. 'us_pt' => 1.0,
  609. 'uk_pt' => 8.32856176149081E-01,
  610. 'qt' => 5.00000000000000E-01,
  611. 'gal' => 1.25000000000000E-01,
  612. 'l' => 4.73279432064682E-01,
  613. 'lt' => 4.73279432064682E-01
  614. ),
  615. 'uk_pt' => array( 'tsp' => 1.15266000000000E+02,
  616. 'tbs' => 3.84220000000000E+01,
  617. 'oz' => 1.92110000000000E+01,
  618. 'cup' => 2.40137500000000E+00,
  619. 'pt' => 1.20068750000000E+00,
  620. 'us_pt' => 1.20068750000000E+00,
  621. 'uk_pt' => 1.0,
  622. 'qt' => 6.00343750000000E-01,
  623. 'gal' => 1.50085937500000E-01,
  624. 'l' => 5.68260698087162E-01,
  625. 'lt' => 5.68260698087162E-01
  626. ),
  627. 'qt' => array( 'tsp' => 1.92000000000000E+02,
  628. 'tbs' => 6.40000000000000E+01,
  629. 'oz' => 3.20000000000000E+01,
  630. 'cup' => 4.00000000000000E+00,
  631. 'pt' => 2.00000000000000E+00,
  632. 'us_pt' => 2.00000000000000E+00,
  633. 'uk_pt' => 1.66571235229816E+00,
  634. 'qt' => 1.0,
  635. 'gal' => 2.50000000000000E-01,
  636. 'l' => 9.46558864129363E-01,
  637. 'lt' => 9.46558864129363E-01
  638. ),
  639. 'gal' => array( 'tsp' => 7.68000000000000E+02,
  640. 'tbs' => 2.56000000000000E+02,
  641. 'oz' => 1.28000000000000E+02,
  642. 'cup' => 1.60000000000000E+01,
  643. 'pt' => 8.00000000000000E+00,
  644. 'us_pt' => 8.00000000000000E+00,
  645. 'uk_pt' => 6.66284940919265E+00,
  646. 'qt' => 4.00000000000000E+00,
  647. 'gal' => 1.0,
  648. 'l' => 3.78623545651745E+00,
  649. 'lt' => 3.78623545651745E+00
  650. ),
  651. 'l' => array( 'tsp' => 2.02840000000000E+02,
  652. 'tbs' => 6.76133333333333E+01,
  653. 'oz' => 3.38066666666667E+01,
  654. 'cup' => 4.22583333333333E+00,
  655. 'pt' => 2.11291666666667E+00,
  656. 'us_pt' => 2.11291666666667E+00,
  657. 'uk_pt' => 1.75975569552166E+00,
  658. 'qt' => 1.05645833333333E+00,
  659. 'gal' => 2.64114583333333E-01,
  660. 'l' => 1.0,
  661. 'lt' => 1.0
  662. ),
  663. 'lt' => array( 'tsp' => 2.02840000000000E+02,
  664. 'tbs' => 6.76133333333333E+01,
  665. 'oz' => 3.38066666666667E+01,
  666. 'cup' => 4.22583333333333E+00,
  667. 'pt' => 2.11291666666667E+00,
  668. 'us_pt' => 2.11291666666667E+00,
  669. 'uk_pt' => 1.75975569552166E+00,
  670. 'qt' => 1.05645833333333E+00,
  671. 'gal' => 2.64114583333333E-01,
  672. 'l' => 1.0,
  673. 'lt' => 1.0
  674. )
  675. )
  676. );
  677. /**
  678. * _parseComplex
  679. *
  680. * Parses a complex number into its real and imaginary parts, and an I or J suffix
  681. *
  682. * @param string $complexNumber The complex number
  683. * @return string[] Indexed on "real", "imaginary" and "suffix"
  684. */
  685. public static function _parseComplex($complexNumber) {
  686. $workString = (string) $complexNumber;
  687. $realNumber = $imaginary = 0;
  688. // Extract the suffix, if there is one
  689. $suffix = substr($workString,-1);
  690. if (!is_numeric($suffix)) {
  691. $workString = substr($workString,0,-1);
  692. } else {
  693. $suffix = '';
  694. }
  695. // Split the input into its Real and Imaginary components
  696. $leadingSign = 0;
  697. if (strlen($workString) > 0) {
  698. $leadingSign = (($workString{0} == '+') || ($workString{0} == '-')) ? 1 : 0;
  699. }
  700. $power = '';
  701. $realNumber = strtok($workString, '+-');
  702. if (strtoupper(substr($realNumber,-1)) == 'E') {
  703. $power = strtok('+-');
  704. ++$leadingSign;
  705. }
  706. $realNumber = substr($workString,0,strlen($realNumber)+strlen($power)+$leadingSign);
  707. if ($suffix != '') {
  708. $imaginary = substr($workString,strlen($realNumber));
  709. if (($imaginary == '') && (($realNumber == '') || ($realNumber == '+') || ($realNumber == '-'))) {
  710. $imaginary = $realNumber.'1';
  711. $realNumber = '0';
  712. } else if ($imaginary == '') {
  713. $imaginary = $realNumber;
  714. $realNumber = '0';
  715. } elseif (($imaginary == '+') || ($imaginary == '-')) {
  716. $imaginary .= '1';
  717. }
  718. }
  719. return array( 'real' => $realNumber,
  720. 'imaginary' => $imaginary,
  721. 'suffix' => $suffix
  722. );
  723. } // function _parseComplex()
  724. /**
  725. * _cleanComplex
  726. *
  727. * Cleans the leading characters in a complex number string
  728. *
  729. * @param string $complexNumber The complex number to clean
  730. * @return string The "cleaned" complex number
  731. */
  732. private static function _cleanComplex($complexNumber) {
  733. if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1);
  734. if ($complexNumber{0} == '0') $complexNumber = substr($complexNumber,1);
  735. if ($complexNumber{0} == '.') $complexNumber = '0'.$complexNumber;
  736. if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1);
  737. return $complexNumber;
  738. }
  739. private static function _nbrConversionFormat($xVal,$places) {
  740. if (!is_null($places)) {
  741. if (strlen($xVal) <= $places) {
  742. return substr(str_pad($xVal,$places,'0',STR_PAD_LEFT),-10);
  743. } else {
  744. return PHPExcel_Calculation_Functions::NaN();
  745. }
  746. }
  747. return substr($xVal,-10);
  748. } // function _nbrConversionFormat()
  749. /**
  750. * BESSELI
  751. *
  752. * Returns the modified Bessel function, which is equivalent to the Bessel function evaluated for
  753. * purely imaginary arguments
  754. *
  755. * Excel Function:
  756. * BESSELI(x,ord)
  757. *
  758. * @access public
  759. * @category Engineering Functions
  760. * @param float $x The value at which to evaluate the function.
  761. * If x is nonnumeric, BESSELI returns the #VALUE! error value.
  762. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  763. * If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
  764. * If $ord < 0, BESSELI returns the #NUM! error value.
  765. * @return float
  766. *
  767. * @TODO Better handling of the approximation method to support the differences between Excel/Gnumeric and Open/Libre Office
  768. *
  769. */
  770. public static function BESSELI($x, $ord) {
  771. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  772. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  773. if ((is_numeric($x)) && (is_numeric($ord))) {
  774. $ord = floor($ord);
  775. if ($ord < 0) {
  776. return PHPExcel_Calculation_Functions::NaN();
  777. }
  778. if (abs($x) <= 30) {
  779. $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
  780. $ordK = 1;
  781. $fSqrX = ($x * $x) / 4;
  782. do {
  783. $fTerm *= $fSqrX;
  784. $fTerm /= ($ordK * ($ordK + $ord));
  785. $fResult += $fTerm;
  786. } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
  787. } else {
  788. $f_2_PI = 2 * M_PI;
  789. $fXAbs = abs($x);
  790. $fResult = exp($fXAbs) / sqrt($f_2_PI * $fXAbs);
  791. if (($ord & 1) && ($x < 0)) {
  792. $fResult = -$fResult;
  793. }
  794. }
  795. return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
  796. }
  797. return PHPExcel_Calculation_Functions::VALUE();
  798. } // function BESSELI()
  799. /**
  800. * BESSELJ
  801. *
  802. * Returns the Bessel function
  803. *
  804. * Excel Function:
  805. * BESSELJ(x,ord)
  806. *
  807. * @access public
  808. * @category Engineering Functions
  809. * @param float $x The value at which to evaluate the function.
  810. * If x is nonnumeric, BESSELJ returns the #VALUE! error value.
  811. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  812. * If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
  813. * If $ord < 0, BESSELJ returns the #NUM! error value.
  814. * @return float
  815. *
  816. * @TODO Better handling of the approximation method to support the differences between Excel/Gnumeric and Open/Libre Office
  817. *
  818. */
  819. public static function BESSELJ($x, $ord) {
  820. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  821. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  822. if ((is_numeric($x)) && (is_numeric($ord))) {
  823. $ord = floor($ord);
  824. if ($ord < 0) {
  825. return PHPExcel_Calculation_Functions::NaN();
  826. }
  827. $fResult = 0;
  828. if (abs($x) <= 30) {
  829. $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
  830. $ordK = 1;
  831. $fSqrX = ($x * $x) / -4;
  832. do {
  833. $fTerm *= $fSqrX;
  834. $fTerm /= ($ordK * ($ordK + $ord));
  835. $fResult += $fTerm;
  836. } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
  837. } else {
  838. $f_PI_DIV_2 = M_PI / 2;
  839. $f_PI_DIV_4 = M_PI / 4;
  840. $fXAbs = abs($x);
  841. $fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4);
  842. if (($ord & 1) && ($x < 0)) {
  843. $fResult = -$fResult;
  844. }
  845. }
  846. return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
  847. }
  848. return PHPExcel_Calculation_Functions::VALUE();
  849. } // function BESSELJ()
  850. private static function _Besselk0($fNum) {
  851. if ($fNum <= 2) {
  852. $fNum2 = $fNum * 0.5;
  853. $y = ($fNum2 * $fNum2);
  854. $fRet = -log($fNum2) * self::BESSELI($fNum, 0) +
  855. (-0.57721566 + $y * (0.42278420 + $y * (0.23069756 + $y * (0.3488590e-1 + $y * (0.262698e-2 + $y *
  856. (0.10750e-3 + $y * 0.74e-5))))));
  857. } else {
  858. $y = 2 / $fNum;
  859. $fRet = exp(-$fNum) / sqrt($fNum) *
  860. (1.25331414 + $y * (-0.7832358e-1 + $y * (0.2189568e-1 + $y * (-0.1062446e-1 + $y *
  861. (0.587872e-2 + $y * (-0.251540e-2 + $y * 0.53208e-3))))));
  862. }
  863. return $fRet;
  864. } // function _Besselk0()
  865. private static function _Besselk1($fNum) {
  866. if ($fNum <= 2) {
  867. $fNum2 = $fNum * 0.5;
  868. $y = ($fNum2 * $fNum2);
  869. $fRet = log($fNum2) * self::BESSELI($fNum, 1) +
  870. (1 + $y * (0.15443144 + $y * (-0.67278579 + $y * (-0.18156897 + $y * (-0.1919402e-1 + $y *
  871. (-0.110404e-2 + $y * (-0.4686e-4))))))) / $fNum;
  872. } else {
  873. $y = 2 / $fNum;
  874. $fRet = exp(-$fNum) / sqrt($fNum) *
  875. (1.25331414 + $y * (0.23498619 + $y * (-0.3655620e-1 + $y * (0.1504268e-1 + $y * (-0.780353e-2 + $y *
  876. (0.325614e-2 + $y * (-0.68245e-3)))))));
  877. }
  878. return $fRet;
  879. } // function _Besselk1()
  880. /**
  881. * BESSELK
  882. *
  883. * Returns the modified Bessel function, which is equivalent to the Bessel functions evaluated
  884. * for purely imaginary arguments.
  885. *
  886. * Excel Function:
  887. * BESSELK(x,ord)
  888. *
  889. * @access public
  890. * @category Engineering Functions
  891. * @param float $x The value at which to evaluate the function.
  892. * If x is nonnumeric, BESSELK returns the #VALUE! error value.
  893. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  894. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
  895. * If $ord < 0, BESSELK returns the #NUM! error value.
  896. * @return float
  897. *
  898. * @TODO Better handling of the approximation method to support the differences between Excel/Gnumeric and Open/Libre Office
  899. *
  900. */
  901. public static function BESSELK($x, $ord) {
  902. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  903. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  904. if ((is_numeric($x)) && (is_numeric($ord))) {
  905. if (($ord < 0) || ($x == 0.0)) {
  906. return PHPExcel_Calculation_Functions::NaN();
  907. }
  908. switch(floor($ord)) {
  909. case 0 : return self::_Besselk0($x);
  910. break;
  911. case 1 : return self::_Besselk1($x);
  912. break;
  913. default : $fTox = 2 / $x;
  914. $fBkm = self::_Besselk0($x);
  915. $fBk = self::_Besselk1($x);
  916. for ($n = 1; $n < $ord; ++$n) {
  917. $fBkp = $fBkm + $n * $fTox * $fBk;
  918. $fBkm = $fBk;
  919. $fBk = $fBkp;
  920. }
  921. }
  922. return (is_nan($fBk)) ? PHPExcel_Calculation_Functions::NaN() : $fBk;
  923. }
  924. return PHPExcel_Calculation_Functions::VALUE();
  925. } // function BESSELK()
  926. private static function _Bessely0($fNum) {
  927. if ($fNum < 8.0) {
  928. $y = ($fNum * $fNum);
  929. $f1 = -2957821389.0 + $y * (7062834065.0 + $y * (-512359803.6 + $y * (10879881.29 + $y * (-86327.92757 + $y * 228.4622733))));
  930. $f2 = 40076544269.0 + $y * (745249964.8 + $y * (7189466.438 + $y * (47447.26470 + $y * (226.1030244 + $y))));
  931. $fRet = $f1 / $f2 + 0.636619772 * self::BESSELJ($fNum, 0) * log($fNum);
  932. } else {
  933. $z = 8.0 / $fNum;
  934. $y = ($z * $z);
  935. $xx = $fNum - 0.785398164;
  936. $f1 = 1 + $y * (-0.1098628627e-2 + $y * (0.2734510407e-4 + $y * (-0.2073370639e-5 + $y * 0.2093887211e-6)));
  937. $f2 = -0.1562499995e-1 + $y * (0.1430488765e-3 + $y * (-0.6911147651e-5 + $y * (0.7621095161e-6 + $y * (-0.934945152e-7))));
  938. $fRet = sqrt(0.636619772 / $fNum) * (sin($xx) * $f1 + $z * cos($xx) * $f2);
  939. }
  940. return $fRet;
  941. } // function _Bessely0()
  942. private static function _Bessely1($fNum) {
  943. if ($fNum < 8.0) {
  944. $y = ($fNum * $fNum);
  945. $f1 = $fNum * (-0.4900604943e13 + $y * (0.1275274390e13 + $y * (-0.5153438139e11 + $y * (0.7349264551e9 + $y *
  946. (-0.4237922726e7 + $y * 0.8511937935e4)))));
  947. $f2 = 0.2499580570e14 + $y * (0.4244419664e12 + $y * (0.3733650367e10 + $y * (0.2245904002e8 + $y *
  948. (0.1020426050e6 + $y * (0.3549632885e3 + $y)))));
  949. $fRet = $f1 / $f2 + 0.636619772 * ( self::BESSELJ($fNum, 1) * log($fNum) - 1 / $fNum);
  950. } else {
  951. // $z = 8.0 / $fNum;
  952. // $y = ($z * $z);
  953. // $xx = $fNum - 2.356194491;
  954. // $f1 = 1 + $y * (0.183105e-2 + $y * (-0.3516396496e-4 + $y * (0.2457520174e-5 + $y * (-0.240337019e6))));
  955. // $f2 = 0.04687499995 + $y * (-0.2002690873e-3 + $y * (0.8449199096e-5 + $y * (-0.88228987e-6 + $y * 0.105787412e-6)));
  956. // $fRet = sqrt(0.636619772 / $fNum) * (sin($xx) * $f1 + $z * cos($xx) * $f2);
  957. #i12430# ...but this seems to work much better.
  958. $fRet = sqrt(0.636619772 / $fNum) * sin($fNum - 2.356194491);
  959. }
  960. return $fRet;
  961. } // function _Bessely1()
  962. /**
  963. * BESSELY
  964. *
  965. * Returns the Bessel function, which is also called the Weber function or the Neumann function.
  966. *
  967. * Excel Function:
  968. * BESSELY(x,ord)
  969. *
  970. * @access public
  971. * @category Engineering Functions
  972. * @param float $x The value at which to evaluate the function.
  973. * If x is nonnumeric, BESSELK returns the #VALUE! error value.
  974. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  975. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
  976. * If $ord < 0, BESSELK returns the #NUM! error value.
  977. *
  978. * @TODO Better handling of the approximation method to support the differences between Excel/Gnumeric and Open/Libre Office
  979. *
  980. * @return float
  981. */
  982. public static function BESSELY($x, $ord) {
  983. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  984. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  985. if ((is_numeric($x)) && (is_numeric($ord))) {
  986. if (($ord < 0) || ($x == 0.0)) {
  987. return PHPExcel_Calculation_Functions::NaN();
  988. }
  989. switch(floor($ord)) {
  990. case 0 : return self::_Bessely0($x);
  991. break;
  992. case 1 : return self::_Bessely1($x);
  993. break;
  994. default: $fTox = 2 / $x;
  995. $fBym = self::_Bessely0($x);
  996. $fBy = self::_Bessely1($x);
  997. for ($n = 1; $n < $ord; ++$n) {
  998. $fByp = $n * $fTox * $fBy - $fBym;
  999. $fBym = $fBy;
  1000. $fBy = $fByp;
  1001. }
  1002. }
  1003. return (is_nan($fBy)) ? PHPExcel_Calculation_Functions::NaN() : $fBy;
  1004. }
  1005. return PHPExcel_Calculation_Functions::VALUE();
  1006. } // function BESSELY()
  1007. /**
  1008. * BINTODEC
  1009. *
  1010. * Return a binary value as decimal.
  1011. *
  1012. * Excel Function:
  1013. * BIN2DEC(x)
  1014. *
  1015. * @access public
  1016. * @category Engineering Functions
  1017. * @param string $x The binary number (as a string) that you want to convert. The number
  1018. * cannot contain more than 10 characters (10 bits). The most significant
  1019. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
  1020. * Negative numbers are represented using two's-complement notation.
  1021. * If number is not a valid binary number, or if number contains more than
  1022. * 10 characters (10 bits), BIN2DEC returns the #NUM! error value.
  1023. * @return string
  1024. */
  1025. public static function BINTODEC($x) {
  1026. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1027. if (is_bool($x)) {
  1028. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1029. $x = (int) $x;
  1030. } else {
  1031. return PHPExcel_Calculation_Functions::VALUE();
  1032. }
  1033. }
  1034. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  1035. $x = floor($x);
  1036. }
  1037. $x = (string) $x;
  1038. if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
  1039. return PHPExcel_Calculation_Functions::NaN();
  1040. }
  1041. if (strlen($x) > 1

Large files files are truncated, but you can click here to view the full file