No Description

Engineering.php 96KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  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 - 2014 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. * Cleans the leading characters in a complex number string
  726. *
  727. * @param string $complexNumber The complex number to clean
  728. * @return string The "cleaned" complex number
  729. */
  730. private static function _cleanComplex($complexNumber) {
  731. if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1);
  732. if ($complexNumber{0} == '0') $complexNumber = substr($complexNumber,1);
  733. if ($complexNumber{0} == '.') $complexNumber = '0'.$complexNumber;
  734. if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1);
  735. return $complexNumber;
  736. }
  737. /**
  738. * Formats a number base string value with leading zeroes
  739. *
  740. * @param string $xVal The "number" to pad
  741. * @param integer $places The length that we want to pad this value
  742. * @return string The padded "number"
  743. */
  744. private static function _nbrConversionFormat($xVal, $places) {
  745. if (!is_null($places)) {
  746. if (strlen($xVal) <= $places) {
  747. return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10);
  748. } else {
  749. return PHPExcel_Calculation_Functions::NaN();
  750. }
  751. }
  752. return substr($xVal, -10);
  753. } // function _nbrConversionFormat()
  754. /**
  755. * BESSELI
  756. *
  757. * Returns the modified Bessel function In(x), which is equivalent to the Bessel function evaluated
  758. * for purely imaginary arguments
  759. *
  760. * Excel Function:
  761. * BESSELI(x,ord)
  762. *
  763. * @access public
  764. * @category Engineering Functions
  765. * @param float $x The value at which to evaluate the function.
  766. * If x is nonnumeric, BESSELI returns the #VALUE! error value.
  767. * @param integer $ord The order of the Bessel function.
  768. * If ord is not an integer, it is truncated.
  769. * If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
  770. * If $ord < 0, BESSELI returns the #NUM! error value.
  771. * @return float
  772. *
  773. */
  774. public static function BESSELI($x, $ord) {
  775. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  776. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  777. if ((is_numeric($x)) && (is_numeric($ord))) {
  778. $ord = floor($ord);
  779. if ($ord < 0) {
  780. return PHPExcel_Calculation_Functions::NaN();
  781. }
  782. if (abs($x) <= 30) {
  783. $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
  784. $ordK = 1;
  785. $fSqrX = ($x * $x) / 4;
  786. do {
  787. $fTerm *= $fSqrX;
  788. $fTerm /= ($ordK * ($ordK + $ord));
  789. $fResult += $fTerm;
  790. } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
  791. } else {
  792. $f_2_PI = 2 * M_PI;
  793. $fXAbs = abs($x);
  794. $fResult = exp($fXAbs) / sqrt($f_2_PI * $fXAbs);
  795. if (($ord & 1) && ($x < 0)) {
  796. $fResult = -$fResult;
  797. }
  798. }
  799. return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
  800. }
  801. return PHPExcel_Calculation_Functions::VALUE();
  802. } // function BESSELI()
  803. /**
  804. * BESSELJ
  805. *
  806. * Returns the Bessel function
  807. *
  808. * Excel Function:
  809. * BESSELJ(x,ord)
  810. *
  811. * @access public
  812. * @category Engineering Functions
  813. * @param float $x The value at which to evaluate the function.
  814. * If x is nonnumeric, BESSELJ returns the #VALUE! error value.
  815. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  816. * If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
  817. * If $ord < 0, BESSELJ returns the #NUM! error value.
  818. * @return float
  819. *
  820. */
  821. public static function BESSELJ($x, $ord) {
  822. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  823. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  824. if ((is_numeric($x)) && (is_numeric($ord))) {
  825. $ord = floor($ord);
  826. if ($ord < 0) {
  827. return PHPExcel_Calculation_Functions::NaN();
  828. }
  829. $fResult = 0;
  830. if (abs($x) <= 30) {
  831. $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
  832. $ordK = 1;
  833. $fSqrX = ($x * $x) / -4;
  834. do {
  835. $fTerm *= $fSqrX;
  836. $fTerm /= ($ordK * ($ordK + $ord));
  837. $fResult += $fTerm;
  838. } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
  839. } else {
  840. $f_PI_DIV_2 = M_PI / 2;
  841. $f_PI_DIV_4 = M_PI / 4;
  842. $fXAbs = abs($x);
  843. $fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4);
  844. if (($ord & 1) && ($x < 0)) {
  845. $fResult = -$fResult;
  846. }
  847. }
  848. return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
  849. }
  850. return PHPExcel_Calculation_Functions::VALUE();
  851. } // function BESSELJ()
  852. private static function _Besselk0($fNum) {
  853. if ($fNum <= 2) {
  854. $fNum2 = $fNum * 0.5;
  855. $y = ($fNum2 * $fNum2);
  856. $fRet = -log($fNum2) * self::BESSELI($fNum, 0) +
  857. (-0.57721566 + $y * (0.42278420 + $y * (0.23069756 + $y * (0.3488590e-1 + $y * (0.262698e-2 + $y *
  858. (0.10750e-3 + $y * 0.74e-5))))));
  859. } else {
  860. $y = 2 / $fNum;
  861. $fRet = exp(-$fNum) / sqrt($fNum) *
  862. (1.25331414 + $y * (-0.7832358e-1 + $y * (0.2189568e-1 + $y * (-0.1062446e-1 + $y *
  863. (0.587872e-2 + $y * (-0.251540e-2 + $y * 0.53208e-3))))));
  864. }
  865. return $fRet;
  866. } // function _Besselk0()
  867. private static function _Besselk1($fNum) {
  868. if ($fNum <= 2) {
  869. $fNum2 = $fNum * 0.5;
  870. $y = ($fNum2 * $fNum2);
  871. $fRet = log($fNum2) * self::BESSELI($fNum, 1) +
  872. (1 + $y * (0.15443144 + $y * (-0.67278579 + $y * (-0.18156897 + $y * (-0.1919402e-1 + $y *
  873. (-0.110404e-2 + $y * (-0.4686e-4))))))) / $fNum;
  874. } else {
  875. $y = 2 / $fNum;
  876. $fRet = exp(-$fNum) / sqrt($fNum) *
  877. (1.25331414 + $y * (0.23498619 + $y * (-0.3655620e-1 + $y * (0.1504268e-1 + $y * (-0.780353e-2 + $y *
  878. (0.325614e-2 + $y * (-0.68245e-3)))))));
  879. }
  880. return $fRet;
  881. } // function _Besselk1()
  882. /**
  883. * BESSELK
  884. *
  885. * Returns the modified Bessel function Kn(x), which is equivalent to the Bessel functions evaluated
  886. * for purely imaginary arguments.
  887. *
  888. * Excel Function:
  889. * BESSELK(x,ord)
  890. *
  891. * @access public
  892. * @category Engineering Functions
  893. * @param float $x The value at which to evaluate the function.
  894. * If x is nonnumeric, BESSELK returns the #VALUE! error value.
  895. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  896. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
  897. * If $ord < 0, BESSELK returns the #NUM! error value.
  898. * @return float
  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. $fRet = sqrt(0.636619772 / $fNum) * sin($fNum - 2.356194491);
  952. }
  953. return $fRet;
  954. } // function _Bessely1()
  955. /**
  956. * BESSELY
  957. *
  958. * Returns the Bessel function, which is also called the Weber function or the Neumann function.
  959. *
  960. * Excel Function:
  961. * BESSELY(x,ord)
  962. *
  963. * @access public
  964. * @category Engineering Functions
  965. * @param float $x The value at which to evaluate the function.
  966. * If x is nonnumeric, BESSELK returns the #VALUE! error value.
  967. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  968. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
  969. * If $ord < 0, BESSELK returns the #NUM! error value.
  970. *
  971. * @return float
  972. */
  973. public static function BESSELY($x, $ord) {
  974. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  975. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  976. if ((is_numeric($x)) && (is_numeric($ord))) {
  977. if (($ord < 0) || ($x == 0.0)) {
  978. return PHPExcel_Calculation_Functions::NaN();
  979. }
  980. switch(floor($ord)) {
  981. case 0 : return self::_Bessely0($x);
  982. break;
  983. case 1 : return self::_Bessely1($x);
  984. break;
  985. default: $fTox = 2 / $x;
  986. $fBym = self::_Bessely0($x);
  987. $fBy = self::_Bessely1($x);
  988. for ($n = 1; $n < $ord; ++$n) {
  989. $fByp = $n * $fTox * $fBy - $fBym;
  990. $fBym = $fBy;
  991. $fBy = $fByp;
  992. }
  993. }
  994. return (is_nan($fBy)) ? PHPExcel_Calculation_Functions::NaN() : $fBy;
  995. }
  996. return PHPExcel_Calculation_Functions::VALUE();
  997. } // function BESSELY()
  998. /**
  999. * BINTODEC
  1000. *
  1001. * Return a binary value as decimal.
  1002. *
  1003. * Excel Function:
  1004. * BIN2DEC(x)
  1005. *
  1006. * @access public
  1007. * @category Engineering Functions
  1008. * @param string $x The binary number (as a string) that you want to convert. The number
  1009. * cannot contain more than 10 characters (10 bits). The most significant
  1010. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
  1011. * Negative numbers are represented using two's-complement notation.
  1012. * If number is not a valid binary number, or if number contains more than
  1013. * 10 characters (10 bits), BIN2DEC returns the #NUM! error value.
  1014. * @return string
  1015. */
  1016. public static function BINTODEC($x) {
  1017. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1018. if (is_bool($x)) {
  1019. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1020. $x = (int) $x;
  1021. } else {
  1022. return PHPExcel_Calculation_Functions::VALUE();
  1023. }
  1024. }
  1025. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  1026. $x = floor($x);
  1027. }
  1028. $x = (string) $x;
  1029. if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
  1030. return PHPExcel_Calculation_Functions::NaN();
  1031. }
  1032. if (strlen($x) > 10) {
  1033. return PHPExcel_Calculation_Functions::NaN();
  1034. } elseif (strlen($x) == 10) {
  1035. // Two's Complement
  1036. $x = substr($x,-9);
  1037. return '-'.(512-bindec($x));
  1038. }
  1039. return bindec($x);
  1040. } // function BINTODEC()
  1041. /**
  1042. * BINTOHEX
  1043. *
  1044. * Return a binary value as hex.
  1045. *
  1046. * Excel Function:
  1047. * BIN2HEX(x[,places])
  1048. *
  1049. * @access public
  1050. * @category Engineering Functions
  1051. * @param string $x The binary number (as a string) that you want to convert. The number
  1052. * cannot contain more than 10 characters (10 bits). The most significant
  1053. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
  1054. * Negative numbers are represented using two's-complement notation.
  1055. * If number is not a valid binary number, or if number contains more than
  1056. * 10 characters (10 bits), BIN2HEX returns the #NUM! error value.
  1057. * @param integer $places The number of characters to use. If places is omitted, BIN2HEX uses the
  1058. * minimum number of characters necessary. Places is useful for padding the
  1059. * return value with leading 0s (zeros).
  1060. * If places is not an integer, it is truncated.
  1061. * If places is nonnumeric, BIN2HEX returns the #VALUE! error value.
  1062. * If places is negative, BIN2HEX returns the #NUM! error value.
  1063. * @return string
  1064. */
  1065. public static function BINTOHEX($x, $places=NULL) {
  1066. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1067. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1068. if (is_bool($x)) {
  1069. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1070. $x = (int) $x;
  1071. } else {
  1072. return PHPExcel_Calculation_Functions::VALUE();
  1073. }
  1074. }
  1075. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  1076. $x = floor($x);
  1077. }
  1078. $x = (string) $x;
  1079. if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
  1080. return PHPExcel_Calculation_Functions::NaN();
  1081. }
  1082. if (strlen($x) > 10) {
  1083. return PHPExcel_Calculation_Functions::NaN();
  1084. } elseif (strlen($x) == 10) {
  1085. // Two's Complement
  1086. return str_repeat('F',8).substr(strtoupper(dechex(bindec(substr($x,-9)))),-2);
  1087. }
  1088. $hexVal = (string) strtoupper(dechex(bindec($x)));
  1089. return self::_nbrConversionFormat($hexVal,$places);
  1090. } // function BINTOHEX()
  1091. /**
  1092. * BINTOOCT
  1093. *
  1094. * Return a binary value as octal.
  1095. *
  1096. * Excel Function:
  1097. * BIN2OCT(x[,places])
  1098. *
  1099. * @access public
  1100. * @category Engineering Functions
  1101. * @param string $x The binary number (as a string) that you want to convert. The number
  1102. * cannot contain more than 10 characters (10 bits). The most significant
  1103. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
  1104. * Negative numbers are represented using two's-complement notation.
  1105. * If number is not a valid binary number, or if number contains more than
  1106. * 10 characters (10 bits), BIN2OCT returns the #NUM! error value.
  1107. * @param integer $places The number of characters to use. If places is omitted, BIN2OCT uses the
  1108. * minimum number of characters necessary. Places is useful for padding the
  1109. * return value with leading 0s (zeros).
  1110. * If places is not an integer, it is truncated.
  1111. * If places is nonnumeric, BIN2OCT returns the #VALUE! error value.
  1112. * If places is negative, BIN2OCT returns the #NUM! error value.
  1113. * @return string
  1114. */
  1115. public static function BINTOOCT($x, $places=NULL) {
  1116. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1117. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1118. if (is_bool($x)) {
  1119. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1120. $x = (int) $x;
  1121. } else {
  1122. return PHPExcel_Calculation_Functions::VALUE();
  1123. }
  1124. }
  1125. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  1126. $x = floor($x);
  1127. }
  1128. $x = (string) $x;
  1129. if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
  1130. return PHPExcel_Calculation_Functions::NaN();
  1131. }
  1132. if (strlen($x) > 10) {
  1133. return PHPExcel_Calculation_Functions::NaN();
  1134. } elseif (strlen($x) == 10) {
  1135. // Two's Complement
  1136. return str_repeat('7',7).substr(strtoupper(decoct(bindec(substr($x,-9)))),-3);
  1137. }
  1138. $octVal = (string) decoct(bindec($x));
  1139. return self::_nbrConversionFormat($octVal,$places);
  1140. } // function BINTOOCT()
  1141. /**
  1142. * DECTOBIN
  1143. *
  1144. * Return a decimal value as binary.
  1145. *
  1146. * Excel Function:
  1147. * DEC2BIN(x[,places])
  1148. *
  1149. * @access public
  1150. * @category Engineering Functions
  1151. * @param string $x The decimal integer you want to convert. If number is negative,
  1152. * valid place values are ignored and DEC2BIN returns a 10-character
  1153. * (10-bit) binary number in which the most significant bit is the sign
  1154. * bit. The remaining 9 bits are magnitude bits. Negative numbers are
  1155. * represented using two's-complement notation.
  1156. * If number < -512 or if number > 511, DEC2BIN returns the #NUM! error
  1157. * value.
  1158. * If number is nonnumeric, DEC2BIN returns the #VALUE! error value.
  1159. * If DEC2BIN requires more than places characters, it returns the #NUM!
  1160. * error value.
  1161. * @param integer $places The number of characters to use. If places is omitted, DEC2BIN uses
  1162. * the minimum number of characters necessary. Places is useful for
  1163. * padding the return value with leading 0s (zeros).
  1164. * If places is not an integer, it is truncated.
  1165. * If places is nonnumeric, DEC2BIN returns the #VALUE! error value.
  1166. * If places is zero or negative, DEC2BIN returns the #NUM! error value.
  1167. * @return string
  1168. */
  1169. public static function DECTOBIN($x, $places=NULL) {
  1170. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1171. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1172. if (is_bool($x)) {
  1173. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1174. $x = (int) $x;
  1175. } else {
  1176. return PHPExcel_Calculation_Functions::VALUE();
  1177. }
  1178. }
  1179. $x = (string) $x;
  1180. if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) {
  1181. return PHPExcel_Calculation_Functions::VALUE();
  1182. }
  1183. $x = (string) floor($x);
  1184. $r = decbin($x);
  1185. if (strlen($r) == 32) {
  1186. // Two's Complement
  1187. $r = substr($r,-10);
  1188. } elseif (strlen($r) > 11) {
  1189. return PHPExcel_Calculation_Functions::NaN();
  1190. }
  1191. return self::_nbrConversionFormat($r,$places);
  1192. } // function DECTOBIN()
  1193. /**
  1194. * DECTOHEX
  1195. *
  1196. * Return a decimal value as hex.
  1197. *
  1198. * Excel Function:
  1199. * DEC2HEX(x[,places])
  1200. *
  1201. * @access public
  1202. * @category Engineering Functions
  1203. * @param string $x The decimal integer you want to convert. If number is negative,
  1204. * places is ignored and DEC2HEX returns a 10-character (40-bit)
  1205. * hexadecimal number in which the most significant bit is the sign
  1206. * bit. The remaining 39 bits are magnitude bits. Negative numbers
  1207. * are represented using two's-complement notation.
  1208. * If number < -549,755,813,888 or if number > 549,755,813,887,
  1209. * DEC2HEX returns the #NUM! error value.
  1210. * If number is nonnumeric, DEC2HEX returns the #VALUE! error value.
  1211. * If DEC2HEX requires more than places characters, it returns the
  1212. * #NUM! error value.
  1213. * @param integer $places The number of characters to use. If places is omitted, DEC2HEX uses
  1214. * the minimum number of characters necessary. Places is useful for
  1215. * padding the return value with leading 0s (zeros).
  1216. * If places is not an integer, it is truncated.
  1217. * If places is nonnumeric, DEC2HEX returns the #VALUE! error value.
  1218. * If places is zero or negative, DEC2HEX returns the #NUM! error value.
  1219. * @return string
  1220. */
  1221. public static function DECTOHEX($x, $places=null) {
  1222. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1223. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1224. if (is_bool($x)) {
  1225. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1226. $x = (int) $x;
  1227. } else {
  1228. return PHPExcel_Calculation_Functions::VALUE();
  1229. }
  1230. }
  1231. $x = (string) $x;
  1232. if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) {
  1233. return PHPExcel_Calculation_Functions::VALUE();
  1234. }
  1235. $x = (string) floor($x);
  1236. $r = strtoupper(dechex($x));
  1237. if (strlen($r) == 8) {
  1238. // Two's Complement
  1239. $r = 'FF'.$r;
  1240. }
  1241. return self::_nbrConversionFormat($r,$places);
  1242. } // function DECTOHEX()
  1243. /**
  1244. * DECTOOCT
  1245. *
  1246. * Return an decimal value as octal.
  1247. *
  1248. * Excel Function:
  1249. * DEC2OCT(x[,places])
  1250. *
  1251. * @access public
  1252. * @category Engineering Functions
  1253. * @param string $x The decimal integer you want to convert. If number is negative,
  1254. * places is ignored and DEC2OCT returns a 10-character (30-bit)
  1255. * octal number in which the most significant bit is the sign bit.
  1256. * The remaining 29 bits are magnitude bits. Negative numbers are
  1257. * represented using two's-complement notation.
  1258. * If number < -536,870,912 or if number > 536,870,911, DEC2OCT
  1259. * returns the #NUM! error value.
  1260. * If number is nonnumeric, DEC2OCT returns the #VALUE! error value.
  1261. * If DEC2OCT requires more than places characters, it returns the
  1262. * #NUM! error value.
  1263. * @param integer $places The number of characters to use. If places is omitted, DEC2OCT uses
  1264. * the minimum number of characters necessary. Places is useful for
  1265. * padding the return value with leading 0s (zeros).
  1266. * If places is not an integer, it is truncated.
  1267. * If places is nonnumeric, DEC2OCT returns the #VALUE! error value.
  1268. * If places is zero or negative, DEC2OCT returns the #NUM! error value.
  1269. * @return string
  1270. */
  1271. public static function DECTOOCT($x, $places=null) {
  1272. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1273. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1274. if (is_bool($x)) {
  1275. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1276. $x = (int) $x;
  1277. } else {
  1278. return PHPExcel_Calculation_Functions::VALUE();
  1279. }
  1280. }
  1281. $x = (string) $x;
  1282. if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) {
  1283. return PHPExcel_Calculation_Functions::VALUE();
  1284. }
  1285. $x = (string) floor($x);
  1286. $r = decoct($x);
  1287. if (strlen($r) == 11) {
  1288. // Two's Complement
  1289. $r = substr($r,-10);
  1290. }
  1291. return self::_nbrConversionFormat($r,$places);
  1292. } // function DECTOOCT()
  1293. /**
  1294. * HEXTOBIN
  1295. *
  1296. * Return a hex value as binary.
  1297. *
  1298. * Excel Function:
  1299. * HEX2BIN(x[,places])
  1300. *
  1301. * @access public
  1302. * @category Engineering Functions
  1303. * @param string $x the hexadecimal number you want to convert. Number cannot
  1304. * contain more than 10 characters. The most significant bit of
  1305. * number is the sign bit (40th bit from the right). The remaining
  1306. * 9 bits are magnitude bits. Negative numbers are represented
  1307. * using two's-complement notation.
  1308. * If number is negative, HEX2BIN ignores places and returns a
  1309. * 10-character binary number.
  1310. * If number is negative, it cannot be less than FFFFFFFE00, and
  1311. * if number is positive, it cannot be greater than 1FF.
  1312. * If number is not a valid hexadecimal number, HEX2BIN returns
  1313. * the #NUM! error value.
  1314. * If HEX2BIN requires more than places characters, it returns
  1315. * the #NUM! error value.
  1316. * @param integer $places The number of characters to use. If places is omitted,
  1317. * HEX2BIN uses the minimum number of characters necessary. Places
  1318. * is useful for padding the return value with leading 0s (zeros).
  1319. * If places is not an integer, it is truncated.
  1320. * If places is nonnumeric, HEX2BIN returns the #VALUE! error value.
  1321. * If places is negative, HEX2BIN returns the #NUM! error value.
  1322. * @return string
  1323. */
  1324. public static function HEXTOBIN($x, $places=null) {
  1325. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1326. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1327. if (is_bool($x)) {
  1328. return PHPExcel_Calculation_Functions::VALUE();
  1329. }
  1330. $x = (string) $x;
  1331. if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) {
  1332. return PHPExcel_Calculation_Functions::NaN();
  1333. }
  1334. $binVal = decbin(hexdec($x));
  1335. return substr(self::_nbrConversionFormat($binVal,$places),-10);
  1336. } // function HEXTOBIN()
  1337. /**
  1338. * HEXTODEC
  1339. *
  1340. * Return a hex value as decimal.
  1341. *
  1342. * Excel Function:
  1343. * HEX2DEC(x)
  1344. *
  1345. * @access public
  1346. * @category Engineering Functions
  1347. * @param string $x The hexadecimal number you want to convert. This number cannot
  1348. * contain more than 10 characters (40 bits). The most significant
  1349. * bit of number is the sign bit. The remaining 39 bits are magnitude
  1350. * bits. Negative numbers are represented using two's-complement
  1351. * notation.
  1352. * If number is not a valid hexadecimal number, HEX2DEC returns the
  1353. * #NUM! error value.
  1354. * @return string
  1355. */
  1356. public static function HEXTODEC($x) {
  1357. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1358. if (is_bool($x)) {
  1359. return PHPExcel_Calculation_Functions::VALUE();
  1360. }
  1361. $x = (string) $x;
  1362. if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) {
  1363. return PHPExcel_Calculation_Functions::NaN();
  1364. }
  1365. return hexdec($x);
  1366. } // function HEXTODEC()
  1367. /**
  1368. * HEXTOOCT
  1369. *
  1370. * Return a hex value as octal.
  1371. *
  1372. * Excel Function:
  1373. * HEX2OCT(x[,places])
  1374. *
  1375. * @access public
  1376. * @category Engineering Functions
  1377. * @param string $x The hexadecimal number you want to convert. Number cannot
  1378. * contain more than 10 characters. The most significant bit of
  1379. * number is the sign bit. The remaining 39 bits are magnitude
  1380. * bits. Negative numbers are represented using two's-complement
  1381. * notation.
  1382. * If number is negative, HEX2OCT ignores places and returns a
  1383. * 10-character octal number.
  1384. * If number is negative, it cannot be less than FFE0000000, and
  1385. * if number is positive, it cannot be greater than 1FFFFFFF.
  1386. * If number is not a valid hexadecimal number, HEX2OCT returns
  1387. * the #NUM! error value.
  1388. * If HEX2OCT requires more than places characters, it returns
  1389. * the #NUM! error value.
  1390. * @param integer $places The number of characters to use. If places is omitted, HEX2OCT
  1391. * uses the minimum number of characters necessary. Places is
  1392. * useful for padding the return value with leading 0s (zeros).
  1393. * If places is not an integer, it is truncated.
  1394. * If places is nonnumeric, HEX2OCT returns the #VALUE! error
  1395. * value.
  1396. * If places is negative, HEX2OCT returns the #NUM! error value.
  1397. * @return string
  1398. */
  1399. public static function HEXTOOCT($x, $places=null) {
  1400. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1401. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1402. if (is_bool($x)) {
  1403. return PHPExcel_Calculation_Functions::VALUE();
  1404. }
  1405. $x = (string) $x;
  1406. if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) {
  1407. return PHPExcel_Calculation_Functions::NaN();
  1408. }
  1409. $octVal = decoct(hexdec($x));
  1410. return self::_nbrConversionFormat($octVal,$places);
  1411. } // function HEXTOOCT()
  1412. /**
  1413. * OCTTOBIN
  1414. *
  1415. * Return an octal value as binary.
  1416. *
  1417. * Excel Function:
  1418. * OCT2BIN(x[,places])
  1419. *
  1420. * @access public
  1421. * @category Engineering Functions
  1422. * @param string $x The octal number you want to convert. Number may not
  1423. * contain more than 10 characters. The most significant
  1424. * bit of number is the sign bit. The remaining 29 bits
  1425. * are magnitude bits. Negative numbers are represented
  1426. * using two's-complement notation.
  1427. * If number is negative, OCT2BIN ignores places and returns
  1428. * a 10-character binary number.
  1429. * If number is negative, it cannot be less than 7777777000,
  1430. * and if number is positive, it cannot be greater than 777.
  1431. * If number is not a valid octal number, OCT2BIN returns
  1432. * the #NUM! error value.
  1433. * If OCT2BIN requires more than places characters, it
  1434. * returns the #NUM! error value.
  1435. * @param integer $places The number of characters to use. If places is omitted,
  1436. * OCT2BIN uses the minimum number of characters necessary.
  1437. * Places is useful for padding the return value with
  1438. * leading 0s (zeros).
  1439. * If places is not an integer, it is truncated.
  1440. * If places is nonnumeric, OCT2BIN returns the #VALUE!
  1441. * error value.
  1442. * If places is negative, OCT2BIN returns the #NUM! error
  1443. * value.
  1444. * @return string
  1445. */
  1446. public static function OCTTOBIN($x, $places=null) {
  1447. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1448. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1449. if (is_bool($x)) {
  1450. return PHPExcel_Calculation_Functions::VALUE();
  1451. }
  1452. $x = (string) $x;
  1453. if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) {
  1454. return PHPExcel_Calculation_Functions::NaN();
  1455. }
  1456. $r = decbin(octdec($x));
  1457. return self::_nbrConversionFormat($r,$places);
  1458. } // function OCTTOBIN()
  1459. /**
  1460. * OCTTODEC
  1461. *
  1462. * Return an octal value as decimal.
  1463. *
  1464. * Excel Function:
  1465. * OCT2DEC(x)
  1466. *
  1467. * @access public
  1468. * @category Engineering Functions
  1469. * @param string $x The octal number you want to convert. Number may not contain
  1470. * more than 10 octal characters (30 bits). The most significant
  1471. * bit of number is the sign bit. The remaining 29 bits are
  1472. * magnitude bits. Negative numbers are represented using
  1473. * two's-complement notation.
  1474. * If number is not a valid octal number, OCT2DEC returns the
  1475. * #NUM! error value.
  1476. * @return string
  1477. */
  1478. public static function OCTTODEC($x) {
  1479. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1480. if (is_bool($x)) {
  1481. return PHPExcel_Calculation_Functions::VALUE();
  1482. }
  1483. $x = (string) $x;
  1484. if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) {
  1485. return PHPExcel_Calculation_Functions::NaN();
  1486. }
  1487. return octdec($x);
  1488. } // function OCTTODEC()
  1489. /**
  1490. * OCTTOHEX
  1491. *
  1492. * Return an octal value as hex.
  1493. *
  1494. * Excel Function:
  1495. * OCT2HEX(x[,places])
  1496. *
  1497. * @access public
  1498. * @category Engineering Functions
  1499. * @param string $x The octal number you want to convert. Number may not contain
  1500. * more than 10 octal characters (30 bits). The most significant
  1501. * bit of number is the sign bit. The remaining 29 bits are
  1502. * magnitude bits. Negative numbers are represented using
  1503. * two's-complement notation.
  1504. * If number is negative, OCT2HEX ignores places and returns a
  1505. * 10-character hexadecimal number.
  1506. * If number is not a valid octal number, OCT2HEX returns the
  1507. * #NUM! error value.
  1508. * If OCT2HEX requires more than places characters, it returns
  1509. * the #NUM! error value.
  1510. * @param integer $places The number of characters to use. If places is omitted, OCT2HEX
  1511. * uses the minimum number of characters necessary. Places is useful
  1512. * for padding the return value with leading 0s (zeros).
  1513. * If places is not an integer, it is truncated.
  1514. * If places is nonnumeric, OCT2HEX returns the #VALUE! error value.
  1515. * If places is negative, OCT2HEX returns the #NUM! error value.
  1516. * @return string
  1517. */
  1518. public static function OCTTOHEX($x, $places=null) {
  1519. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1520. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1521. if (is_bool($x)) {
  1522. return PHPExcel_Calculation_Functions::VALUE();
  1523. }
  1524. $x = (string) $x;
  1525. if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) {
  1526. return PHPExcel_Calculation_Functions::NaN();
  1527. }
  1528. $hexVal = strtoupper(dechex(octdec($x)));
  1529. return self::_nbrConversionFormat($hexVal,$places);
  1530. } // function OCTTOHEX()
  1531. /**
  1532. * COMPLEX
  1533. *
  1534. * Converts real and imaginary coefficients into a complex number of the form x + yi or x + yj.
  1535. *
  1536. * Excel Function:
  1537. * COMPLEX(realNumber,imaginary[,places])
  1538. *
  1539. * @access public
  1540. * @category Engineering Functions
  1541. * @param float $realNumber The real coefficient of the complex number.
  1542. * @param float $imaginary The imaginary coefficient of the complex number.
  1543. * @param string $suffix The suffix for the imaginary component of the complex number.
  1544. * If omitted, the suffix is assumed to be "i".
  1545. * @return string
  1546. */
  1547. public static function COMPLEX($realNumber=0.0, $imaginary=0.0, $suffix='i') {
  1548. $realNumber = (is_null($realNumber)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
  1549. $imaginary = (is_null($imaginary)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($imaginary);
  1550. $suffix = (is_null($suffix)) ? 'i' : PHPExcel_Calculation_Functions::flattenSingleValue($suffix);
  1551. if (((is_numeric($realNumber)) && (is_numeric($imaginary))) &&
  1552. (($suffix == 'i') || ($suffix == 'j') || ($suffix == ''))) {
  1553. $realNumber = (float) $realNumber;
  1554. $imaginary = (float) $imaginary;
  1555. if ($suffix == '') $suffix = 'i';
  1556. if ($realNumber == 0.0) {
  1557. if ($imaginary == 0.0) {
  1558. return (string) '0';
  1559. } elseif ($imaginary == 1.0) {
  1560. return (string) $suffix;
  1561. } elseif ($imaginary == -1.0) {
  1562. return (string) '-'.$suffix;
  1563. }
  1564. return (string) $imaginary.$suffix;
  1565. } elseif ($imaginary == 0.0) {
  1566. return (string) $realNumber;
  1567. } elseif ($imaginary == 1.0) {
  1568. return (string) $realNumber.'+'.$suffix;
  1569. } elseif ($imaginary == -1.0) {
  1570. return (string) $realNumber.'-'.$suffix;
  1571. }
  1572. if ($imaginary > 0) { $imaginary = (string) '+'.$imaginary; }
  1573. return (string) $realNumber.$imaginary.$suffix;
  1574. }
  1575. return PHPExcel_Calculation_Functions::VALUE();
  1576. } // function COMPLEX()
  1577. /**
  1578. * IMAGINARY
  1579. *
  1580. * Returns the imaginary coefficient of a complex number in x + yi or x + yj text format.
  1581. *
  1582. * Excel Function:
  1583. * IMAGINARY(complexNumber)
  1584. *
  1585. * @access public
  1586. * @category Engineering Functions
  1587. * @param string $complexNumber The complex number for which you want the imaginary
  1588. * coefficient.
  1589. * @return float
  1590. */
  1591. public static function IMAGINARY($complexNumber) {
  1592. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1593. $parsedComplex = self::_parseComplex($complexNumber);
  1594. return $parsedComplex['imaginary'];
  1595. } // function IMAGINARY()
  1596. /**
  1597. * IMREAL
  1598. *
  1599. * Returns the real coefficient of a complex number in x + yi or x + yj text format.
  1600. *
  1601. * Excel Function:
  1602. * IMREAL(complexNumber)
  1603. *
  1604. * @access public
  1605. * @category Engineering Functions
  1606. * @param string $complexNumber The complex number for which you want the real coefficient.
  1607. * @return float
  1608. */
  1609. public static function IMREAL($complexNumber) {
  1610. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1611. $parsedComplex = self::_parseComplex($complexNumber);
  1612. return $parsedComplex['real'];
  1613. } // function IMREAL()
  1614. /**
  1615. * IMABS
  1616. *
  1617. * Returns the absolute value (modulus) of a complex number in x + yi or x + yj text format.
  1618. *
  1619. * Excel Function:
  1620. * IMABS(complexNumber)
  1621. *
  1622. * @param string $complexNumber The complex number for which you want the absolute value.
  1623. * @return float
  1624. */
  1625. public static function IMABS($complexNumber) {
  1626. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1627. $parsedComplex = self::_parseComplex($complexNumber);
  1628. return sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']));
  1629. } // function IMABS()
  1630. /**
  1631. * IMARGUMENT
  1632. *
  1633. * Returns the argument theta of a complex number, i.e. the angle in radians from the real
  1634. * axis to the representation of the number in polar coordinates.
  1635. *
  1636. * Excel Function:
  1637. * IMARGUMENT(complexNumber)
  1638. *
  1639. * @param string $complexNumber The complex number for which you want the argument theta.
  1640. * @return float
  1641. */
  1642. public static function IMARGUMENT($complexNumber) {
  1643. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1644. $parsedComplex = self::_parseComplex($complexNumber);
  1645. if ($parsedComplex['real'] == 0.0) {
  1646. if ($parsedComplex['imaginary'] == 0.0) {
  1647. return 0.0;
  1648. } elseif($parsedComplex['imaginary'] < 0.0) {
  1649. return M_PI / -2;
  1650. } else {
  1651. return M_PI / 2;
  1652. }
  1653. } elseif ($parsedComplex['real'] > 0.0) {
  1654. return atan($parsedComplex['imaginary'] / $parsedComplex['real']);
  1655. } elseif ($parsedComplex['imaginary'] < 0.0) {
  1656. return 0 - (M_PI - atan(abs($parsedComplex['imaginary']) / abs($parsedComplex['real'])));
  1657. } else {
  1658. return M_PI - atan($parsedComplex['imaginary'] / abs($parsedComplex['real']));
  1659. }
  1660. } // function IMARGUMENT()
  1661. /**
  1662. * IMCONJUGATE
  1663. *
  1664. * Returns the complex conjugate of a complex number in x + yi or x + yj text format.
  1665. *
  1666. * Excel Function:
  1667. * IMCONJUGATE(complexNumber)
  1668. *
  1669. * @param string $complexNumber The complex number for which you want the conjugate.
  1670. * @return string
  1671. */
  1672. public static function IMCONJUGATE($complexNumber) {
  1673. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1674. $parsedComplex = self::_parseComplex($complexNumber);
  1675. if ($parsedComplex['imaginary'] == 0.0) {
  1676. return $parsedComplex['real'];
  1677. } else {
  1678. return self::_cleanComplex( self::COMPLEX( $parsedComplex['real'],
  1679. 0 - $parsedComplex['imaginary'],
  1680. $parsedComplex['suffix']
  1681. )
  1682. );
  1683. }
  1684. } // function IMCONJUGATE()
  1685. /**
  1686. * IMCOS
  1687. *
  1688. * Returns the cosine of a complex number in x + yi or x + yj text format.
  1689. *
  1690. * Excel Function:
  1691. * IMCOS(complexNumber)
  1692. *
  1693. * @param string $complexNumber The complex number for which you want the cosine.
  1694. * @return string|float
  1695. */
  1696. public static function IMCOS($complexNumber) {
  1697. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1698. $parsedComplex = self::_parseComplex($complexNumber);
  1699. if ($parsedComplex['imaginary'] == 0.0) {
  1700. return cos($parsedComplex['real']);
  1701. } else {
  1702. return self::IMCONJUGATE(self::COMPLEX(cos($parsedComplex['real']) * cosh($parsedComplex['imaginary']),sin($parsedComplex['real']) * sinh($parsedComplex['imaginary']),$parsedComplex['suffix']));
  1703. }
  1704. } // function IMCOS()
  1705. /**
  1706. * IMSIN
  1707. *
  1708. * Returns the sine of a complex number in x + yi or x + yj text format.
  1709. *
  1710. * Excel Function:
  1711. * IMSIN(complexNumber)
  1712. *
  1713. * @param string $complexNumber The complex number for which you want the sine.
  1714. * @return string|float
  1715. */
  1716. public static function IMSIN($complexNumber) {
  1717. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1718. $parsedComplex = self::_parseComplex($complexNumber);
  1719. if ($parsedComplex['imaginary'] == 0.0) {
  1720. return sin($parsedComplex['real']);
  1721. } else {
  1722. return self::COMPLEX(sin($parsedComplex['real']) * cosh($parsedComplex['imaginary']),cos($parsedComplex['real']) * sinh($parsedComplex['imaginary']),$parsedComplex['suffix']);
  1723. }
  1724. } // function IMSIN()
  1725. /**
  1726. * IMSQRT
  1727. *
  1728. * Returns the square root of a complex number in x + yi or x + yj text format.
  1729. *
  1730. * Excel Function:
  1731. * IMSQRT(complexNumber)
  1732. *
  1733. * @param string $complexNumber The complex number for which you want the square root.
  1734. * @return string
  1735. */
  1736. public static function IMSQRT($complexNumber) {
  1737. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1738. $parsedComplex = self::_parseComplex($complexNumber);
  1739. $theta = self::IMARGUMENT($complexNumber);
  1740. $d1 = cos($theta / 2);
  1741. $d2 = sin($theta / 2);
  1742. $r = sqrt(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
  1743. if ($parsedComplex['suffix'] == '') {
  1744. return self::COMPLEX($d1 * $r,$d2 * $r);
  1745. } else {
  1746. return self::COMPLEX($d1 * $r,$d2 * $r,$parsedComplex['suffix']);
  1747. }
  1748. } // function IMSQRT()
  1749. /**
  1750. * IMLN
  1751. *
  1752. * Returns the natural logarithm of a complex number in x + yi or x + yj text format.
  1753. *
  1754. * Excel Function:
  1755. * IMLN(complexNumber)
  1756. *
  1757. * @param string $complexNumber The complex number for which you want the natural logarithm.
  1758. * @return string
  1759. */
  1760. public static function IMLN($complexNumber) {
  1761. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1762. $parsedComplex = self::_parseComplex($complexNumber);
  1763. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1764. return PHPExcel_Calculation_Functions::NaN();
  1765. }
  1766. $logR = log(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
  1767. $t = self::IMARGUMENT($complexNumber);
  1768. if ($parsedComplex['suffix'] == '') {
  1769. return self::COMPLEX($logR,$t);
  1770. } else {
  1771. return self::COMPLEX($logR,$t,$parsedComplex['suffix']);
  1772. }
  1773. } // function IMLN()
  1774. /**
  1775. * IMLOG10
  1776. *
  1777. * Returns the common logarithm (base 10) of a complex number in x + yi or x + yj text format.
  1778. *
  1779. * Excel Function:
  1780. * IMLOG10(complexNumber)
  1781. *
  1782. * @param string $complexNumber The complex number for which you want the common logarithm.
  1783. * @return string
  1784. */
  1785. public static function IMLOG10($complexNumber) {
  1786. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1787. $parsedComplex = self::_parseComplex($complexNumber);
  1788. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1789. return PHPExcel_Calculation_Functions::NaN();
  1790. } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1791. return log10($parsedComplex['real']);
  1792. }
  1793. return self::IMPRODUCT(log10(EULER),self::IMLN($complexNumber));
  1794. } // function IMLOG10()
  1795. /**
  1796. * IMLOG2
  1797. *
  1798. * Returns the base-2 logarithm of a complex number in x + yi or x + yj text format.
  1799. *
  1800. * Excel Function:
  1801. * IMLOG2(complexNumber)
  1802. *
  1803. * @param string $complexNumber The complex number for which you want the base-2 logarithm.
  1804. * @return string
  1805. */
  1806. public static function IMLOG2($complexNumber) {
  1807. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1808. $parsedComplex = self::_parseComplex($complexNumber);
  1809. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1810. return PHPExcel_Calculation_Functions::NaN();
  1811. } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1812. return log($parsedComplex['real'],2);
  1813. }
  1814. return self::IMPRODUCT(log(EULER,2),self::IMLN($complexNumber));
  1815. } // function IMLOG2()
  1816. /**
  1817. * IMEXP
  1818. *
  1819. * Returns the exponential of a complex number in x + yi or x + yj text format.
  1820. *
  1821. * Excel Function:
  1822. * IMEXP(complexNumber)
  1823. *
  1824. * @param string $complexNumber The complex number for which you want the exponential.
  1825. * @return string
  1826. */
  1827. public static function IMEXP($complexNumber) {
  1828. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1829. $parsedComplex = self::_parseComplex($complexNumber);
  1830. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1831. return '1';
  1832. }
  1833. $e = exp($parsedComplex['real']);
  1834. $eX = $e * cos($parsedComplex['imaginary']);
  1835. $eY = $e * sin($parsedComplex['imaginary']);
  1836. if ($parsedComplex['suffix'] == '') {
  1837. return self::COMPLEX($eX,$eY);
  1838. } else {
  1839. return self::COMPLEX($eX,$eY,$parsedComplex['suffix']);
  1840. }
  1841. } // function IMEXP()
  1842. /**
  1843. * IMPOWER
  1844. *
  1845. * Returns a complex number in x + yi or x + yj text format raised to a power.
  1846. *
  1847. * Excel Function:
  1848. * IMPOWER(complexNumber,realNumber)
  1849. *
  1850. * @param string $complexNumber The complex number you want to raise to a power.
  1851. * @param float $realNumber The power to which you want to raise the complex number.
  1852. * @return string
  1853. */
  1854. public static function IMPOWER($complexNumber,$realNumber) {
  1855. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1856. $realNumber = PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
  1857. if (!is_numeric($realNumber)) {
  1858. return PHPExcel_Calculation_Functions::VALUE();
  1859. }
  1860. $parsedComplex = self::_parseComplex($complexNumber);
  1861. $r = sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']));
  1862. $rPower = pow($r,$realNumber);
  1863. $theta = self::IMARGUMENT($complexNumber) * $realNumber;
  1864. if ($theta == 0) {
  1865. return 1;
  1866. } elseif ($parsedComplex['imaginary'] == 0.0) {
  1867. return self::COMPLEX($rPower * cos($theta),$rPower * sin($theta),$parsedComplex['suffix']);
  1868. } else {
  1869. return self::COMPLEX($rPower * cos($theta),$rPower * sin($theta),$parsedComplex['suffix']);
  1870. }
  1871. } // function IMPOWER()
  1872. /**
  1873. * IMDIV
  1874. *
  1875. * Returns the quotient of two complex numbers in x + yi or x + yj text format.
  1876. *
  1877. * Excel Function:
  1878. * IMDIV(complexDividend,complexDivisor)
  1879. *
  1880. * @param string $complexDividend The complex numerator or dividend.
  1881. * @param string $complexDivisor The complex denominator or divisor.
  1882. * @return string
  1883. */
  1884. public static function IMDIV($complexDividend,$complexDivisor) {
  1885. $complexDividend = PHPExcel_Calculation_Functions::flattenSingleValue($complexDividend);
  1886. $complexDivisor = PHPExcel_Calculation_Functions::flattenSingleValue($complexDivisor);
  1887. $parsedComplexDividend = self::_parseComplex($complexDividend);
  1888. $parsedComplexDivisor = self::_parseComplex($complexDivisor);
  1889. if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') &&
  1890. ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) {
  1891. return PHPExcel_Calculation_Functions::NaN();
  1892. }
  1893. if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] == '')) {
  1894. $parsedComplexDivisor['suffix'] = $parsedComplexDividend['suffix'];
  1895. }
  1896. $d1 = ($parsedComplexDividend['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['imaginary']);
  1897. $d2 = ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['real']) - ($parsedComplexDividend['real'] * $parsedComplexDivisor['imaginary']);
  1898. $d3 = ($parsedComplexDivisor['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDivisor['imaginary'] * $parsedComplexDivisor['imaginary']);
  1899. $r = $d1/$d3;
  1900. $i = $d2/$d3;
  1901. if ($i > 0.0) {
  1902. return self::_cleanComplex($r.'+'.$i.$parsedComplexDivisor['suffix']);
  1903. } elseif ($i < 0.0) {
  1904. return self::_cleanComplex($r.$i.$parsedComplexDivisor['suffix']);
  1905. } else {
  1906. return $r;
  1907. }
  1908. } // function IMDIV()
  1909. /**
  1910. * IMSUB
  1911. *
  1912. * Returns the difference of two complex numbers in x + yi or x + yj text format.
  1913. *
  1914. * Excel Function:
  1915. * IMSUB(complexNumber1,complexNumber2)
  1916. *
  1917. * @param string $complexNumber1 The complex number from which to subtract complexNumber2.
  1918. * @param string $complexNumber2 The complex number to subtract from complexNumber1.
  1919. * @return string
  1920. */
  1921. public static function IMSUB($complexNumber1,$complexNumber2) {
  1922. $complexNumber1 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber1);
  1923. $complexNumber2 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber2);
  1924. $parsedComplex1 = self::_parseComplex($complexNumber1);
  1925. $parsedComplex2 = self::_parseComplex($complexNumber2);
  1926. if ((($parsedComplex1['suffix'] != '') && ($parsedComplex2['suffix'] != '')) &&
  1927. ($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) {
  1928. return PHPExcel_Calculation_Functions::NaN();
  1929. } elseif (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) {
  1930. $parsedComplex1['suffix'] = $parsedComplex2['suffix'];
  1931. }
  1932. $d1 = $parsedComplex1['real'] - $parsedComplex2['real'];
  1933. $d2 = $parsedComplex1['imaginary'] - $parsedComplex2['imaginary'];
  1934. return self::COMPLEX($d1,$d2,$parsedComplex1['suffix']);
  1935. } // function IMSUB()
  1936. /**
  1937. * IMSUM
  1938. *
  1939. * Returns the sum of two or more complex numbers in x + yi or x + yj text format.
  1940. *
  1941. * Excel Function:
  1942. * IMSUM(complexNumber[,complexNumber[,...]])
  1943. *
  1944. * @param string $complexNumber,... Series of complex numbers to add
  1945. * @return string
  1946. */
  1947. public static function IMSUM() {
  1948. // Return value
  1949. $returnValue = self::_parseComplex('0');
  1950. $activeSuffix = '';
  1951. // Loop through the arguments
  1952. $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
  1953. foreach ($aArgs as $arg) {
  1954. $parsedComplex = self::_parseComplex($arg);
  1955. if ($activeSuffix == '') {
  1956. $activeSuffix = $parsedComplex['suffix'];
  1957. } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
  1958. return PHPExcel_Calculation_Functions::VALUE();
  1959. }
  1960. $returnValue['real'] += $parsedComplex['real'];
  1961. $returnValue['imaginary'] += $parsedComplex['imaginary'];
  1962. }
  1963. if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; }
  1964. return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix);
  1965. } // function IMSUM()
  1966. /**
  1967. * IMPRODUCT
  1968. *
  1969. * Returns the product of two or more complex numbers in x + yi or x + yj text format.
  1970. *
  1971. * Excel Function:
  1972. * IMPRODUCT(complexNumber[,complexNumber[,...]])
  1973. *
  1974. * @param string $complexNumber,... Series of complex numbers to multiply
  1975. * @return string
  1976. */
  1977. public static function IMPRODUCT() {
  1978. // Return value
  1979. $returnValue = self::_parseComplex('1');
  1980. $activeSuffix = '';
  1981. // Loop through the arguments
  1982. $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
  1983. foreach ($aArgs as $arg) {
  1984. $parsedComplex = self::_parseComplex($arg);
  1985. $workValue = $returnValue;
  1986. if (($parsedComplex['suffix'] != '') && ($activeSuffix == '')) {
  1987. $activeSuffix = $parsedComplex['suffix'];
  1988. } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
  1989. return PHPExcel_Calculation_Functions::NaN();
  1990. }
  1991. $returnValue['real'] = ($workValue['real'] * $parsedComplex['real']) - ($workValue['imaginary'] * $parsedComplex['imaginary']);
  1992. $returnValue['imaginary'] = ($workValue['real'] * $parsedComplex['imaginary']) + ($workValue['imaginary'] * $parsedComplex['real']);
  1993. }
  1994. if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; }
  1995. return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix);
  1996. } // function IMPRODUCT()
  1997. /**
  1998. * DELTA
  1999. *
  2000. * Tests whether two values are equal. Returns 1 if number1 = number2; returns 0 otherwise.
  2001. * Use this function to filter a set of values. For example, by summing several DELTA
  2002. * functions you calculate the count of equal pairs. This function is also known as the
  2003. * Kronecker Delta function.
  2004. *
  2005. * Excel Function:
  2006. * DELTA(a[,b])
  2007. *
  2008. * @param float $a The first number.
  2009. * @param float $b The second number. If omitted, b is assumed to be zero.
  2010. * @return int
  2011. */
  2012. public static function DELTA($a, $b=0) {
  2013. $a = PHPExcel_Calculation_Functions::flattenSingleValue($a);
  2014. $b = PHPExcel_Calculation_Functions::flattenSingleValue($b);
  2015. return (int) ($a == $b);
  2016. } // function DELTA()
  2017. /**
  2018. * GESTEP
  2019. *
  2020. * Excel Function:
  2021. * GESTEP(number[,step])
  2022. *
  2023. * Returns 1 if number >= step; returns 0 (zero) otherwise
  2024. * Use this function to filter a set of values. For example, by summing several GESTEP
  2025. * functions you calculate the count of values that exceed a threshold.
  2026. *
  2027. * @param float $number The value to test against step.
  2028. * @param float $step The threshold value.
  2029. * If you omit a value for step, GESTEP uses zero.
  2030. * @return int
  2031. */
  2032. public static function GESTEP($number, $step=0) {
  2033. $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
  2034. $step = PHPExcel_Calculation_Functions::flattenSingleValue($step);
  2035. return (int) ($number >= $step);
  2036. } // function GESTEP()
  2037. //
  2038. // Private method to calculate the erf value
  2039. //
  2040. private static $_two_sqrtpi = 1.128379167095512574;
  2041. public static function _erfVal($x) {
  2042. if (abs($x) > 2.2) {
  2043. return 1 - self::_erfcVal($x);
  2044. }
  2045. $sum = $term = $x;
  2046. $xsqr = ($x * $x);
  2047. $j = 1;
  2048. do {
  2049. $term *= $xsqr / $j;
  2050. $sum -= $term / (2 * $j + 1);
  2051. ++$j;
  2052. $term *= $xsqr / $j;
  2053. $sum += $term / (2 * $j + 1);
  2054. ++$j;
  2055. if ($sum == 0.0) {
  2056. break;
  2057. }
  2058. } while (abs($term / $sum) > PRECISION);
  2059. return self::$_two_sqrtpi * $sum;
  2060. } // function _erfVal()
  2061. /**
  2062. * ERF
  2063. *
  2064. * Returns the error function integrated between the lower and upper bound arguments.
  2065. *
  2066. * Note: In Excel 2007 or earlier, if you input a negative value for the upper or lower bound arguments,
  2067. * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
  2068. * improved, so that it can now calculate the function for both positive and negative ranges.
  2069. * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
  2070. *
  2071. * Excel Function:
  2072. * ERF(lower[,upper])
  2073. *
  2074. * @param float $lower lower bound for integrating ERF
  2075. * @param float $upper upper bound for integrating ERF.
  2076. * If omitted, ERF integrates between zero and lower_limit
  2077. * @return float
  2078. */
  2079. public static function ERF($lower, $upper = NULL) {
  2080. $lower = PHPExcel_Calculation_Functions::flattenSingleValue($lower);
  2081. $upper = PHPExcel_Calculation_Functions::flattenSingleValue($upper);
  2082. if (is_numeric($lower)) {
  2083. if (is_null($upper)) {
  2084. return self::_erfVal($lower);
  2085. }
  2086. if (is_numeric($upper)) {
  2087. return self::_erfVal($upper) - self::_erfVal($lower);
  2088. }
  2089. }
  2090. return PHPExcel_Calculation_Functions::VALUE();
  2091. } // function ERF()
  2092. //
  2093. // Private method to calculate the erfc value
  2094. //
  2095. private static $_one_sqrtpi = 0.564189583547756287;
  2096. private static function _erfcVal($x) {
  2097. if (abs($x) < 2.2) {
  2098. return 1 - self::_erfVal($x);
  2099. }
  2100. if ($x < 0) {
  2101. return 2 - self::ERFC(-$x);
  2102. }
  2103. $a = $n = 1;
  2104. $b = $c = $x;
  2105. $d = ($x * $x) + 0.5;
  2106. $q1 = $q2 = $b / $d;
  2107. $t = 0;
  2108. do {
  2109. $t = $a * $n + $b * $x;
  2110. $a = $b;
  2111. $b = $t;
  2112. $t = $c * $n + $d * $x;
  2113. $c = $d;
  2114. $d = $t;
  2115. $n += 0.5;
  2116. $q1 = $q2;
  2117. $q2 = $b / $d;
  2118. } while ((abs($q1 - $q2) / $q2) > PRECISION);
  2119. return self::$_one_sqrtpi * exp(-$x * $x) * $q2;
  2120. } // function _erfcVal()
  2121. /**
  2122. * ERFC
  2123. *
  2124. * Returns the complementary ERF function integrated between x and infinity
  2125. *
  2126. * Note: In Excel 2007 or earlier, if you input a negative value for the lower bound argument,
  2127. * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
  2128. * improved, so that it can now calculate the function for both positive and negative x values.
  2129. * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
  2130. *
  2131. * Excel Function:
  2132. * ERFC(x)
  2133. *
  2134. * @param float $x The lower bound for integrating ERFC
  2135. * @return float
  2136. */
  2137. public static function ERFC($x) {
  2138. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  2139. if (is_numeric($x)) {
  2140. return self::_erfcVal($x);
  2141. }
  2142. return PHPExcel_Calculation_Functions::VALUE();
  2143. } // function ERFC()
  2144. /**
  2145. * getConversionGroups
  2146. * Returns a list of the different conversion groups for UOM conversions
  2147. *
  2148. * @return array
  2149. */
  2150. public static function getConversionGroups() {
  2151. $conversionGroups = array();
  2152. foreach(self::$_conversionUnits as $conversionUnit) {
  2153. $conversionGroups[] = $conversionUnit['Group'];
  2154. }
  2155. return array_merge(array_unique($conversionGroups));
  2156. } // function getConversionGroups()
  2157. /**
  2158. * getConversionGroupUnits
  2159. * Returns an array of units of measure, for a specified conversion group, or for all groups
  2160. *
  2161. * @param string $group The group whose units of measure you want to retrieve
  2162. * @return array
  2163. */
  2164. public static function getConversionGroupUnits($group = NULL) {
  2165. $conversionGroups = array();
  2166. foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) {
  2167. if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
  2168. $conversionGroups[$conversionGroup['Group']][] = $conversionUnit;
  2169. }
  2170. }
  2171. return $conversionGroups;
  2172. } // function getConversionGroupUnits()
  2173. /**
  2174. * getConversionGroupUnitDetails
  2175. *
  2176. * @param string $group The group whose units of measure you want to retrieve
  2177. * @return array
  2178. */
  2179. public static function getConversionGroupUnitDetails($group = NULL) {
  2180. $conversionGroups = array();
  2181. foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) {
  2182. if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
  2183. $conversionGroups[$conversionGroup['Group']][] = array( 'unit' => $conversionUnit,
  2184. 'description' => $conversionGroup['Unit Name']
  2185. );
  2186. }
  2187. }
  2188. return $conversionGroups;
  2189. } // function getConversionGroupUnitDetails()
  2190. /**
  2191. * getConversionMultipliers
  2192. * Returns an array of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM()
  2193. *
  2194. * @return array of mixed
  2195. */
  2196. public static function getConversionMultipliers() {
  2197. return self::$_conversionMultipliers;
  2198. } // function getConversionGroups()
  2199. /**
  2200. * CONVERTUOM
  2201. *
  2202. * Converts a number from one measurement system to another.
  2203. * For example, CONVERT can translate a table of distances in miles to a table of distances
  2204. * in kilometers.
  2205. *
  2206. * Excel Function:
  2207. * CONVERT(value,fromUOM,toUOM)
  2208. *
  2209. * @param float $value The value in fromUOM to convert.
  2210. * @param string $fromUOM The units for value.
  2211. * @param string $toUOM The units for the result.
  2212. *
  2213. * @return float
  2214. */
  2215. public static function CONVERTUOM($value, $fromUOM, $toUOM) {
  2216. $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
  2217. $fromUOM = PHPExcel_Calculation_Functions::flattenSingleValue($fromUOM);
  2218. $toUOM = PHPExcel_Calculation_Functions::flattenSingleValue($toUOM);
  2219. if (!is_numeric($value)) {
  2220. return PHPExcel_Calculation_Functions::VALUE();
  2221. }
  2222. $fromMultiplier = 1.0;
  2223. if (isset(self::$_conversionUnits[$fromUOM])) {
  2224. $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group'];
  2225. } else {
  2226. $fromMultiplier = substr($fromUOM,0,1);
  2227. $fromUOM = substr($fromUOM,1);
  2228. if (isset(self::$_conversionMultipliers[$fromMultiplier])) {
  2229. $fromMultiplier = self::$_conversionMultipliers[$fromMultiplier]['multiplier'];
  2230. } else {
  2231. return PHPExcel_Calculation_Functions::NA();
  2232. }
  2233. if ((isset(self::$_conversionUnits[$fromUOM])) && (self::$_conversionUnits[$fromUOM]['AllowPrefix'])) {
  2234. $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group'];
  2235. } else {
  2236. return PHPExcel_Calculation_Functions::NA();
  2237. }
  2238. }
  2239. $value *= $fromMultiplier;
  2240. $toMultiplier = 1.0;
  2241. if (isset(self::$_conversionUnits[$toUOM])) {
  2242. $unitGroup2 = self::$_conversionUnits[$toUOM]['Group'];
  2243. } else {
  2244. $toMultiplier = substr($toUOM,0,1);
  2245. $toUOM = substr($toUOM,1);
  2246. if (isset(self::$_conversionMultipliers[$toMultiplier])) {
  2247. $toMultiplier = self::$_conversionMultipliers[$toMultiplier]['multiplier'];
  2248. } else {
  2249. return PHPExcel_Calculation_Functions::NA();
  2250. }
  2251. if ((isset(self::$_conversionUnits[$toUOM])) && (self::$_conversionUnits[$toUOM]['AllowPrefix'])) {
  2252. $unitGroup2 = self::$_conversionUnits[$toUOM]['Group'];
  2253. } else {
  2254. return PHPExcel_Calculation_Functions::NA();
  2255. }
  2256. }
  2257. if ($unitGroup1 != $unitGroup2) {
  2258. return PHPExcel_Calculation_Functions::NA();
  2259. }
  2260. if (($fromUOM == $toUOM) && ($fromMultiplier == $toMultiplier)) {
  2261. // We've already factored $fromMultiplier into the value, so we need
  2262. // to reverse it again
  2263. return $value / $fromMultiplier;
  2264. } elseif ($unitGroup1 == 'Temperature') {
  2265. if (($fromUOM == 'F') || ($fromUOM == 'fah')) {
  2266. if (($toUOM == 'F') || ($toUOM == 'fah')) {
  2267. return $value;
  2268. } else {
  2269. $value = (($value - 32) / 1.8);
  2270. if (($toUOM == 'K') || ($toUOM == 'kel')) {
  2271. $value += 273.15;
  2272. }
  2273. return $value;
  2274. }
  2275. } elseif ((($fromUOM == 'K') || ($fromUOM == 'kel')) &&
  2276. (($toUOM == 'K') || ($toUOM == 'kel'))) {
  2277. return $value;
  2278. } elseif ((($fromUOM == 'C') || ($fromUOM == 'cel')) &&
  2279. (($toUOM == 'C') || ($toUOM == 'cel'))) {
  2280. return $value;
  2281. }
  2282. if (($toUOM == 'F') || ($toUOM == 'fah')) {
  2283. if (($fromUOM == 'K') || ($fromUOM == 'kel')) {
  2284. $value -= 273.15;
  2285. }
  2286. return ($value * 1.8) + 32;
  2287. }
  2288. if (($toUOM == 'C') || ($toUOM == 'cel')) {
  2289. return $value - 273.15;
  2290. }
  2291. return $value + 273.15;
  2292. }
  2293. return ($value * self::$_unitConversions[$unitGroup1][$fromUOM][$toUOM]) / $toMultiplier;
  2294. } // function CONVERTUOM()
  2295. } // class PHPExcel_Calculation_Engineering