PageRenderTime 54ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/common/libraries/plugin/phpexcel/PHPExcel/Calculation/Engineering.php

https://bitbucket.org/ywarnier/chamilo-dev
PHP | 2135 lines | 1527 code | 207 blank | 401 comment | 315 complexity | 73769569c2093f011fe8c270a1918df6 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT

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

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