Engineering.php 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. if (!defined('PHPEXCEL_ROOT')) {
  8. /**
  9. * @ignore
  10. */
  11. define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
  12. require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  13. }
  14. /** EULER */
  15. define('EULER', 2.71828182845904523536);
  16. /**
  17. * PHPExcel_Calculation_Engineering
  18. *
  19. * Copyright (c) 2006 - 2015 PHPExcel
  20. *
  21. * This library is free software; you can redistribute it and/or
  22. * modify it under the terms of the GNU Lesser General Public
  23. * License as published by the Free Software Foundation; either
  24. * version 2.1 of the License, or (at your option) any later version.
  25. *
  26. * This library is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  29. * Lesser General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Lesser General Public
  32. * License along with this library; if not, write to the Free Software
  33. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  34. *
  35. * @category PHPExcel
  36. * @package PHPExcel_Calculation
  37. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  38. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  39. * @version ##VERSION##, ##DATE##
  40. */
  41. class PHPExcel_Calculation_Engineering
  42. {
  43. /**
  44. * Details of the Units of measure that can be used in CONVERTUOM()
  45. *
  46. * @var mixed[]
  47. */
  48. private static $conversionUnits = array(
  49. 'g' => array('Group' => 'Mass', 'Unit Name' => 'Gram', 'AllowPrefix' => true),
  50. 'sg' => array('Group' => 'Mass', 'Unit Name' => 'Slug', 'AllowPrefix' => false),
  51. 'lbm' => array('Group' => 'Mass', 'Unit Name' => 'Pound mass (avoirdupois)', 'AllowPrefix' => false),
  52. 'u' => array('Group' => 'Mass', 'Unit Name' => 'U (atomic mass unit)', 'AllowPrefix' => true),
  53. 'ozm' => array('Group' => 'Mass', 'Unit Name' => 'Ounce mass (avoirdupois)', 'AllowPrefix' => false),
  54. 'm' => array('Group' => 'Distance', 'Unit Name' => 'Meter', 'AllowPrefix' => true),
  55. 'mi' => array('Group' => 'Distance', 'Unit Name' => 'Statute mile', 'AllowPrefix' => false),
  56. 'Nmi' => array('Group' => 'Distance', 'Unit Name' => 'Nautical mile', 'AllowPrefix' => false),
  57. 'in' => array('Group' => 'Distance', 'Unit Name' => 'Inch', 'AllowPrefix' => false),
  58. 'ft' => array('Group' => 'Distance', 'Unit Name' => 'Foot', 'AllowPrefix' => false),
  59. 'yd' => array('Group' => 'Distance', 'Unit Name' => 'Yard', 'AllowPrefix' => false),
  60. 'ang' => array('Group' => 'Distance', 'Unit Name' => 'Angstrom', 'AllowPrefix' => true),
  61. 'Pica' => array('Group' => 'Distance', 'Unit Name' => 'Pica (1/72 in)', 'AllowPrefix' => false),
  62. 'yr' => array('Group' => 'Time', 'Unit Name' => 'Year', 'AllowPrefix' => false),
  63. 'day' => array('Group' => 'Time', 'Unit Name' => 'Day', 'AllowPrefix' => false),
  64. 'hr' => array('Group' => 'Time', 'Unit Name' => 'Hour', 'AllowPrefix' => false),
  65. 'mn' => array('Group' => 'Time', 'Unit Name' => 'Minute', 'AllowPrefix' => false),
  66. 'sec' => array('Group' => 'Time', 'Unit Name' => 'Second', 'AllowPrefix' => true),
  67. 'Pa' => array('Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => true),
  68. 'p' => array('Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => true),
  69. 'atm' => array('Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => true),
  70. 'at' => array('Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => true),
  71. 'mmHg' => array('Group' => 'Pressure', 'Unit Name' => 'mm of Mercury', 'AllowPrefix' => true),
  72. 'N' => array('Group' => 'Force', 'Unit Name' => 'Newton', 'AllowPrefix' => true),
  73. 'dyn' => array('Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => true),
  74. 'dy' => array('Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => true),
  75. 'lbf' => array('Group' => 'Force', 'Unit Name' => 'Pound force', 'AllowPrefix' => false),
  76. 'J' => array('Group' => 'Energy', 'Unit Name' => 'Joule', 'AllowPrefix' => true),
  77. 'e' => array('Group' => 'Energy', 'Unit Name' => 'Erg', 'AllowPrefix' => true),
  78. 'c' => array('Group' => 'Energy', 'Unit Name' => 'Thermodynamic calorie', 'AllowPrefix' => true),
  79. 'cal' => array('Group' => 'Energy', 'Unit Name' => 'IT calorie', 'AllowPrefix' => true),
  80. 'eV' => array('Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => true),
  81. 'ev' => array('Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => true),
  82. 'HPh' => array('Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => false),
  83. 'hh' => array('Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => false),
  84. 'Wh' => array('Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => true),
  85. 'wh' => array('Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => true),
  86. 'flb' => array('Group' => 'Energy', 'Unit Name' => 'Foot-pound', 'AllowPrefix' => false),
  87. 'BTU' => array('Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => false),
  88. 'btu' => array('Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => false),
  89. 'HP' => array('Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => false),
  90. 'h' => array('Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => false),
  91. 'W' => array('Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => true),
  92. 'w' => array('Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => true),
  93. 'T' => array('Group' => 'Magnetism', 'Unit Name' => 'Tesla', 'AllowPrefix' => true),
  94. 'ga' => array('Group' => 'Magnetism', 'Unit Name' => 'Gauss', 'AllowPrefix' => true),
  95. 'C' => array('Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => false),
  96. 'cel' => array('Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => false),
  97. 'F' => array('Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => false),
  98. 'fah' => array('Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => false),
  99. 'K' => array('Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => false),
  100. 'kel' => array('Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => false),
  101. 'tsp' => array('Group' => 'Liquid', 'Unit Name' => 'Teaspoon', 'AllowPrefix' => false),
  102. 'tbs' => array('Group' => 'Liquid', 'Unit Name' => 'Tablespoon', 'AllowPrefix' => false),
  103. 'oz' => array('Group' => 'Liquid', 'Unit Name' => 'Fluid Ounce', 'AllowPrefix' => false),
  104. 'cup' => array('Group' => 'Liquid', 'Unit Name' => 'Cup', 'AllowPrefix' => false),
  105. 'pt' => array('Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => false),
  106. 'us_pt' => array('Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => false),
  107. 'uk_pt' => array('Group' => 'Liquid', 'Unit Name' => 'U.K. Pint', 'AllowPrefix' => false),
  108. 'qt' => array('Group' => 'Liquid', 'Unit Name' => 'Quart', 'AllowPrefix' => false),
  109. 'gal' => array('Group' => 'Liquid', 'Unit Name' => 'Gallon', 'AllowPrefix' => false),
  110. 'l' => array('Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => true),
  111. 'lt' => array('Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => true),
  112. );
  113. /**
  114. * Details of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM()
  115. *
  116. * @var mixed[]
  117. */
  118. private static $conversionMultipliers = array(
  119. '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(
  146. 'Mass' => array(
  147. 'g' => array(
  148. 'g' => 1.0,
  149. 'sg' => 6.85220500053478E-05,
  150. 'lbm' => 2.20462291469134E-03,
  151. 'u' => 6.02217000000000E+23,
  152. 'ozm' => 3.52739718003627E-02,
  153. ),
  154. 'sg' => array(
  155. 'g' => 1.45938424189287E+04,
  156. 'sg' => 1.0,
  157. 'lbm' => 3.21739194101647E+01,
  158. 'u' => 8.78866000000000E+27,
  159. 'ozm' => 5.14782785944229E+02,
  160. ),
  161. 'lbm' => array(
  162. 'g' => 4.5359230974881148E+02,
  163. 'sg' => 3.10810749306493E-02,
  164. 'lbm' => 1.0,
  165. 'u' => 2.73161000000000E+26,
  166. 'ozm' => 1.60000023429410E+01,
  167. ),
  168. 'u' => array(
  169. 'g' => 1.66053100460465E-24,
  170. 'sg' => 1.13782988532950E-28,
  171. 'lbm' => 3.66084470330684E-27,
  172. 'u' => 1.0,
  173. 'ozm' => 5.85735238300524E-26,
  174. ),
  175. 'ozm' => array(
  176. 'g' => 2.83495152079732E+01,
  177. 'sg' => 1.94256689870811E-03,
  178. 'lbm' => 6.24999908478882E-02,
  179. 'u' => 1.70725600000000E+25,
  180. 'ozm' => 1.0,
  181. ),
  182. ),
  183. 'Distance' => array(
  184. 'm' => array(
  185. 'm' => 1.0,
  186. 'mi' => 6.21371192237334E-04,
  187. 'Nmi' => 5.39956803455724E-04,
  188. 'in' => 3.93700787401575E+01,
  189. 'ft' => 3.28083989501312E+00,
  190. 'yd' => 1.09361329797891E+00,
  191. 'ang' => 1.00000000000000E+10,
  192. 'Pica' => 2.83464566929116E+03,
  193. ),
  194. 'mi' => array(
  195. 'm' => 1.60934400000000E+03,
  196. 'mi' => 1.0,
  197. 'Nmi' => 8.68976241900648E-01,
  198. 'in' => 6.33600000000000E+04,
  199. 'ft' => 5.28000000000000E+03,
  200. 'yd' => 1.76000000000000E+03,
  201. 'ang' => 1.60934400000000E+13,
  202. 'Pica' => 4.56191999999971E+06,
  203. ),
  204. 'Nmi' => array(
  205. 'm' => 1.85200000000000E+03,
  206. 'mi' => 1.15077944802354E+00,
  207. 'Nmi' => 1.0,
  208. 'in' => 7.29133858267717E+04,
  209. 'ft' => 6.07611548556430E+03,
  210. 'yd' => 2.02537182785694E+03,
  211. 'ang' => 1.85200000000000E+13,
  212. 'Pica' => 5.24976377952723E+06,
  213. ),
  214. 'in' => array(
  215. 'm' => 2.54000000000000E-02,
  216. 'mi' => 1.57828282828283E-05,
  217. 'Nmi' => 1.37149028077754E-05,
  218. 'in' => 1.0,
  219. 'ft' => 8.33333333333333E-02,
  220. 'yd' => 2.77777777686643E-02,
  221. 'ang' => 2.54000000000000E+08,
  222. 'Pica' => 7.19999999999955E+01,
  223. ),
  224. 'ft' => array(
  225. 'm' => 3.04800000000000E-01,
  226. 'mi' => 1.89393939393939E-04,
  227. 'Nmi' => 1.64578833693305E-04,
  228. 'in' => 1.20000000000000E+01,
  229. 'ft' => 1.0,
  230. 'yd' => 3.33333333223972E-01,
  231. 'ang' => 3.04800000000000E+09,
  232. 'Pica' => 8.63999999999946E+02,
  233. ),
  234. 'yd' => array(
  235. 'm' => 9.14400000300000E-01,
  236. 'mi' => 5.68181818368230E-04,
  237. 'Nmi' => 4.93736501241901E-04,
  238. 'in' => 3.60000000118110E+01,
  239. 'ft' => 3.00000000000000E+00,
  240. 'yd' => 1.0,
  241. 'ang' => 9.14400000300000E+09,
  242. 'Pica' => 2.59200000085023E+03,
  243. ),
  244. 'ang' => array(
  245. 'm' => 1.00000000000000E-10,
  246. 'mi' => 6.21371192237334E-14,
  247. 'Nmi' => 5.39956803455724E-14,
  248. 'in' => 3.93700787401575E-09,
  249. 'ft' => 3.28083989501312E-10,
  250. 'yd' => 1.09361329797891E-10,
  251. 'ang' => 1.0,
  252. 'Pica' => 2.83464566929116E-07,
  253. ),
  254. 'Pica' => array(
  255. 'm' => 3.52777777777800E-04,
  256. 'mi' => 2.19205948372629E-07,
  257. 'Nmi' => 1.90484761219114E-07,
  258. 'in' => 1.38888888888898E-02,
  259. 'ft' => 1.15740740740748E-03,
  260. 'yd' => 3.85802469009251E-04,
  261. 'ang' => 3.52777777777800E+06,
  262. 'Pica' => 1.0,
  263. ),
  264. ),
  265. 'Time' => array(
  266. 'yr' => array(
  267. 'yr' => 1.0,
  268. 'day' => 365.25,
  269. 'hr' => 8766.0,
  270. 'mn' => 525960.0,
  271. 'sec' => 31557600.0,
  272. ),
  273. 'day' => array(
  274. 'yr' => 2.73785078713210E-03,
  275. 'day' => 1.0,
  276. 'hr' => 24.0,
  277. 'mn' => 1440.0,
  278. 'sec' => 86400.0,
  279. ),
  280. 'hr' => array(
  281. 'yr' => 1.14077116130504E-04,
  282. 'day' => 4.16666666666667E-02,
  283. 'hr' => 1.0,
  284. 'mn' => 60.0,
  285. 'sec' => 3600.0,
  286. ),
  287. 'mn' => array(
  288. 'yr' => 1.90128526884174E-06,
  289. 'day' => 6.94444444444444E-04,
  290. 'hr' => 1.66666666666667E-02,
  291. 'mn' => 1.0,
  292. 'sec' => 60.0,
  293. ),
  294. 'sec' => array(
  295. 'yr' => 3.16880878140289E-08,
  296. 'day' => 1.15740740740741E-05,
  297. 'hr' => 2.77777777777778E-04,
  298. 'mn' => 1.66666666666667E-02,
  299. 'sec' => 1.0,
  300. ),
  301. ),
  302. 'Pressure' => array(
  303. 'Pa' => array(
  304. 'Pa' => 1.0,
  305. 'p' => 1.0,
  306. 'atm' => 9.86923299998193E-06,
  307. 'at' => 9.86923299998193E-06,
  308. 'mmHg' => 7.50061707998627E-03,
  309. ),
  310. 'p' => array(
  311. 'Pa' => 1.0,
  312. 'p' => 1.0,
  313. 'atm' => 9.86923299998193E-06,
  314. 'at' => 9.86923299998193E-06,
  315. 'mmHg' => 7.50061707998627E-03,
  316. ),
  317. 'atm' => array(
  318. 'Pa' => 1.01324996583000E+05,
  319. 'p' => 1.01324996583000E+05,
  320. 'atm' => 1.0,
  321. 'at' => 1.0,
  322. 'mmHg' => 760.0,
  323. ),
  324. 'at' => array(
  325. 'Pa' => 1.01324996583000E+05,
  326. 'p' => 1.01324996583000E+05,
  327. 'atm' => 1.0,
  328. 'at' => 1.0,
  329. 'mmHg' => 760.0,
  330. ),
  331. 'mmHg' => array(
  332. 'Pa' => 1.33322363925000E+02,
  333. 'p' => 1.33322363925000E+02,
  334. 'atm' => 1.31578947368421E-03,
  335. 'at' => 1.31578947368421E-03,
  336. 'mmHg' => 1.0,
  337. ),
  338. ),
  339. 'Force' => array(
  340. 'N' => array(
  341. 'N' => 1.0,
  342. 'dyn' => 1.0E+5,
  343. 'dy' => 1.0E+5,
  344. 'lbf' => 2.24808923655339E-01,
  345. ),
  346. 'dyn' => array(
  347. 'N' => 1.0E-5,
  348. 'dyn' => 1.0,
  349. 'dy' => 1.0,
  350. 'lbf' => 2.24808923655339E-06,
  351. ),
  352. 'dy' => array(
  353. 'N' => 1.0E-5,
  354. 'dyn' => 1.0,
  355. 'dy' => 1.0,
  356. 'lbf' => 2.24808923655339E-06,
  357. ),
  358. 'lbf' => array(
  359. 'N' => 4.448222,
  360. 'dyn' => 4.448222E+5,
  361. 'dy' => 4.448222E+5,
  362. 'lbf' => 1.0,
  363. ),
  364. ),
  365. 'Energy' => array(
  366. 'J' => array(
  367. 'J' => 1.0,
  368. 'e' => 9.99999519343231E+06,
  369. 'c' => 2.39006249473467E-01,
  370. 'cal' => 2.38846190642017E-01,
  371. 'eV' => 6.24145700000000E+18,
  372. 'ev' => 6.24145700000000E+18,
  373. 'HPh' => 3.72506430801000E-07,
  374. 'hh' => 3.72506430801000E-07,
  375. 'Wh' => 2.77777916238711E-04,
  376. 'wh' => 2.77777916238711E-04,
  377. 'flb' => 2.37304222192651E+01,
  378. 'BTU' => 9.47815067349015E-04,
  379. 'btu' => 9.47815067349015E-04,
  380. ),
  381. 'e' => array(
  382. 'J' => 1.00000048065700E-07,
  383. 'e' => 1.0,
  384. 'c' => 2.39006364353494E-08,
  385. 'cal' => 2.38846305445111E-08,
  386. 'eV' => 6.24146000000000E+11,
  387. 'ev' => 6.24146000000000E+11,
  388. 'HPh' => 3.72506609848824E-14,
  389. 'hh' => 3.72506609848824E-14,
  390. 'Wh' => 2.77778049754611E-11,
  391. 'wh' => 2.77778049754611E-11,
  392. 'flb' => 2.37304336254586E-06,
  393. 'BTU' => 9.47815522922962E-11,
  394. 'btu' => 9.47815522922962E-11,
  395. ),
  396. 'c' => array(
  397. 'J' => 4.18399101363672E+00,
  398. 'e' => 4.18398900257312E+07,
  399. 'c' => 1.0,
  400. 'cal' => 9.99330315287563E-01,
  401. 'eV' => 2.61142000000000E+19,
  402. 'ev' => 2.61142000000000E+19,
  403. 'HPh' => 1.55856355899327E-06,
  404. 'hh' => 1.55856355899327E-06,
  405. 'Wh' => 1.16222030532950E-03,
  406. 'wh' => 1.16222030532950E-03,
  407. 'flb' => 9.92878733152102E+01,
  408. 'BTU' => 3.96564972437776E-03,
  409. 'btu' => 3.96564972437776E-03,
  410. ),
  411. 'cal' => array(
  412. 'J' => 4.18679484613929E+00,
  413. 'e' => 4.18679283372801E+07,
  414. 'c' => 1.00067013349059E+00,
  415. 'cal' => 1.0,
  416. 'eV' => 2.61317000000000E+19,
  417. 'ev' => 2.61317000000000E+19,
  418. 'HPh' => 1.55960800463137E-06,
  419. 'hh' => 1.55960800463137E-06,
  420. 'Wh' => 1.16299914807955E-03,
  421. 'wh' => 1.16299914807955E-03,
  422. 'flb' => 9.93544094443283E+01,
  423. 'BTU' => 3.96830723907002E-03,
  424. 'btu' => 3.96830723907002E-03,
  425. ),
  426. 'eV' => array(
  427. 'J' => 1.60219000146921E-19,
  428. 'e' => 1.60218923136574E-12,
  429. 'c' => 3.82933423195043E-20,
  430. 'cal' => 3.82676978535648E-20,
  431. 'eV' => 1.0,
  432. 'ev' => 1.0,
  433. 'HPh' => 5.96826078912344E-26,
  434. 'hh' => 5.96826078912344E-26,
  435. 'Wh' => 4.45053000026614E-23,
  436. 'wh' => 4.45053000026614E-23,
  437. 'flb' => 3.80206452103492E-18,
  438. 'BTU' => 1.51857982414846E-22,
  439. 'btu' => 1.51857982414846E-22,
  440. ),
  441. 'ev' => array(
  442. 'J' => 1.60219000146921E-19,
  443. 'e' => 1.60218923136574E-12,
  444. 'c' => 3.82933423195043E-20,
  445. 'cal' => 3.82676978535648E-20,
  446. 'eV' => 1.0,
  447. 'ev' => 1.0,
  448. 'HPh' => 5.96826078912344E-26,
  449. 'hh' => 5.96826078912344E-26,
  450. 'Wh' => 4.45053000026614E-23,
  451. 'wh' => 4.45053000026614E-23,
  452. 'flb' => 3.80206452103492E-18,
  453. 'BTU' => 1.51857982414846E-22,
  454. 'btu' => 1.51857982414846E-22,
  455. ),
  456. 'HPh' => array(
  457. 'J' => 2.68451741316170E+06,
  458. 'e' => 2.68451612283024E+13,
  459. 'c' => 6.41616438565991E+05,
  460. 'cal' => 6.41186757845835E+05,
  461. 'eV' => 1.67553000000000E+25,
  462. 'ev' => 1.67553000000000E+25,
  463. 'HPh' => 1.0,
  464. 'hh' => 1.0,
  465. 'Wh' => 7.45699653134593E+02,
  466. 'wh' => 7.45699653134593E+02,
  467. 'flb' => 6.37047316692964E+07,
  468. 'BTU' => 2.54442605275546E+03,
  469. 'btu' => 2.54442605275546E+03,
  470. ),
  471. 'hh' => array(
  472. 'J' => 2.68451741316170E+06,
  473. 'e' => 2.68451612283024E+13,
  474. 'c' => 6.41616438565991E+05,
  475. 'cal' => 6.41186757845835E+05,
  476. 'eV' => 1.67553000000000E+25,
  477. 'ev' => 1.67553000000000E+25,
  478. 'HPh' => 1.0,
  479. 'hh' => 1.0,
  480. 'Wh' => 7.45699653134593E+02,
  481. 'wh' => 7.45699653134593E+02,
  482. 'flb' => 6.37047316692964E+07,
  483. 'BTU' => 2.54442605275546E+03,
  484. 'btu' => 2.54442605275546E+03,
  485. ),
  486. 'Wh' => array(
  487. 'J' => 3.59999820554720E+03,
  488. 'e' => 3.59999647518369E+10,
  489. 'c' => 8.60422069219046E+02,
  490. 'cal' => 8.59845857713046E+02,
  491. 'eV' => 2.24692340000000E+22,
  492. 'ev' => 2.24692340000000E+22,
  493. 'HPh' => 1.34102248243839E-03,
  494. 'hh' => 1.34102248243839E-03,
  495. 'Wh' => 1.0,
  496. 'wh' => 1.0,
  497. 'flb' => 8.54294774062316E+04,
  498. 'BTU' => 3.41213254164705E+00,
  499. 'btu' => 3.41213254164705E+00,
  500. ),
  501. 'wh' => array(
  502. 'J' => 3.59999820554720E+03,
  503. 'e' => 3.59999647518369E+10,
  504. 'c' => 8.60422069219046E+02,
  505. 'cal' => 8.59845857713046E+02,
  506. 'eV' => 2.24692340000000E+22,
  507. 'ev' => 2.24692340000000E+22,
  508. 'HPh' => 1.34102248243839E-03,
  509. 'hh' => 1.34102248243839E-03,
  510. 'Wh' => 1.0,
  511. 'wh' => 1.0,
  512. 'flb' => 8.54294774062316E+04,
  513. 'BTU' => 3.41213254164705E+00,
  514. 'btu' => 3.41213254164705E+00,
  515. ),
  516. 'flb' => array(
  517. 'J' => 4.21400003236424E-02,
  518. 'e' => 4.21399800687660E+05,
  519. 'c' => 1.00717234301644E-02,
  520. 'cal' => 1.00649785509554E-02,
  521. 'eV' => 2.63015000000000E+17,
  522. 'ev' => 2.63015000000000E+17,
  523. 'HPh' => 1.56974211145130E-08,
  524. 'hh' => 1.56974211145130E-08,
  525. 'Wh' => 1.17055614802000E-05,
  526. 'wh' => 1.17055614802000E-05,
  527. 'flb' => 1.0,
  528. 'BTU' => 3.99409272448406E-05,
  529. 'btu' => 3.99409272448406E-05,
  530. ),
  531. 'BTU' => array(
  532. 'J' => 1.05505813786749E+03,
  533. 'e' => 1.05505763074665E+10,
  534. 'c' => 2.52165488508168E+02,
  535. 'cal' => 2.51996617135510E+02,
  536. 'eV' => 6.58510000000000E+21,
  537. 'ev' => 6.58510000000000E+21,
  538. 'HPh' => 3.93015941224568E-04,
  539. 'hh' => 3.93015941224568E-04,
  540. 'Wh' => 2.93071851047526E-01,
  541. 'wh' => 2.93071851047526E-01,
  542. 'flb' => 2.50369750774671E+04,
  543. 'BTU' => 1.0,
  544. 'btu' => 1.0,
  545. ),
  546. 'btu' => array(
  547. 'J' => 1.05505813786749E+03,
  548. 'e' => 1.05505763074665E+10,
  549. 'c' => 2.52165488508168E+02,
  550. 'cal' => 2.51996617135510E+02,
  551. 'eV' => 6.58510000000000E+21,
  552. 'ev' => 6.58510000000000E+21,
  553. 'HPh' => 3.93015941224568E-04,
  554. 'hh' => 3.93015941224568E-04,
  555. 'Wh' => 2.93071851047526E-01,
  556. 'wh' => 2.93071851047526E-01,
  557. 'flb' => 2.50369750774671E+04,
  558. 'BTU' => 1.0,
  559. 'btu' => 1.0,
  560. ),
  561. ),
  562. 'Power' => array(
  563. 'HP' => array(
  564. 'HP' => 1.0,
  565. 'h' => 1.0,
  566. 'W' => 7.45701000000000E+02,
  567. 'w' => 7.45701000000000E+02,
  568. ),
  569. 'h' => array(
  570. 'HP' => 1.0,
  571. 'h' => 1.0,
  572. 'W' => 7.45701000000000E+02,
  573. 'w' => 7.45701000000000E+02,
  574. ),
  575. 'W' => array(
  576. 'HP' => 1.34102006031908E-03,
  577. 'h' => 1.34102006031908E-03,
  578. 'W' => 1.0,
  579. 'w' => 1.0,
  580. ),
  581. 'w' => array(
  582. 'HP' => 1.34102006031908E-03,
  583. 'h' => 1.34102006031908E-03,
  584. 'W' => 1.0,
  585. 'w' => 1.0,
  586. ),
  587. ),
  588. 'Magnetism' => array(
  589. 'T' => array(
  590. 'T' => 1.0,
  591. 'ga' => 10000.0,
  592. ),
  593. 'ga' => array(
  594. 'T' => 0.0001,
  595. 'ga' => 1.0,
  596. ),
  597. ),
  598. 'Liquid' => array(
  599. 'tsp' => array(
  600. 'tsp' => 1.0,
  601. 'tbs' => 3.33333333333333E-01,
  602. 'oz' => 1.66666666666667E-01,
  603. 'cup' => 2.08333333333333E-02,
  604. 'pt' => 1.04166666666667E-02,
  605. 'us_pt' => 1.04166666666667E-02,
  606. 'uk_pt' => 8.67558516821960E-03,
  607. 'qt' => 5.20833333333333E-03,
  608. 'gal' => 1.30208333333333E-03,
  609. 'l' => 4.92999408400710E-03,
  610. 'lt' => 4.92999408400710E-03,
  611. ),
  612. 'tbs' => array(
  613. 'tsp' => 3.00000000000000E+00,
  614. 'tbs' => 1.0,
  615. 'oz' => 5.00000000000000E-01,
  616. 'cup' => 6.25000000000000E-02,
  617. 'pt' => 3.12500000000000E-02,
  618. 'us_pt' => 3.12500000000000E-02,
  619. 'uk_pt' => 2.60267555046588E-02,
  620. 'qt' => 1.56250000000000E-02,
  621. 'gal' => 3.90625000000000E-03,
  622. 'l' => 1.47899822520213E-02,
  623. 'lt' => 1.47899822520213E-02,
  624. ),
  625. 'oz' => array(
  626. 'tsp' => 6.00000000000000E+00,
  627. 'tbs' => 2.00000000000000E+00,
  628. 'oz' => 1.0,
  629. 'cup' => 1.25000000000000E-01,
  630. 'pt' => 6.25000000000000E-02,
  631. 'us_pt' => 6.25000000000000E-02,
  632. 'uk_pt' => 5.20535110093176E-02,
  633. 'qt' => 3.12500000000000E-02,
  634. 'gal' => 7.81250000000000E-03,
  635. 'l' => 2.95799645040426E-02,
  636. 'lt' => 2.95799645040426E-02,
  637. ),
  638. 'cup' => array(
  639. 'tsp' => 4.80000000000000E+01,
  640. 'tbs' => 1.60000000000000E+01,
  641. 'oz' => 8.00000000000000E+00,
  642. 'cup' => 1.0,
  643. 'pt' => 5.00000000000000E-01,
  644. 'us_pt' => 5.00000000000000E-01,
  645. 'uk_pt' => 4.16428088074541E-01,
  646. 'qt' => 2.50000000000000E-01,
  647. 'gal' => 6.25000000000000E-02,
  648. 'l' => 2.36639716032341E-01,
  649. 'lt' => 2.36639716032341E-01,
  650. ),
  651. 'pt' => array(
  652. 'tsp' => 9.60000000000000E+01,
  653. 'tbs' => 3.20000000000000E+01,
  654. 'oz' => 1.60000000000000E+01,
  655. 'cup' => 2.00000000000000E+00,
  656. 'pt' => 1.0,
  657. 'us_pt' => 1.0,
  658. 'uk_pt' => 8.32856176149081E-01,
  659. 'qt' => 5.00000000000000E-01,
  660. 'gal' => 1.25000000000000E-01,
  661. 'l' => 4.73279432064682E-01,
  662. 'lt' => 4.73279432064682E-01,
  663. ),
  664. 'us_pt' => array(
  665. 'tsp' => 9.60000000000000E+01,
  666. 'tbs' => 3.20000000000000E+01,
  667. 'oz' => 1.60000000000000E+01,
  668. 'cup' => 2.00000000000000E+00,
  669. 'pt' => 1.0,
  670. 'us_pt' => 1.0,
  671. 'uk_pt' => 8.32856176149081E-01,
  672. 'qt' => 5.00000000000000E-01,
  673. 'gal' => 1.25000000000000E-01,
  674. 'l' => 4.73279432064682E-01,
  675. 'lt' => 4.73279432064682E-01,
  676. ),
  677. 'uk_pt' => array(
  678. 'tsp' => 1.15266000000000E+02,
  679. 'tbs' => 3.84220000000000E+01,
  680. 'oz' => 1.92110000000000E+01,
  681. 'cup' => 2.40137500000000E+00,
  682. 'pt' => 1.20068750000000E+00,
  683. 'us_pt' => 1.20068750000000E+00,
  684. 'uk_pt' => 1.0,
  685. 'qt' => 6.00343750000000E-01,
  686. 'gal' => 1.50085937500000E-01,
  687. 'l' => 5.68260698087162E-01,
  688. 'lt' => 5.68260698087162E-01,
  689. ),
  690. 'qt' => array(
  691. 'tsp' => 1.92000000000000E+02,
  692. 'tbs' => 6.40000000000000E+01,
  693. 'oz' => 3.20000000000000E+01,
  694. 'cup' => 4.00000000000000E+00,
  695. 'pt' => 2.00000000000000E+00,
  696. 'us_pt' => 2.00000000000000E+00,
  697. 'uk_pt' => 1.66571235229816E+00,
  698. 'qt' => 1.0,
  699. 'gal' => 2.50000000000000E-01,
  700. 'l' => 9.46558864129363E-01,
  701. 'lt' => 9.46558864129363E-01,
  702. ),
  703. 'gal' => array(
  704. 'tsp' => 7.68000000000000E+02,
  705. 'tbs' => 2.56000000000000E+02,
  706. 'oz' => 1.28000000000000E+02,
  707. 'cup' => 1.60000000000000E+01,
  708. 'pt' => 8.00000000000000E+00,
  709. 'us_pt' => 8.00000000000000E+00,
  710. 'uk_pt' => 6.66284940919265E+00,
  711. 'qt' => 4.00000000000000E+00,
  712. 'gal' => 1.0,
  713. 'l' => 3.78623545651745E+00,
  714. 'lt' => 3.78623545651745E+00,
  715. ),
  716. 'l' => array(
  717. 'tsp' => 2.02840000000000E+02,
  718. 'tbs' => 6.76133333333333E+01,
  719. 'oz' => 3.38066666666667E+01,
  720. 'cup' => 4.22583333333333E+00,
  721. 'pt' => 2.11291666666667E+00,
  722. 'us_pt' => 2.11291666666667E+00,
  723. 'uk_pt' => 1.75975569552166E+00,
  724. 'qt' => 1.05645833333333E+00,
  725. 'gal' => 2.64114583333333E-01,
  726. 'l' => 1.0,
  727. 'lt' => 1.0,
  728. ),
  729. 'lt' => array(
  730. 'tsp' => 2.02840000000000E+02,
  731. 'tbs' => 6.76133333333333E+01,
  732. 'oz' => 3.38066666666667E+01,
  733. 'cup' => 4.22583333333333E+00,
  734. 'pt' => 2.11291666666667E+00,
  735. 'us_pt' => 2.11291666666667E+00,
  736. 'uk_pt' => 1.75975569552166E+00,
  737. 'qt' => 1.05645833333333E+00,
  738. 'gal' => 2.64114583333333E-01,
  739. 'l' => 1.0,
  740. 'lt' => 1.0,
  741. ),
  742. ),
  743. );
  744. /**
  745. * parseComplex
  746. *
  747. * Parses a complex number into its real and imaginary parts, and an I or J suffix
  748. *
  749. * @param string $complexNumber The complex number
  750. * @return string[] Indexed on "real", "imaginary" and "suffix"
  751. */
  752. public static function parseComplex($complexNumber)
  753. {
  754. $workString = (string) $complexNumber;
  755. $realNumber = $imaginary = 0;
  756. // Extract the suffix, if there is one
  757. $suffix = substr($workString, -1);
  758. if (!is_numeric($suffix)) {
  759. $workString = substr($workString, 0, -1);
  760. } else {
  761. $suffix = '';
  762. }
  763. // Split the input into its Real and Imaginary components
  764. $leadingSign = 0;
  765. if (strlen($workString) > 0) {
  766. $leadingSign = (($workString{0} == '+') || ($workString{0} == '-')) ? 1 : 0;
  767. }
  768. $power = '';
  769. $realNumber = strtok($workString, '+-');
  770. if (strtoupper(substr($realNumber, -1)) == 'E') {
  771. $power = strtok('+-');
  772. ++$leadingSign;
  773. }
  774. $realNumber = substr($workString, 0, strlen($realNumber)+strlen($power)+$leadingSign);
  775. if ($suffix != '') {
  776. $imaginary = substr($workString, strlen($realNumber));
  777. if (($imaginary == '') && (($realNumber == '') || ($realNumber == '+') || ($realNumber == '-'))) {
  778. $imaginary = $realNumber.'1';
  779. $realNumber = '0';
  780. } elseif ($imaginary == '') {
  781. $imaginary = $realNumber;
  782. $realNumber = '0';
  783. } elseif (($imaginary == '+') || ($imaginary == '-')) {
  784. $imaginary .= '1';
  785. }
  786. }
  787. return array(
  788. 'real' => $realNumber,
  789. 'imaginary' => $imaginary,
  790. 'suffix' => $suffix
  791. );
  792. }
  793. /**
  794. * Cleans the leading characters in a complex number string
  795. *
  796. * @param string $complexNumber The complex number to clean
  797. * @return string The "cleaned" complex number
  798. */
  799. private static function cleanComplex($complexNumber)
  800. {
  801. if ($complexNumber{0} == '+') {
  802. $complexNumber = substr($complexNumber, 1);
  803. }
  804. if ($complexNumber{0} == '0') {
  805. $complexNumber = substr($complexNumber, 1);
  806. }
  807. if ($complexNumber{0} == '.') {
  808. $complexNumber = '0'.$complexNumber;
  809. }
  810. if ($complexNumber{0} == '+') {
  811. $complexNumber = substr($complexNumber, 1);
  812. }
  813. return $complexNumber;
  814. }
  815. /**
  816. * Formats a number base string value with leading zeroes
  817. *
  818. * @param string $xVal The "number" to pad
  819. * @param integer $places The length that we want to pad this value
  820. * @return string The padded "number"
  821. */
  822. private static function nbrConversionFormat($xVal, $places)
  823. {
  824. if (!is_null($places)) {
  825. if (strlen($xVal) <= $places) {
  826. return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10);
  827. } else {
  828. return PHPExcel_Calculation_Functions::NaN();
  829. }
  830. }
  831. return substr($xVal, -10);
  832. }
  833. /**
  834. * BESSELI
  835. *
  836. * Returns the modified Bessel function In(x), which is equivalent to the Bessel function evaluated
  837. * for purely imaginary arguments
  838. *
  839. * Excel Function:
  840. * BESSELI(x,ord)
  841. *
  842. * @access public
  843. * @category Engineering Functions
  844. * @param float $x The value at which to evaluate the function.
  845. * If x is nonnumeric, BESSELI returns the #VALUE! error value.
  846. * @param integer $ord The order of the Bessel function.
  847. * If ord is not an integer, it is truncated.
  848. * If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
  849. * If $ord < 0, BESSELI returns the #NUM! error value.
  850. * @return float
  851. *
  852. */
  853. public static function BESSELI($x, $ord)
  854. {
  855. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  856. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  857. if ((is_numeric($x)) && (is_numeric($ord))) {
  858. $ord = floor($ord);
  859. if ($ord < 0) {
  860. return PHPExcel_Calculation_Functions::NaN();
  861. }
  862. if (abs($x) <= 30) {
  863. $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
  864. $ordK = 1;
  865. $fSqrX = ($x * $x) / 4;
  866. do {
  867. $fTerm *= $fSqrX;
  868. $fTerm /= ($ordK * ($ordK + $ord));
  869. $fResult += $fTerm;
  870. } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
  871. } else {
  872. $f_2_PI = 2 * M_PI;
  873. $fXAbs = abs($x);
  874. $fResult = exp($fXAbs) / sqrt($f_2_PI * $fXAbs);
  875. if (($ord & 1) && ($x < 0)) {
  876. $fResult = -$fResult;
  877. }
  878. }
  879. return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
  880. }
  881. return PHPExcel_Calculation_Functions::VALUE();
  882. }
  883. /**
  884. * BESSELJ
  885. *
  886. * Returns the Bessel function
  887. *
  888. * Excel Function:
  889. * BESSELJ(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, BESSELJ 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, BESSELJ returns the #VALUE! error value.
  897. * If $ord < 0, BESSELJ returns the #NUM! error value.
  898. * @return float
  899. *
  900. */
  901. public static function BESSELJ($x, $ord)
  902. {
  903. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  904. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  905. if ((is_numeric($x)) && (is_numeric($ord))) {
  906. $ord = floor($ord);
  907. if ($ord < 0) {
  908. return PHPExcel_Calculation_Functions::NaN();
  909. }
  910. $fResult = 0;
  911. if (abs($x) <= 30) {
  912. $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
  913. $ordK = 1;
  914. $fSqrX = ($x * $x) / -4;
  915. do {
  916. $fTerm *= $fSqrX;
  917. $fTerm /= ($ordK * ($ordK + $ord));
  918. $fResult += $fTerm;
  919. } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
  920. } else {
  921. $f_PI_DIV_2 = M_PI / 2;
  922. $f_PI_DIV_4 = M_PI / 4;
  923. $fXAbs = abs($x);
  924. $fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4);
  925. if (($ord & 1) && ($x < 0)) {
  926. $fResult = -$fResult;
  927. }
  928. }
  929. return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
  930. }
  931. return PHPExcel_Calculation_Functions::VALUE();
  932. }
  933. private static function besselK0($fNum)
  934. {
  935. if ($fNum <= 2) {
  936. $fNum2 = $fNum * 0.5;
  937. $y = ($fNum2 * $fNum2);
  938. $fRet = -log($fNum2) * self::BESSELI($fNum, 0) +
  939. (-0.57721566 + $y * (0.42278420 + $y * (0.23069756 + $y * (0.3488590e-1 + $y * (0.262698e-2 + $y *
  940. (0.10750e-3 + $y * 0.74e-5))))));
  941. } else {
  942. $y = 2 / $fNum;
  943. $fRet = exp(-$fNum) / sqrt($fNum) *
  944. (1.25331414 + $y * (-0.7832358e-1 + $y * (0.2189568e-1 + $y * (-0.1062446e-1 + $y *
  945. (0.587872e-2 + $y * (-0.251540e-2 + $y * 0.53208e-3))))));
  946. }
  947. return $fRet;
  948. }
  949. private static function besselK1($fNum)
  950. {
  951. if ($fNum <= 2) {
  952. $fNum2 = $fNum * 0.5;
  953. $y = ($fNum2 * $fNum2);
  954. $fRet = log($fNum2) * self::BESSELI($fNum, 1) +
  955. (1 + $y * (0.15443144 + $y * (-0.67278579 + $y * (-0.18156897 + $y * (-0.1919402e-1 + $y *
  956. (-0.110404e-2 + $y * (-0.4686e-4))))))) / $fNum;
  957. } else {
  958. $y = 2 / $fNum;
  959. $fRet = exp(-$fNum) / sqrt($fNum) *
  960. (1.25331414 + $y * (0.23498619 + $y * (-0.3655620e-1 + $y * (0.1504268e-1 + $y * (-0.780353e-2 + $y *
  961. (0.325614e-2 + $y * (-0.68245e-3)))))));
  962. }
  963. return $fRet;
  964. }
  965. /**
  966. * BESSELK
  967. *
  968. * Returns the modified Bessel function Kn(x), which is equivalent to the Bessel functions evaluated
  969. * for purely imaginary arguments.
  970. *
  971. * Excel Function:
  972. * BESSELK(x,ord)
  973. *
  974. * @access public
  975. * @category Engineering Functions
  976. * @param float $x The value at which to evaluate the function.
  977. * If x is nonnumeric, BESSELK returns the #VALUE! error value.
  978. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  979. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
  980. * If $ord < 0, BESSELK returns the #NUM! error value.
  981. * @return float
  982. *
  983. */
  984. public static function BESSELK($x, $ord)
  985. {
  986. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  987. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  988. if ((is_numeric($x)) && (is_numeric($ord))) {
  989. if (($ord < 0) || ($x == 0.0)) {
  990. return PHPExcel_Calculation_Functions::NaN();
  991. }
  992. switch (floor($ord)) {
  993. case 0:
  994. return self::besselK0($x);
  995. case 1:
  996. return self::besselK1($x);
  997. default:
  998. $fTox = 2 / $x;
  999. $fBkm = self::besselK0($x);
  1000. $fBk = self::besselK1($x);
  1001. for ($n = 1; $n < $ord; ++$n) {
  1002. $fBkp = $fBkm + $n * $fTox * $fBk;
  1003. $fBkm = $fBk;
  1004. $fBk = $fBkp;
  1005. }
  1006. }
  1007. return (is_nan($fBk)) ? PHPExcel_Calculation_Functions::NaN() : $fBk;
  1008. }
  1009. return PHPExcel_Calculation_Functions::VALUE();
  1010. }
  1011. private static function besselY0($fNum)
  1012. {
  1013. if ($fNum < 8.0) {
  1014. $y = ($fNum * $fNum);
  1015. $f1 = -2957821389.0 + $y * (7062834065.0 + $y * (-512359803.6 + $y * (10879881.29 + $y * (-86327.92757 + $y * 228.4622733))));
  1016. $f2 = 40076544269.0 + $y * (745249964.8 + $y * (7189466.438 + $y * (47447.26470 + $y * (226.1030244 + $y))));
  1017. $fRet = $f1 / $f2 + 0.636619772 * self::BESSELJ($fNum, 0) * log($fNum);
  1018. } else {
  1019. $z = 8.0 / $fNum;
  1020. $y = ($z * $z);
  1021. $xx = $fNum - 0.785398164;
  1022. $f1 = 1 + $y * (-0.1098628627e-2 + $y * (0.2734510407e-4 + $y * (-0.2073370639e-5 + $y * 0.2093887211e-6)));
  1023. $f2 = -0.1562499995e-1 + $y * (0.1430488765e-3 + $y * (-0.6911147651e-5 + $y * (0.7621095161e-6 + $y * (-0.934945152e-7))));
  1024. $fRet = sqrt(0.636619772 / $fNum) * (sin($xx) * $f1 + $z * cos($xx) * $f2);
  1025. }
  1026. return $fRet;
  1027. }
  1028. private static function besselY1($fNum)
  1029. {
  1030. if ($fNum < 8.0) {
  1031. $y = ($fNum * $fNum);
  1032. $f1 = $fNum * (-0.4900604943e13 + $y * (0.1275274390e13 + $y * (-0.5153438139e11 + $y * (0.7349264551e9 + $y *
  1033. (-0.4237922726e7 + $y * 0.8511937935e4)))));
  1034. $f2 = 0.2499580570e14 + $y * (0.4244419664e12 + $y * (0.3733650367e10 + $y * (0.2245904002e8 + $y *
  1035. (0.1020426050e6 + $y * (0.3549632885e3 + $y)))));
  1036. $fRet = $f1 / $f2 + 0.636619772 * ( self::BESSELJ($fNum, 1) * log($fNum) - 1 / $fNum);
  1037. } else {
  1038. $fRet = sqrt(0.636619772 / $fNum) * sin($fNum - 2.356194491);
  1039. }
  1040. return $fRet;
  1041. }
  1042. /**
  1043. * BESSELY
  1044. *
  1045. * Returns the Bessel function, which is also called the Weber function or the Neumann function.
  1046. *
  1047. * Excel Function:
  1048. * BESSELY(x,ord)
  1049. *
  1050. * @access public
  1051. * @category Engineering Functions
  1052. * @param float $x The value at which to evaluate the function.
  1053. * If x is nonnumeric, BESSELK returns the #VALUE! error value.
  1054. * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
  1055. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
  1056. * If $ord < 0, BESSELK returns the #NUM! error value.
  1057. *
  1058. * @return float
  1059. */
  1060. public static function BESSELY($x, $ord)
  1061. {
  1062. $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1063. $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
  1064. if ((is_numeric($x)) && (is_numeric($ord))) {
  1065. if (($ord < 0) || ($x == 0.0)) {
  1066. return PHPExcel_Calculation_Functions::NaN();
  1067. }
  1068. switch (floor($ord)) {
  1069. case 0:
  1070. return self::besselY0($x);
  1071. case 1:
  1072. return self::besselY1($x);
  1073. default:
  1074. $fTox = 2 / $x;
  1075. $fBym = self::besselY0($x);
  1076. $fBy = self::besselY1($x);
  1077. for ($n = 1; $n < $ord; ++$n) {
  1078. $fByp = $n * $fTox * $fBy - $fBym;
  1079. $fBym = $fBy;
  1080. $fBy = $fByp;
  1081. }
  1082. }
  1083. return (is_nan($fBy)) ? PHPExcel_Calculation_Functions::NaN() : $fBy;
  1084. }
  1085. return PHPExcel_Calculation_Functions::VALUE();
  1086. }
  1087. /**
  1088. * BINTODEC
  1089. *
  1090. * Return a binary value as decimal.
  1091. *
  1092. * Excel Function:
  1093. * BIN2DEC(x)
  1094. *
  1095. * @access public
  1096. * @category Engineering Functions
  1097. * @param string $x The binary number (as a string) that you want to convert. The number
  1098. * cannot contain more than 10 characters (10 bits). The most significant
  1099. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
  1100. * Negative numbers are represented using two's-complement notation.
  1101. * If number is not a valid binary number, or if number contains more than
  1102. * 10 characters (10 bits), BIN2DEC returns the #NUM! error value.
  1103. * @return string
  1104. */
  1105. public static function BINTODEC($x)
  1106. {
  1107. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1108. if (is_bool($x)) {
  1109. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1110. $x = (int) $x;
  1111. } else {
  1112. return PHPExcel_Calculation_Functions::VALUE();
  1113. }
  1114. }
  1115. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  1116. $x = floor($x);
  1117. }
  1118. $x = (string) $x;
  1119. if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
  1120. return PHPExcel_Calculation_Functions::NaN();
  1121. }
  1122. if (strlen($x) > 10) {
  1123. return PHPExcel_Calculation_Functions::NaN();
  1124. } elseif (strlen($x) == 10) {
  1125. // Two's Complement
  1126. $x = substr($x, -9);
  1127. return '-'.(512-bindec($x));
  1128. }
  1129. return bindec($x);
  1130. }
  1131. /**
  1132. * BINTOHEX
  1133. *
  1134. * Return a binary value as hex.
  1135. *
  1136. * Excel Function:
  1137. * BIN2HEX(x[,places])
  1138. *
  1139. * @access public
  1140. * @category Engineering Functions
  1141. * @param string $x The binary number (as a string) that you want to convert. The number
  1142. * cannot contain more than 10 characters (10 bits). The most significant
  1143. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
  1144. * Negative numbers are represented using two's-complement notation.
  1145. * If number is not a valid binary number, or if number contains more than
  1146. * 10 characters (10 bits), BIN2HEX returns the #NUM! error value.
  1147. * @param integer $places The number of characters to use. If places is omitted, BIN2HEX uses the
  1148. * minimum number of characters necessary. Places is useful for padding the
  1149. * return value with leading 0s (zeros).
  1150. * If places is not an integer, it is truncated.
  1151. * If places is nonnumeric, BIN2HEX returns the #VALUE! error value.
  1152. * If places is negative, BIN2HEX returns the #NUM! error value.
  1153. * @return string
  1154. */
  1155. public static function BINTOHEX($x, $places = null)
  1156. {
  1157. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1158. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1159. if (is_bool($x)) {
  1160. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1161. $x = (int) $x;
  1162. } else {
  1163. return PHPExcel_Calculation_Functions::VALUE();
  1164. }
  1165. }
  1166. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  1167. $x = floor($x);
  1168. }
  1169. $x = (string) $x;
  1170. if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
  1171. return PHPExcel_Calculation_Functions::NaN();
  1172. }
  1173. if (strlen($x) > 10) {
  1174. return PHPExcel_Calculation_Functions::NaN();
  1175. } elseif (strlen($x) == 10) {
  1176. // Two's Complement
  1177. return str_repeat('F', 8).substr(strtoupper(dechex(bindec(substr($x, -9)))), -2);
  1178. }
  1179. $hexVal = (string) strtoupper(dechex(bindec($x)));
  1180. return self::nbrConversionFormat($hexVal, $places);
  1181. }
  1182. /**
  1183. * BINTOOCT
  1184. *
  1185. * Return a binary value as octal.
  1186. *
  1187. * Excel Function:
  1188. * BIN2OCT(x[,places])
  1189. *
  1190. * @access public
  1191. * @category Engineering Functions
  1192. * @param string $x The binary number (as a string) that you want to convert. The number
  1193. * cannot contain more than 10 characters (10 bits). The most significant
  1194. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
  1195. * Negative numbers are represented using two's-complement notation.
  1196. * If number is not a valid binary number, or if number contains more than
  1197. * 10 characters (10 bits), BIN2OCT returns the #NUM! error value.
  1198. * @param integer $places The number of characters to use. If places is omitted, BIN2OCT uses the
  1199. * minimum number of characters necessary. Places is useful for padding the
  1200. * return value with leading 0s (zeros).
  1201. * If places is not an integer, it is truncated.
  1202. * If places is nonnumeric, BIN2OCT returns the #VALUE! error value.
  1203. * If places is negative, BIN2OCT returns the #NUM! error value.
  1204. * @return string
  1205. */
  1206. public static function BINTOOCT($x, $places = null)
  1207. {
  1208. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1209. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1210. if (is_bool($x)) {
  1211. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1212. $x = (int) $x;
  1213. } else {
  1214. return PHPExcel_Calculation_Functions::VALUE();
  1215. }
  1216. }
  1217. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
  1218. $x = floor($x);
  1219. }
  1220. $x = (string) $x;
  1221. if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
  1222. return PHPExcel_Calculation_Functions::NaN();
  1223. }
  1224. if (strlen($x) > 10) {
  1225. return PHPExcel_Calculation_Functions::NaN();
  1226. } elseif (strlen($x) == 10) {
  1227. // Two's Complement
  1228. return str_repeat('7', 7).substr(strtoupper(decoct(bindec(substr($x, -9)))), -3);
  1229. }
  1230. $octVal = (string) decoct(bindec($x));
  1231. return self::nbrConversionFormat($octVal, $places);
  1232. }
  1233. /**
  1234. * DECTOBIN
  1235. *
  1236. * Return a decimal value as binary.
  1237. *
  1238. * Excel Function:
  1239. * DEC2BIN(x[,places])
  1240. *
  1241. * @access public
  1242. * @category Engineering Functions
  1243. * @param string $x The decimal integer you want to convert. If number is negative,
  1244. * valid place values are ignored and DEC2BIN returns a 10-character
  1245. * (10-bit) binary number in which the most significant bit is the sign
  1246. * bit. The remaining 9 bits are magnitude bits. Negative numbers are
  1247. * represented using two's-complement notation.
  1248. * If number < -512 or if number > 511, DEC2BIN returns the #NUM! error
  1249. * value.
  1250. * If number is nonnumeric, DEC2BIN returns the #VALUE! error value.
  1251. * If DEC2BIN requires more than places characters, it returns the #NUM!
  1252. * error value.
  1253. * @param integer $places The number of characters to use. If places is omitted, DEC2BIN uses
  1254. * the minimum number of characters necessary. Places is useful for
  1255. * padding the return value with leading 0s (zeros).
  1256. * If places is not an integer, it is truncated.
  1257. * If places is nonnumeric, DEC2BIN returns the #VALUE! error value.
  1258. * If places is zero or negative, DEC2BIN returns the #NUM! error value.
  1259. * @return string
  1260. */
  1261. public static function DECTOBIN($x, $places = null)
  1262. {
  1263. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1264. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1265. if (is_bool($x)) {
  1266. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1267. $x = (int) $x;
  1268. } else {
  1269. return PHPExcel_Calculation_Functions::VALUE();
  1270. }
  1271. }
  1272. $x = (string) $x;
  1273. if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) {
  1274. return PHPExcel_Calculation_Functions::VALUE();
  1275. }
  1276. $x = (string) floor($x);
  1277. $r = decbin($x);
  1278. if (strlen($r) == 32) {
  1279. // Two's Complement
  1280. $r = substr($r, -10);
  1281. } elseif (strlen($r) > 11) {
  1282. return PHPExcel_Calculation_Functions::NaN();
  1283. }
  1284. return self::nbrConversionFormat($r, $places);
  1285. }
  1286. /**
  1287. * DECTOHEX
  1288. *
  1289. * Return a decimal value as hex.
  1290. *
  1291. * Excel Function:
  1292. * DEC2HEX(x[,places])
  1293. *
  1294. * @access public
  1295. * @category Engineering Functions
  1296. * @param string $x The decimal integer you want to convert. If number is negative,
  1297. * places is ignored and DEC2HEX returns a 10-character (40-bit)
  1298. * hexadecimal number in which the most significant bit is the sign
  1299. * bit. The remaining 39 bits are magnitude bits. Negative numbers
  1300. * are represented using two's-complement notation.
  1301. * If number < -549,755,813,888 or if number > 549,755,813,887,
  1302. * DEC2HEX returns the #NUM! error value.
  1303. * If number is nonnumeric, DEC2HEX returns the #VALUE! error value.
  1304. * If DEC2HEX requires more than places characters, it returns the
  1305. * #NUM! error value.
  1306. * @param integer $places The number of characters to use. If places is omitted, DEC2HEX uses
  1307. * the minimum number of characters necessary. Places is useful for
  1308. * padding the return value with leading 0s (zeros).
  1309. * If places is not an integer, it is truncated.
  1310. * If places is nonnumeric, DEC2HEX returns the #VALUE! error value.
  1311. * If places is zero or negative, DEC2HEX returns the #NUM! error value.
  1312. * @return string
  1313. */
  1314. public static function DECTOHEX($x, $places = null)
  1315. {
  1316. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1317. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1318. if (is_bool($x)) {
  1319. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1320. $x = (int) $x;
  1321. } else {
  1322. return PHPExcel_Calculation_Functions::VALUE();
  1323. }
  1324. }
  1325. $x = (string) $x;
  1326. if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) {
  1327. return PHPExcel_Calculation_Functions::VALUE();
  1328. }
  1329. $x = (string) floor($x);
  1330. $r = strtoupper(dechex($x));
  1331. if (strlen($r) == 8) {
  1332. // Two's Complement
  1333. $r = 'FF'.$r;
  1334. }
  1335. return self::nbrConversionFormat($r, $places);
  1336. }
  1337. /**
  1338. * DECTOOCT
  1339. *
  1340. * Return an decimal value as octal.
  1341. *
  1342. * Excel Function:
  1343. * DEC2OCT(x[,places])
  1344. *
  1345. * @access public
  1346. * @category Engineering Functions
  1347. * @param string $x The decimal integer you want to convert. If number is negative,
  1348. * places is ignored and DEC2OCT returns a 10-character (30-bit)
  1349. * octal number in which the most significant bit is the sign bit.
  1350. * The remaining 29 bits are magnitude bits. Negative numbers are
  1351. * represented using two's-complement notation.
  1352. * If number < -536,870,912 or if number > 536,870,911, DEC2OCT
  1353. * returns the #NUM! error value.
  1354. * If number is nonnumeric, DEC2OCT returns the #VALUE! error value.
  1355. * If DEC2OCT requires more than places characters, it returns the
  1356. * #NUM! error value.
  1357. * @param integer $places The number of characters to use. If places is omitted, DEC2OCT uses
  1358. * the minimum number of characters necessary. Places is useful for
  1359. * padding the return value with leading 0s (zeros).
  1360. * If places is not an integer, it is truncated.
  1361. * If places is nonnumeric, DEC2OCT returns the #VALUE! error value.
  1362. * If places is zero or negative, DEC2OCT returns the #NUM! error value.
  1363. * @return string
  1364. */
  1365. public static function DECTOOCT($x, $places = null)
  1366. {
  1367. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1368. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1369. if (is_bool($x)) {
  1370. if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
  1371. $x = (int) $x;
  1372. } else {
  1373. return PHPExcel_Calculation_Functions::VALUE();
  1374. }
  1375. }
  1376. $x = (string) $x;
  1377. if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) {
  1378. return PHPExcel_Calculation_Functions::VALUE();
  1379. }
  1380. $x = (string) floor($x);
  1381. $r = decoct($x);
  1382. if (strlen($r) == 11) {
  1383. // Two's Complement
  1384. $r = substr($r, -10);
  1385. }
  1386. return self::nbrConversionFormat($r, $places);
  1387. }
  1388. /**
  1389. * HEXTOBIN
  1390. *
  1391. * Return a hex value as binary.
  1392. *
  1393. * Excel Function:
  1394. * HEX2BIN(x[,places])
  1395. *
  1396. * @access public
  1397. * @category Engineering Functions
  1398. * @param string $x the hexadecimal number you want to convert. Number cannot
  1399. * contain more than 10 characters. The most significant bit of
  1400. * number is the sign bit (40th bit from the right). The remaining
  1401. * 9 bits are magnitude bits. Negative numbers are represented
  1402. * using two's-complement notation.
  1403. * If number is negative, HEX2BIN ignores places and returns a
  1404. * 10-character binary number.
  1405. * If number is negative, it cannot be less than FFFFFFFE00, and
  1406. * if number is positive, it cannot be greater than 1FF.
  1407. * If number is not a valid hexadecimal number, HEX2BIN returns
  1408. * the #NUM! error value.
  1409. * If HEX2BIN requires more than places characters, it returns
  1410. * the #NUM! error value.
  1411. * @param integer $places The number of characters to use. If places is omitted,
  1412. * HEX2BIN uses the minimum number of characters necessary. Places
  1413. * is useful for padding the return value with leading 0s (zeros).
  1414. * If places is not an integer, it is truncated.
  1415. * If places is nonnumeric, HEX2BIN returns the #VALUE! error value.
  1416. * If places is negative, HEX2BIN returns the #NUM! error value.
  1417. * @return string
  1418. */
  1419. public static function HEXTOBIN($x, $places = null)
  1420. {
  1421. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1422. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1423. if (is_bool($x)) {
  1424. return PHPExcel_Calculation_Functions::VALUE();
  1425. }
  1426. $x = (string) $x;
  1427. if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) {
  1428. return PHPExcel_Calculation_Functions::NaN();
  1429. }
  1430. $binVal = decbin(hexdec($x));
  1431. return substr(self::nbrConversionFormat($binVal, $places), -10);
  1432. }
  1433. /**
  1434. * HEXTODEC
  1435. *
  1436. * Return a hex value as decimal.
  1437. *
  1438. * Excel Function:
  1439. * HEX2DEC(x)
  1440. *
  1441. * @access public
  1442. * @category Engineering Functions
  1443. * @param string $x The hexadecimal number you want to convert. This number cannot
  1444. * contain more than 10 characters (40 bits). The most significant
  1445. * bit of number is the sign bit. The remaining 39 bits are magnitude
  1446. * bits. Negative numbers are represented using two's-complement
  1447. * notation.
  1448. * If number is not a valid hexadecimal number, HEX2DEC returns the
  1449. * #NUM! error value.
  1450. * @return string
  1451. */
  1452. public static function HEXTODEC($x)
  1453. {
  1454. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1455. if (is_bool($x)) {
  1456. return PHPExcel_Calculation_Functions::VALUE();
  1457. }
  1458. $x = (string) $x;
  1459. if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) {
  1460. return PHPExcel_Calculation_Functions::NaN();
  1461. }
  1462. return hexdec($x);
  1463. }
  1464. /**
  1465. * HEXTOOCT
  1466. *
  1467. * Return a hex value as octal.
  1468. *
  1469. * Excel Function:
  1470. * HEX2OCT(x[,places])
  1471. *
  1472. * @access public
  1473. * @category Engineering Functions
  1474. * @param string $x The hexadecimal number you want to convert. Number cannot
  1475. * contain more than 10 characters. The most significant bit of
  1476. * number is the sign bit. The remaining 39 bits are magnitude
  1477. * bits. Negative numbers are represented using two's-complement
  1478. * notation.
  1479. * If number is negative, HEX2OCT ignores places and returns a
  1480. * 10-character octal number.
  1481. * If number is negative, it cannot be less than FFE0000000, and
  1482. * if number is positive, it cannot be greater than 1FFFFFFF.
  1483. * If number is not a valid hexadecimal number, HEX2OCT returns
  1484. * the #NUM! error value.
  1485. * If HEX2OCT requires more than places characters, it returns
  1486. * the #NUM! error value.
  1487. * @param integer $places The number of characters to use. If places is omitted, HEX2OCT
  1488. * uses the minimum number of characters necessary. Places is
  1489. * useful for padding the return value with leading 0s (zeros).
  1490. * If places is not an integer, it is truncated.
  1491. * If places is nonnumeric, HEX2OCT returns the #VALUE! error
  1492. * value.
  1493. * If places is negative, HEX2OCT returns the #NUM! error value.
  1494. * @return string
  1495. */
  1496. public static function HEXTOOCT($x, $places = null)
  1497. {
  1498. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1499. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1500. if (is_bool($x)) {
  1501. return PHPExcel_Calculation_Functions::VALUE();
  1502. }
  1503. $x = (string) $x;
  1504. if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) {
  1505. return PHPExcel_Calculation_Functions::NaN();
  1506. }
  1507. $octVal = decoct(hexdec($x));
  1508. return self::nbrConversionFormat($octVal, $places);
  1509. } // function HEXTOOCT()
  1510. /**
  1511. * OCTTOBIN
  1512. *
  1513. * Return an octal value as binary.
  1514. *
  1515. * Excel Function:
  1516. * OCT2BIN(x[,places])
  1517. *
  1518. * @access public
  1519. * @category Engineering Functions
  1520. * @param string $x The octal number you want to convert. Number may not
  1521. * contain more than 10 characters. The most significant
  1522. * bit of number is the sign bit. The remaining 29 bits
  1523. * are magnitude bits. Negative numbers are represented
  1524. * using two's-complement notation.
  1525. * If number is negative, OCT2BIN ignores places and returns
  1526. * a 10-character binary number.
  1527. * If number is negative, it cannot be less than 7777777000,
  1528. * and if number is positive, it cannot be greater than 777.
  1529. * If number is not a valid octal number, OCT2BIN returns
  1530. * the #NUM! error value.
  1531. * If OCT2BIN requires more than places characters, it
  1532. * returns the #NUM! error value.
  1533. * @param integer $places The number of characters to use. If places is omitted,
  1534. * OCT2BIN uses the minimum number of characters necessary.
  1535. * Places is useful for padding the return value with
  1536. * leading 0s (zeros).
  1537. * If places is not an integer, it is truncated.
  1538. * If places is nonnumeric, OCT2BIN returns the #VALUE!
  1539. * error value.
  1540. * If places is negative, OCT2BIN returns the #NUM! error
  1541. * value.
  1542. * @return string
  1543. */
  1544. public static function OCTTOBIN($x, $places = null)
  1545. {
  1546. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1547. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1548. if (is_bool($x)) {
  1549. return PHPExcel_Calculation_Functions::VALUE();
  1550. }
  1551. $x = (string) $x;
  1552. if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) {
  1553. return PHPExcel_Calculation_Functions::NaN();
  1554. }
  1555. $r = decbin(octdec($x));
  1556. return self::nbrConversionFormat($r, $places);
  1557. }
  1558. /**
  1559. * OCTTODEC
  1560. *
  1561. * Return an octal value as decimal.
  1562. *
  1563. * Excel Function:
  1564. * OCT2DEC(x)
  1565. *
  1566. * @access public
  1567. * @category Engineering Functions
  1568. * @param string $x The octal number you want to convert. Number may not contain
  1569. * more than 10 octal characters (30 bits). The most significant
  1570. * bit of number is the sign bit. The remaining 29 bits are
  1571. * magnitude bits. Negative numbers are represented using
  1572. * two's-complement notation.
  1573. * If number is not a valid octal number, OCT2DEC returns the
  1574. * #NUM! error value.
  1575. * @return string
  1576. */
  1577. public static function OCTTODEC($x)
  1578. {
  1579. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1580. if (is_bool($x)) {
  1581. return PHPExcel_Calculation_Functions::VALUE();
  1582. }
  1583. $x = (string) $x;
  1584. if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) {
  1585. return PHPExcel_Calculation_Functions::NaN();
  1586. }
  1587. return octdec($x);
  1588. }
  1589. /**
  1590. * OCTTOHEX
  1591. *
  1592. * Return an octal value as hex.
  1593. *
  1594. * Excel Function:
  1595. * OCT2HEX(x[,places])
  1596. *
  1597. * @access public
  1598. * @category Engineering Functions
  1599. * @param string $x The octal number you want to convert. Number may not contain
  1600. * more than 10 octal characters (30 bits). The most significant
  1601. * bit of number is the sign bit. The remaining 29 bits are
  1602. * magnitude bits. Negative numbers are represented using
  1603. * two's-complement notation.
  1604. * If number is negative, OCT2HEX ignores places and returns a
  1605. * 10-character hexadecimal number.
  1606. * If number is not a valid octal number, OCT2HEX returns the
  1607. * #NUM! error value.
  1608. * If OCT2HEX requires more than places characters, it returns
  1609. * the #NUM! error value.
  1610. * @param integer $places The number of characters to use. If places is omitted, OCT2HEX
  1611. * uses the minimum number of characters necessary. Places is useful
  1612. * for padding the return value with leading 0s (zeros).
  1613. * If places is not an integer, it is truncated.
  1614. * If places is nonnumeric, OCT2HEX returns the #VALUE! error value.
  1615. * If places is negative, OCT2HEX returns the #NUM! error value.
  1616. * @return string
  1617. */
  1618. public static function OCTTOHEX($x, $places = null)
  1619. {
  1620. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  1621. $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
  1622. if (is_bool($x)) {
  1623. return PHPExcel_Calculation_Functions::VALUE();
  1624. }
  1625. $x = (string) $x;
  1626. if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) {
  1627. return PHPExcel_Calculation_Functions::NaN();
  1628. }
  1629. $hexVal = strtoupper(dechex(octdec($x)));
  1630. return self::nbrConversionFormat($hexVal, $places);
  1631. }
  1632. /**
  1633. * COMPLEX
  1634. *
  1635. * Converts real and imaginary coefficients into a complex number of the form x + yi or x + yj.
  1636. *
  1637. * Excel Function:
  1638. * COMPLEX(realNumber,imaginary[,places])
  1639. *
  1640. * @access public
  1641. * @category Engineering Functions
  1642. * @param float $realNumber The real coefficient of the complex number.
  1643. * @param float $imaginary The imaginary coefficient of the complex number.
  1644. * @param string $suffix The suffix for the imaginary component of the complex number.
  1645. * If omitted, the suffix is assumed to be "i".
  1646. * @return string
  1647. */
  1648. public static function COMPLEX($realNumber = 0.0, $imaginary = 0.0, $suffix = 'i')
  1649. {
  1650. $realNumber = (is_null($realNumber)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
  1651. $imaginary = (is_null($imaginary)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($imaginary);
  1652. $suffix = (is_null($suffix)) ? 'i' : PHPExcel_Calculation_Functions::flattenSingleValue($suffix);
  1653. if (((is_numeric($realNumber)) && (is_numeric($imaginary))) &&
  1654. (($suffix == 'i') || ($suffix == 'j') || ($suffix == ''))) {
  1655. $realNumber = (float) $realNumber;
  1656. $imaginary = (float) $imaginary;
  1657. if ($suffix == '') {
  1658. $suffix = 'i';
  1659. }
  1660. if ($realNumber == 0.0) {
  1661. if ($imaginary == 0.0) {
  1662. return (string) '0';
  1663. } elseif ($imaginary == 1.0) {
  1664. return (string) $suffix;
  1665. } elseif ($imaginary == -1.0) {
  1666. return (string) '-'.$suffix;
  1667. }
  1668. return (string) $imaginary.$suffix;
  1669. } elseif ($imaginary == 0.0) {
  1670. return (string) $realNumber;
  1671. } elseif ($imaginary == 1.0) {
  1672. return (string) $realNumber.'+'.$suffix;
  1673. } elseif ($imaginary == -1.0) {
  1674. return (string) $realNumber.'-'.$suffix;
  1675. }
  1676. if ($imaginary > 0) {
  1677. $imaginary = (string) '+'.$imaginary;
  1678. }
  1679. return (string) $realNumber.$imaginary.$suffix;
  1680. }
  1681. return PHPExcel_Calculation_Functions::VALUE();
  1682. }
  1683. /**
  1684. * IMAGINARY
  1685. *
  1686. * Returns the imaginary coefficient of a complex number in x + yi or x + yj text format.
  1687. *
  1688. * Excel Function:
  1689. * IMAGINARY(complexNumber)
  1690. *
  1691. * @access public
  1692. * @category Engineering Functions
  1693. * @param string $complexNumber The complex number for which you want the imaginary
  1694. * coefficient.
  1695. * @return float
  1696. */
  1697. public static function IMAGINARY($complexNumber)
  1698. {
  1699. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1700. $parsedComplex = self::parseComplex($complexNumber);
  1701. return $parsedComplex['imaginary'];
  1702. }
  1703. /**
  1704. * IMREAL
  1705. *
  1706. * Returns the real coefficient of a complex number in x + yi or x + yj text format.
  1707. *
  1708. * Excel Function:
  1709. * IMREAL(complexNumber)
  1710. *
  1711. * @access public
  1712. * @category Engineering Functions
  1713. * @param string $complexNumber The complex number for which you want the real coefficient.
  1714. * @return float
  1715. */
  1716. public static function IMREAL($complexNumber)
  1717. {
  1718. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1719. $parsedComplex = self::parseComplex($complexNumber);
  1720. return $parsedComplex['real'];
  1721. }
  1722. /**
  1723. * IMABS
  1724. *
  1725. * Returns the absolute value (modulus) of a complex number in x + yi or x + yj text format.
  1726. *
  1727. * Excel Function:
  1728. * IMABS(complexNumber)
  1729. *
  1730. * @param string $complexNumber The complex number for which you want the absolute value.
  1731. * @return float
  1732. */
  1733. public static function IMABS($complexNumber)
  1734. {
  1735. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1736. $parsedComplex = self::parseComplex($complexNumber);
  1737. return sqrt(
  1738. ($parsedComplex['real'] * $parsedComplex['real']) +
  1739. ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])
  1740. );
  1741. }
  1742. /**
  1743. * IMARGUMENT
  1744. *
  1745. * Returns the argument theta of a complex number, i.e. the angle in radians from the real
  1746. * axis to the representation of the number in polar coordinates.
  1747. *
  1748. * Excel Function:
  1749. * IMARGUMENT(complexNumber)
  1750. *
  1751. * @param string $complexNumber The complex number for which you want the argument theta.
  1752. * @return float
  1753. */
  1754. public static function IMARGUMENT($complexNumber)
  1755. {
  1756. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1757. $parsedComplex = self::parseComplex($complexNumber);
  1758. if ($parsedComplex['real'] == 0.0) {
  1759. if ($parsedComplex['imaginary'] == 0.0) {
  1760. return 0.0;
  1761. } elseif ($parsedComplex['imaginary'] < 0.0) {
  1762. return M_PI / -2;
  1763. } else {
  1764. return M_PI / 2;
  1765. }
  1766. } elseif ($parsedComplex['real'] > 0.0) {
  1767. return atan($parsedComplex['imaginary'] / $parsedComplex['real']);
  1768. } elseif ($parsedComplex['imaginary'] < 0.0) {
  1769. return 0 - (M_PI - atan(abs($parsedComplex['imaginary']) / abs($parsedComplex['real'])));
  1770. } else {
  1771. return M_PI - atan($parsedComplex['imaginary'] / abs($parsedComplex['real']));
  1772. }
  1773. }
  1774. /**
  1775. * IMCONJUGATE
  1776. *
  1777. * Returns the complex conjugate of a complex number in x + yi or x + yj text format.
  1778. *
  1779. * Excel Function:
  1780. * IMCONJUGATE(complexNumber)
  1781. *
  1782. * @param string $complexNumber The complex number for which you want the conjugate.
  1783. * @return string
  1784. */
  1785. public static function IMCONJUGATE($complexNumber)
  1786. {
  1787. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1788. $parsedComplex = self::parseComplex($complexNumber);
  1789. if ($parsedComplex['imaginary'] == 0.0) {
  1790. return $parsedComplex['real'];
  1791. } else {
  1792. return self::cleanComplex(
  1793. self::COMPLEX(
  1794. $parsedComplex['real'],
  1795. 0 - $parsedComplex['imaginary'],
  1796. $parsedComplex['suffix']
  1797. )
  1798. );
  1799. }
  1800. }
  1801. /**
  1802. * IMCOS
  1803. *
  1804. * Returns the cosine of a complex number in x + yi or x + yj text format.
  1805. *
  1806. * Excel Function:
  1807. * IMCOS(complexNumber)
  1808. *
  1809. * @param string $complexNumber The complex number for which you want the cosine.
  1810. * @return string|float
  1811. */
  1812. public static function IMCOS($complexNumber)
  1813. {
  1814. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1815. $parsedComplex = self::parseComplex($complexNumber);
  1816. if ($parsedComplex['imaginary'] == 0.0) {
  1817. return cos($parsedComplex['real']);
  1818. } else {
  1819. return self::IMCONJUGATE(
  1820. self::COMPLEX(
  1821. cos($parsedComplex['real']) * cosh($parsedComplex['imaginary']),
  1822. sin($parsedComplex['real']) * sinh($parsedComplex['imaginary']),
  1823. $parsedComplex['suffix']
  1824. )
  1825. );
  1826. }
  1827. }
  1828. /**
  1829. * IMSIN
  1830. *
  1831. * Returns the sine of a complex number in x + yi or x + yj text format.
  1832. *
  1833. * Excel Function:
  1834. * IMSIN(complexNumber)
  1835. *
  1836. * @param string $complexNumber The complex number for which you want the sine.
  1837. * @return string|float
  1838. */
  1839. public static function IMSIN($complexNumber)
  1840. {
  1841. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1842. $parsedComplex = self::parseComplex($complexNumber);
  1843. if ($parsedComplex['imaginary'] == 0.0) {
  1844. return sin($parsedComplex['real']);
  1845. } else {
  1846. return self::COMPLEX(
  1847. sin($parsedComplex['real']) * cosh($parsedComplex['imaginary']),
  1848. cos($parsedComplex['real']) * sinh($parsedComplex['imaginary']),
  1849. $parsedComplex['suffix']
  1850. );
  1851. }
  1852. }
  1853. /**
  1854. * IMSQRT
  1855. *
  1856. * Returns the square root of a complex number in x + yi or x + yj text format.
  1857. *
  1858. * Excel Function:
  1859. * IMSQRT(complexNumber)
  1860. *
  1861. * @param string $complexNumber The complex number for which you want the square root.
  1862. * @return string
  1863. */
  1864. public static function IMSQRT($complexNumber)
  1865. {
  1866. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1867. $parsedComplex = self::parseComplex($complexNumber);
  1868. $theta = self::IMARGUMENT($complexNumber);
  1869. $d1 = cos($theta / 2);
  1870. $d2 = sin($theta / 2);
  1871. $r = sqrt(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
  1872. if ($parsedComplex['suffix'] == '') {
  1873. return self::COMPLEX($d1 * $r, $d2 * $r);
  1874. } else {
  1875. return self::COMPLEX($d1 * $r, $d2 * $r, $parsedComplex['suffix']);
  1876. }
  1877. }
  1878. /**
  1879. * IMLN
  1880. *
  1881. * Returns the natural logarithm of a complex number in x + yi or x + yj text format.
  1882. *
  1883. * Excel Function:
  1884. * IMLN(complexNumber)
  1885. *
  1886. * @param string $complexNumber The complex number for which you want the natural logarithm.
  1887. * @return string
  1888. */
  1889. public static function IMLN($complexNumber)
  1890. {
  1891. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1892. $parsedComplex = self::parseComplex($complexNumber);
  1893. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1894. return PHPExcel_Calculation_Functions::NaN();
  1895. }
  1896. $logR = log(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
  1897. $t = self::IMARGUMENT($complexNumber);
  1898. if ($parsedComplex['suffix'] == '') {
  1899. return self::COMPLEX($logR, $t);
  1900. } else {
  1901. return self::COMPLEX($logR, $t, $parsedComplex['suffix']);
  1902. }
  1903. }
  1904. /**
  1905. * IMLOG10
  1906. *
  1907. * Returns the common logarithm (base 10) of a complex number in x + yi or x + yj text format.
  1908. *
  1909. * Excel Function:
  1910. * IMLOG10(complexNumber)
  1911. *
  1912. * @param string $complexNumber The complex number for which you want the common logarithm.
  1913. * @return string
  1914. */
  1915. public static function IMLOG10($complexNumber)
  1916. {
  1917. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1918. $parsedComplex = self::parseComplex($complexNumber);
  1919. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1920. return PHPExcel_Calculation_Functions::NaN();
  1921. } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1922. return log10($parsedComplex['real']);
  1923. }
  1924. return self::IMPRODUCT(log10(EULER), self::IMLN($complexNumber));
  1925. }
  1926. /**
  1927. * IMLOG2
  1928. *
  1929. * Returns the base-2 logarithm of a complex number in x + yi or x + yj text format.
  1930. *
  1931. * Excel Function:
  1932. * IMLOG2(complexNumber)
  1933. *
  1934. * @param string $complexNumber The complex number for which you want the base-2 logarithm.
  1935. * @return string
  1936. */
  1937. public static function IMLOG2($complexNumber)
  1938. {
  1939. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1940. $parsedComplex = self::parseComplex($complexNumber);
  1941. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1942. return PHPExcel_Calculation_Functions::NaN();
  1943. } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1944. return log($parsedComplex['real'], 2);
  1945. }
  1946. return self::IMPRODUCT(log(EULER, 2), self::IMLN($complexNumber));
  1947. }
  1948. /**
  1949. * IMEXP
  1950. *
  1951. * Returns the exponential of a complex number in x + yi or x + yj text format.
  1952. *
  1953. * Excel Function:
  1954. * IMEXP(complexNumber)
  1955. *
  1956. * @param string $complexNumber The complex number for which you want the exponential.
  1957. * @return string
  1958. */
  1959. public static function IMEXP($complexNumber)
  1960. {
  1961. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1962. $parsedComplex = self::parseComplex($complexNumber);
  1963. if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
  1964. return '1';
  1965. }
  1966. $e = exp($parsedComplex['real']);
  1967. $eX = $e * cos($parsedComplex['imaginary']);
  1968. $eY = $e * sin($parsedComplex['imaginary']);
  1969. if ($parsedComplex['suffix'] == '') {
  1970. return self::COMPLEX($eX, $eY);
  1971. } else {
  1972. return self::COMPLEX($eX, $eY, $parsedComplex['suffix']);
  1973. }
  1974. }
  1975. /**
  1976. * IMPOWER
  1977. *
  1978. * Returns a complex number in x + yi or x + yj text format raised to a power.
  1979. *
  1980. * Excel Function:
  1981. * IMPOWER(complexNumber,realNumber)
  1982. *
  1983. * @param string $complexNumber The complex number you want to raise to a power.
  1984. * @param float $realNumber The power to which you want to raise the complex number.
  1985. * @return string
  1986. */
  1987. public static function IMPOWER($complexNumber, $realNumber)
  1988. {
  1989. $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
  1990. $realNumber = PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
  1991. if (!is_numeric($realNumber)) {
  1992. return PHPExcel_Calculation_Functions::VALUE();
  1993. }
  1994. $parsedComplex = self::parseComplex($complexNumber);
  1995. $r = sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']));
  1996. $rPower = pow($r, $realNumber);
  1997. $theta = self::IMARGUMENT($complexNumber) * $realNumber;
  1998. if ($theta == 0) {
  1999. return 1;
  2000. } elseif ($parsedComplex['imaginary'] == 0.0) {
  2001. return self::COMPLEX($rPower * cos($theta), $rPower * sin($theta), $parsedComplex['suffix']);
  2002. } else {
  2003. return self::COMPLEX($rPower * cos($theta), $rPower * sin($theta), $parsedComplex['suffix']);
  2004. }
  2005. }
  2006. /**
  2007. * IMDIV
  2008. *
  2009. * Returns the quotient of two complex numbers in x + yi or x + yj text format.
  2010. *
  2011. * Excel Function:
  2012. * IMDIV(complexDividend,complexDivisor)
  2013. *
  2014. * @param string $complexDividend The complex numerator or dividend.
  2015. * @param string $complexDivisor The complex denominator or divisor.
  2016. * @return string
  2017. */
  2018. public static function IMDIV($complexDividend, $complexDivisor)
  2019. {
  2020. $complexDividend = PHPExcel_Calculation_Functions::flattenSingleValue($complexDividend);
  2021. $complexDivisor = PHPExcel_Calculation_Functions::flattenSingleValue($complexDivisor);
  2022. $parsedComplexDividend = self::parseComplex($complexDividend);
  2023. $parsedComplexDivisor = self::parseComplex($complexDivisor);
  2024. if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') &&
  2025. ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) {
  2026. return PHPExcel_Calculation_Functions::NaN();
  2027. }
  2028. if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] == '')) {
  2029. $parsedComplexDivisor['suffix'] = $parsedComplexDividend['suffix'];
  2030. }
  2031. $d1 = ($parsedComplexDividend['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['imaginary']);
  2032. $d2 = ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['real']) - ($parsedComplexDividend['real'] * $parsedComplexDivisor['imaginary']);
  2033. $d3 = ($parsedComplexDivisor['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDivisor['imaginary'] * $parsedComplexDivisor['imaginary']);
  2034. $r = $d1 / $d3;
  2035. $i = $d2 / $d3;
  2036. if ($i > 0.0) {
  2037. return self::cleanComplex($r.'+'.$i.$parsedComplexDivisor['suffix']);
  2038. } elseif ($i < 0.0) {
  2039. return self::cleanComplex($r.$i.$parsedComplexDivisor['suffix']);
  2040. } else {
  2041. return $r;
  2042. }
  2043. }
  2044. /**
  2045. * IMSUB
  2046. *
  2047. * Returns the difference of two complex numbers in x + yi or x + yj text format.
  2048. *
  2049. * Excel Function:
  2050. * IMSUB(complexNumber1,complexNumber2)
  2051. *
  2052. * @param string $complexNumber1 The complex number from which to subtract complexNumber2.
  2053. * @param string $complexNumber2 The complex number to subtract from complexNumber1.
  2054. * @return string
  2055. */
  2056. public static function IMSUB($complexNumber1, $complexNumber2)
  2057. {
  2058. $complexNumber1 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber1);
  2059. $complexNumber2 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber2);
  2060. $parsedComplex1 = self::parseComplex($complexNumber1);
  2061. $parsedComplex2 = self::parseComplex($complexNumber2);
  2062. if ((($parsedComplex1['suffix'] != '') && ($parsedComplex2['suffix'] != '')) &&
  2063. ($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) {
  2064. return PHPExcel_Calculation_Functions::NaN();
  2065. } elseif (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) {
  2066. $parsedComplex1['suffix'] = $parsedComplex2['suffix'];
  2067. }
  2068. $d1 = $parsedComplex1['real'] - $parsedComplex2['real'];
  2069. $d2 = $parsedComplex1['imaginary'] - $parsedComplex2['imaginary'];
  2070. return self::COMPLEX($d1, $d2, $parsedComplex1['suffix']);
  2071. }
  2072. /**
  2073. * IMSUM
  2074. *
  2075. * Returns the sum of two or more complex numbers in x + yi or x + yj text format.
  2076. *
  2077. * Excel Function:
  2078. * IMSUM(complexNumber[,complexNumber[,...]])
  2079. *
  2080. * @param string $complexNumber,... Series of complex numbers to add
  2081. * @return string
  2082. */
  2083. public static function IMSUM()
  2084. {
  2085. // Return value
  2086. $returnValue = self::parseComplex('0');
  2087. $activeSuffix = '';
  2088. // Loop through the arguments
  2089. $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
  2090. foreach ($aArgs as $arg) {
  2091. $parsedComplex = self::parseComplex($arg);
  2092. if ($activeSuffix == '') {
  2093. $activeSuffix = $parsedComplex['suffix'];
  2094. } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
  2095. return PHPExcel_Calculation_Functions::VALUE();
  2096. }
  2097. $returnValue['real'] += $parsedComplex['real'];
  2098. $returnValue['imaginary'] += $parsedComplex['imaginary'];
  2099. }
  2100. if ($returnValue['imaginary'] == 0.0) {
  2101. $activeSuffix = '';
  2102. }
  2103. return self::COMPLEX($returnValue['real'], $returnValue['imaginary'], $activeSuffix);
  2104. }
  2105. /**
  2106. * IMPRODUCT
  2107. *
  2108. * Returns the product of two or more complex numbers in x + yi or x + yj text format.
  2109. *
  2110. * Excel Function:
  2111. * IMPRODUCT(complexNumber[,complexNumber[,...]])
  2112. *
  2113. * @param string $complexNumber,... Series of complex numbers to multiply
  2114. * @return string
  2115. */
  2116. public static function IMPRODUCT()
  2117. {
  2118. // Return value
  2119. $returnValue = self::parseComplex('1');
  2120. $activeSuffix = '';
  2121. // Loop through the arguments
  2122. $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
  2123. foreach ($aArgs as $arg) {
  2124. $parsedComplex = self::parseComplex($arg);
  2125. $workValue = $returnValue;
  2126. if (($parsedComplex['suffix'] != '') && ($activeSuffix == '')) {
  2127. $activeSuffix = $parsedComplex['suffix'];
  2128. } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
  2129. return PHPExcel_Calculation_Functions::NaN();
  2130. }
  2131. $returnValue['real'] = ($workValue['real'] * $parsedComplex['real']) - ($workValue['imaginary'] * $parsedComplex['imaginary']);
  2132. $returnValue['imaginary'] = ($workValue['real'] * $parsedComplex['imaginary']) + ($workValue['imaginary'] * $parsedComplex['real']);
  2133. }
  2134. if ($returnValue['imaginary'] == 0.0) {
  2135. $activeSuffix = '';
  2136. }
  2137. return self::COMPLEX($returnValue['real'], $returnValue['imaginary'], $activeSuffix);
  2138. }
  2139. /**
  2140. * DELTA
  2141. *
  2142. * Tests whether two values are equal. Returns 1 if number1 = number2; returns 0 otherwise.
  2143. * Use this function to filter a set of values. For example, by summing several DELTA
  2144. * functions you calculate the count of equal pairs. This function is also known as the
  2145. * Kronecker Delta function.
  2146. *
  2147. * Excel Function:
  2148. * DELTA(a[,b])
  2149. *
  2150. * @param float $a The first number.
  2151. * @param float $b The second number. If omitted, b is assumed to be zero.
  2152. * @return int
  2153. */
  2154. public static function DELTA($a, $b = 0)
  2155. {
  2156. $a = PHPExcel_Calculation_Functions::flattenSingleValue($a);
  2157. $b = PHPExcel_Calculation_Functions::flattenSingleValue($b);
  2158. return (int) ($a == $b);
  2159. }
  2160. /**
  2161. * GESTEP
  2162. *
  2163. * Excel Function:
  2164. * GESTEP(number[,step])
  2165. *
  2166. * Returns 1 if number >= step; returns 0 (zero) otherwise
  2167. * Use this function to filter a set of values. For example, by summing several GESTEP
  2168. * functions you calculate the count of values that exceed a threshold.
  2169. *
  2170. * @param float $number The value to test against step.
  2171. * @param float $step The threshold value.
  2172. * If you omit a value for step, GESTEP uses zero.
  2173. * @return int
  2174. */
  2175. public static function GESTEP($number, $step = 0)
  2176. {
  2177. $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
  2178. $step = PHPExcel_Calculation_Functions::flattenSingleValue($step);
  2179. return (int) ($number >= $step);
  2180. }
  2181. //
  2182. // Private method to calculate the erf value
  2183. //
  2184. private static $twoSqrtPi = 1.128379167095512574;
  2185. public static function erfVal($x)
  2186. {
  2187. if (abs($x) > 2.2) {
  2188. return 1 - self::erfcVal($x);
  2189. }
  2190. $sum = $term = $x;
  2191. $xsqr = ($x * $x);
  2192. $j = 1;
  2193. do {
  2194. $term *= $xsqr / $j;
  2195. $sum -= $term / (2 * $j + 1);
  2196. ++$j;
  2197. $term *= $xsqr / $j;
  2198. $sum += $term / (2 * $j + 1);
  2199. ++$j;
  2200. if ($sum == 0.0) {
  2201. break;
  2202. }
  2203. } while (abs($term / $sum) > PRECISION);
  2204. return self::$twoSqrtPi * $sum;
  2205. }
  2206. /**
  2207. * ERF
  2208. *
  2209. * Returns the error function integrated between the lower and upper bound arguments.
  2210. *
  2211. * Note: In Excel 2007 or earlier, if you input a negative value for the upper or lower bound arguments,
  2212. * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
  2213. * improved, so that it can now calculate the function for both positive and negative ranges.
  2214. * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
  2215. *
  2216. * Excel Function:
  2217. * ERF(lower[,upper])
  2218. *
  2219. * @param float $lower lower bound for integrating ERF
  2220. * @param float $upper upper bound for integrating ERF.
  2221. * If omitted, ERF integrates between zero and lower_limit
  2222. * @return float
  2223. */
  2224. public static function ERF($lower, $upper = null)
  2225. {
  2226. $lower = PHPExcel_Calculation_Functions::flattenSingleValue($lower);
  2227. $upper = PHPExcel_Calculation_Functions::flattenSingleValue($upper);
  2228. if (is_numeric($lower)) {
  2229. if (is_null($upper)) {
  2230. return self::erfVal($lower);
  2231. }
  2232. if (is_numeric($upper)) {
  2233. return self::erfVal($upper) - self::erfVal($lower);
  2234. }
  2235. }
  2236. return PHPExcel_Calculation_Functions::VALUE();
  2237. }
  2238. //
  2239. // Private method to calculate the erfc value
  2240. //
  2241. private static $oneSqrtPi = 0.564189583547756287;
  2242. private static function erfcVal($x)
  2243. {
  2244. if (abs($x) < 2.2) {
  2245. return 1 - self::erfVal($x);
  2246. }
  2247. if ($x < 0) {
  2248. return 2 - self::ERFC(-$x);
  2249. }
  2250. $a = $n = 1;
  2251. $b = $c = $x;
  2252. $d = ($x * $x) + 0.5;
  2253. $q1 = $q2 = $b / $d;
  2254. $t = 0;
  2255. do {
  2256. $t = $a * $n + $b * $x;
  2257. $a = $b;
  2258. $b = $t;
  2259. $t = $c * $n + $d * $x;
  2260. $c = $d;
  2261. $d = $t;
  2262. $n += 0.5;
  2263. $q1 = $q2;
  2264. $q2 = $b / $d;
  2265. } while ((abs($q1 - $q2) / $q2) > PRECISION);
  2266. return self::$oneSqrtPi * exp(-$x * $x) * $q2;
  2267. }
  2268. /**
  2269. * ERFC
  2270. *
  2271. * Returns the complementary ERF function integrated between x and infinity
  2272. *
  2273. * Note: In Excel 2007 or earlier, if you input a negative value for the lower bound argument,
  2274. * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
  2275. * improved, so that it can now calculate the function for both positive and negative x values.
  2276. * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
  2277. *
  2278. * Excel Function:
  2279. * ERFC(x)
  2280. *
  2281. * @param float $x The lower bound for integrating ERFC
  2282. * @return float
  2283. */
  2284. public static function ERFC($x)
  2285. {
  2286. $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
  2287. if (is_numeric($x)) {
  2288. return self::erfcVal($x);
  2289. }
  2290. return PHPExcel_Calculation_Functions::VALUE();
  2291. }
  2292. /**
  2293. * getConversionGroups
  2294. * Returns a list of the different conversion groups for UOM conversions
  2295. *
  2296. * @return array
  2297. */
  2298. public static function getConversionGroups()
  2299. {
  2300. $conversionGroups = array();
  2301. foreach (self::$conversionUnits as $conversionUnit) {
  2302. $conversionGroups[] = $conversionUnit['Group'];
  2303. }
  2304. return array_merge(array_unique($conversionGroups));
  2305. }
  2306. /**
  2307. * getConversionGroupUnits
  2308. * Returns an array of units of measure, for a specified conversion group, or for all groups
  2309. *
  2310. * @param string $group The group whose units of measure you want to retrieve
  2311. * @return array
  2312. */
  2313. public static function getConversionGroupUnits($group = null)
  2314. {
  2315. $conversionGroups = array();
  2316. foreach (self::$conversionUnits as $conversionUnit => $conversionGroup) {
  2317. if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
  2318. $conversionGroups[$conversionGroup['Group']][] = $conversionUnit;
  2319. }
  2320. }
  2321. return $conversionGroups;
  2322. }
  2323. /**
  2324. * getConversionGroupUnitDetails
  2325. *
  2326. * @param string $group The group whose units of measure you want to retrieve
  2327. * @return array
  2328. */
  2329. public static function getConversionGroupUnitDetails($group = null)
  2330. {
  2331. $conversionGroups = array();
  2332. foreach (self::$conversionUnits as $conversionUnit => $conversionGroup) {
  2333. if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
  2334. $conversionGroups[$conversionGroup['Group']][] = array(
  2335. 'unit' => $conversionUnit,
  2336. 'description' => $conversionGroup['Unit Name']
  2337. );
  2338. }
  2339. }
  2340. return $conversionGroups;
  2341. }
  2342. /**
  2343. * getConversionMultipliers
  2344. * Returns an array of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM()
  2345. *
  2346. * @return array of mixed
  2347. */
  2348. public static function getConversionMultipliers()
  2349. {
  2350. return self::$conversionMultipliers;
  2351. }
  2352. /**
  2353. * CONVERTUOM
  2354. *
  2355. * Converts a number from one measurement system to another.
  2356. * For example, CONVERT can translate a table of distances in miles to a table of distances
  2357. * in kilometers.
  2358. *
  2359. * Excel Function:
  2360. * CONVERT(value,fromUOM,toUOM)
  2361. *
  2362. * @param float $value The value in fromUOM to convert.
  2363. * @param string $fromUOM The units for value.
  2364. * @param string $toUOM The units for the result.
  2365. *
  2366. * @return float
  2367. */
  2368. public static function CONVERTUOM($value, $fromUOM, $toUOM)
  2369. {
  2370. $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
  2371. $fromUOM = PHPExcel_Calculation_Functions::flattenSingleValue($fromUOM);
  2372. $toUOM = PHPExcel_Calculation_Functions::flattenSingleValue($toUOM);
  2373. if (!is_numeric($value)) {
  2374. return PHPExcel_Calculation_Functions::VALUE();
  2375. }
  2376. $fromMultiplier = 1.0;
  2377. if (isset(self::$conversionUnits[$fromUOM])) {
  2378. $unitGroup1 = self::$conversionUnits[$fromUOM]['Group'];
  2379. } else {
  2380. $fromMultiplier = substr($fromUOM, 0, 1);
  2381. $fromUOM = substr($fromUOM, 1);
  2382. if (isset(self::$conversionMultipliers[$fromMultiplier])) {
  2383. $fromMultiplier = self::$conversionMultipliers[$fromMultiplier]['multiplier'];
  2384. } else {
  2385. return PHPExcel_Calculation_Functions::NA();
  2386. }
  2387. if ((isset(self::$conversionUnits[$fromUOM])) && (self::$conversionUnits[$fromUOM]['AllowPrefix'])) {
  2388. $unitGroup1 = self::$conversionUnits[$fromUOM]['Group'];
  2389. } else {
  2390. return PHPExcel_Calculation_Functions::NA();
  2391. }
  2392. }
  2393. $value *= $fromMultiplier;
  2394. $toMultiplier = 1.0;
  2395. if (isset(self::$conversionUnits[$toUOM])) {
  2396. $unitGroup2 = self::$conversionUnits[$toUOM]['Group'];
  2397. } else {
  2398. $toMultiplier = substr($toUOM, 0, 1);
  2399. $toUOM = substr($toUOM, 1);
  2400. if (isset(self::$conversionMultipliers[$toMultiplier])) {
  2401. $toMultiplier = self::$conversionMultipliers[$toMultiplier]['multiplier'];
  2402. } else {
  2403. return PHPExcel_Calculation_Functions::NA();
  2404. }
  2405. if ((isset(self::$conversionUnits[$toUOM])) && (self::$conversionUnits[$toUOM]['AllowPrefix'])) {
  2406. $unitGroup2 = self::$conversionUnits[$toUOM]['Group'];
  2407. } else {
  2408. return PHPExcel_Calculation_Functions::NA();
  2409. }
  2410. }
  2411. if ($unitGroup1 != $unitGroup2) {
  2412. return PHPExcel_Calculation_Functions::NA();
  2413. }
  2414. if (($fromUOM == $toUOM) && ($fromMultiplier == $toMultiplier)) {
  2415. // We've already factored $fromMultiplier into the value, so we need
  2416. // to reverse it again
  2417. return $value / $fromMultiplier;
  2418. } elseif ($unitGroup1 == 'Temperature') {
  2419. if (($fromUOM == 'F') || ($fromUOM == 'fah')) {
  2420. if (($toUOM == 'F') || ($toUOM == 'fah')) {
  2421. return $value;
  2422. } else {
  2423. $value = (($value - 32) / 1.8);
  2424. if (($toUOM == 'K') || ($toUOM == 'kel')) {
  2425. $value += 273.15;
  2426. }
  2427. return $value;
  2428. }
  2429. } elseif ((($fromUOM == 'K') || ($fromUOM == 'kel')) &&
  2430. (($toUOM == 'K') || ($toUOM == 'kel'))) {
  2431. return $value;
  2432. } elseif ((($fromUOM == 'C') || ($fromUOM == 'cel')) &&
  2433. (($toUOM == 'C') || ($toUOM == 'cel'))) {
  2434. return $value;
  2435. }
  2436. if (($toUOM == 'F') || ($toUOM == 'fah')) {
  2437. if (($fromUOM == 'K') || ($fromUOM == 'kel')) {
  2438. $value -= 273.15;
  2439. }
  2440. return ($value * 1.8) + 32;
  2441. }
  2442. if (($toUOM == 'C') || ($toUOM == 'cel')) {
  2443. return $value - 273.15;
  2444. }
  2445. return $value + 273.15;
  2446. }
  2447. return ($value * self::$unitConversions[$unitGroup1][$fromUOM][$toUOM]) / $toMultiplier;
  2448. }
  2449. }