PageRenderTime 68ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/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

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 - 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_OPENOF

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