PHPExcel_Calculation
[ class tree: PHPExcel_Calculation ] [ index: PHPExcel_Calculation ] [ all elements ]

Source for file Engineering.php

Documentation is available at Engineering.php

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

Documentation generated on Sun, 27 Feb 2011 16:30:31 -0800 by phpDocumentor 1.4.3