<?PHP

/*

 This program is a simple metric length equivalents table calculator.

 AUTHOR   : Jay Tanner - 2025
 LANGUAGE : PHP v8.2.12
 LICENSE  : Public Domain

 There are 23 length units symbols recognized by
 this program.

********************************************
*/


// Initialize output buffer.
   
ob_start();

   
$_PROGRAM_VERSION_ '3.0';

   
$cYear gmdate("Y");

   
$_ACTION_FILE_NAME_ $_SERVER['SCRIPT_NAME'];

   
$_HTML_TITLE_ 'Metric Length Equivalents Calculator';

   
$_HEADER_ "<span style='font-size:15pt;'>Quick Metric Length Equivalents Table Calculator</span><br>
   <span style='font-size:10pt;'>PHP Program by Jay Tanner - v
$_PROGRAM_VERSION_</span>";

// Set default text and background colors for the text area.
   
$TxColor 'black';
   
$BgColor 'white';

   
$UNITS_TABLE =
" SYMBOL    UNITS of LENGTH or DISTANCE \n
   A        &#197;ngstroms
   nm       Nanometers  or Millimicrons
 um / u     Micrometers or Microns
   mm       Millimeters
   cm       Centimeters
   in       Inches
   ft       Feet
   yd       Yards
   m        Meters
   rd       Rods
   ch       Chains
   fur      Furlongs
   km       Kilometers
   mi       Miles (Statute)
   nmi      Nautical Miles
   LS       Light Seconds
   LM       Light Minutes
   AU       Astronomical Units
   LH       Light Hours
   LD       Light Days
   LW       Light Weeks
   LY       Light Years
   pc       Parsecs (Parallax Seconds)
"
;



// -----------------------------------------------------------------
// Define some standard metric length/distance interconversion
// factors in terms of metres per unit (M_PER_UNIT).  This is the
// factor to multiply the units by to compute the equivalent metres.

   
define ('M_PER_A'   '0.0000000001');     //  m per angstrom
   
define ('M_PER_NM'  '0.000000001');      //  m per nanometer
   
define ('M_PER_UM'  '0.000001');         //  m per micrometer (micron)
   
define ('M_PER_MM'  '0.001');            //  m per millimeter
   
define ('M_PER_CM'  '0.01');             //  m per centimeter
   
define ('M_PER_IN'  '0.0254');           //  m per inch
   
define ('M_PER_FT'  '0.3048');           //  m per foot
   
define ('M_PER_YD'  '0.9144');           //  m per yard
   
define ('M_PER_M'   '1');                //  m per meter
   
define ('M_PER_RD'  '5.0292');           //  m per rod
   
define ('M_PER_CH'  '20.1168');          //  m per chain
   
define ('M_PER_FUR' '201.168');          //  m per furlong
   
define ('M_PER_KM'  '1000');             //  m per kilometer
   
define ('M_PER_MI'  '1609.344');         //  m per mile (statute)
   
define ('M_PER_NMI' '1852');             //  m per nautical mile
   
define ('M_PER_LS'  '299792458');        //  m per light second
   
define ('M_PER_LM'  '17987547480');      //  m per light minute
   
define ('M_PER_LH'  '1079252848800');    //  m per light hour
   
define ('M_PER_LD'  '25902068371200');   //  m per light day
   
define ('M_PER_LW'  '181314478598400');  //  m per light week
   
define ('M_PER_LY'  '9460730472580800'); //  m light year
   
define ('M_PER_AU'  '149597870700');     //  NASA/JPL-DE405/IAU
   
define ('M_PER_PC''30856775814913672.78913937957796471610731921160409179801404019227702329218699929686983213533880655599332701202380058827783247463');

// Read interface arguments.
   
$LengthValue Filter_Input(INPUT_POST'LengthValue');
   
$LengthValue BC_Int_Frac_to_Dec_Val ($LengthValue64);

   
$LengthValue Str_Replace(','''$LengthValue);
   
$LengthValue Str_Replace(' '''$LengthValue);

   
$LengthUnits Filter_Input(INPUT_POST'LengthUnits');

// Set defaults if empty inputs.
   
if ($LengthValue == '') {$LengthValue '1';}
   if (
$LengthUnits == '') {$LengthUnits 'm';}

// AUTO-ADJUST SYMBOL CASE
   
$LengthUnits StrToLower($LengthUnits);

   if (
       
$LengthUnits == 'a'
   
or  $LengthUnits == 'au'
   
or  $LengthUnits == 'ly'
   
or  $LengthUnits == 'ls'
   
or  $LengthUnits == 'lm'
   
or  $LengthUnits == 'lh'
   
or  $LengthUnits == 'ld'
   
or  $LengthUnits == 'lw'
      
)
      {
$LengthUnits StrToUpper($LengthUnits);}

// **********************************
// **********************************
// AT THIS POINT, THE INPUT INTERFACE
// VALUES SHOULD BE READY FOR USE.



// ---------------------------------------
// CHECK FOR AND BLOCK INVALID DATE INPUT.

   
if (!is_numeric($LengthValue))
      {
       
$out "\n  Invalid argument.\n";
       
$TxColor 'white';
       
$BgColor 'maroon';
      }

else

// ===============================
// CONTINUE BELOW IF ARGUMENTS OK.

  
{
   
$u BC_Big_Int_Name ($LengthValue'');
   
$out " LENGTHS or DISTANCES EQUIVALENT TO:\n $LengthValue $LengthUnits$u\n";

   
$U 'A';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= "\n " $w " &#197; $u \n ";

   
$U 'nm';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'um';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'mm';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'cm';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'in';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'ft';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'yd';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'm';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'rd';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'ch';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'fur';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'km';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'mi';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'nmi';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'LS';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'LM';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'AU';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'LH';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'LD';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'LW';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'LY';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n ";

   
$U 'pc';  $w From_Units_To_Units($LengthValue$LengthUnits$U);
   
$u BC_Big_Int_Name ($w'');  $out .= $w $U $u \n\n";
  }

// =========================================================

   
$UNITS_TABLE =
$UNITS_TABLE";

// ---------------------------------------------
// Automatically set TextArea1 columns and rows.

   
$Text1Cols Max(Array_Map('StrLen'PReg_Split("[\n]"trim($out))));
   
$Text1Rows Substr_Count($out"\n");

   print <<< _HTML

<!DOCTYPE HTML>

<HTML lang='en'>
<head>
<title>
$_HTML_TITLE_</title>

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="description" content="A numerical metric length units equivalents calculator.">
<meta name="keywords" content="metric length conversion,metrics,length converter">
<meta name="author" content="Jay Tanner - https://www.NeoProgrammics.com">
<meta http-equiv="pragma"  content="no-cache">
<meta http-equiv="expires" content="-1">
<meta name="robots"    content="index,follow">
<meta name="googlebot" content="index,follow">

<style>
 BODY
{
 color:white; background:black; font-family:Verdana; font-size:120%;
}



 DIV
{
 color:black; background:white; font-family:Verdana; font-size:110%;
 padding:6px; border-radius:8px;
}



PRE
{
 background:white; color:black; font-family:monospace; font-size:150%;
 font-weight:bold; line-height:125%; padding:6px; border:1px solid black;
 border-radius:8px;
}



CODE
{
 font-family:monospace; font-size:140%; font-weight:bold;
}



 TABLE
{
 font-size:100%;
}

 TD
{
 color:black; background-color:black; line-height:125%; font-size:100%;
 padding:6px; text-align:left;
}



 TEXTAREA
{
 color:black; background:white; font-family:monospace; font-size:11pt;
 font-weight:bold; border-radius: 8px; border:1px solid black; padding:10px;
 white-space:pre;
}



 INPUT[type='text']::-ms-clear {width:0; height:0;}

 INPUT[type='text']
{
 font-family:monospace; color:black; background:white; font-size:125%;
 font-weight:bold; text-align:center; box-shadow:2px 2px 3px #666666;
 border:1px solid black; border-radius:4px;
}

 INPUT[type='text']:focus
{
 font-family:monospace; background:white; box-shadow:2px 2px 3px #666666;
 font-size:125%; border:2px solid blue; text-align:center; font-weight:bold;
 border-radius:4px;
}



 INPUT[type='submit']
{
 background:black; color:#777777; font-family:Verdana; font-size:10pt;
 font-weight:bold; border-radius:4px; border:4px solid #008800;
 padding:3pt;
}
 INPUT[type='submit']:hover
{
 background:black; color:white; font-family:Verdana; font-size:10pt;
 font-weight:bold; border-radius:4px; border:4px solid GreenYellow;
 padding:3pt;
}



 HR {background:black; height:2px; border:0px;}



 A:link
{
 font-size:80%; background:transparent; color:DodgerBlue;
 font-family:Verdana; font-weight:bold; text-decoration:none;
 line-height:175%; padding:3px; border:1px solid transparent;
}

 A:visited
{
 font-size:80%; background:transparent; color:gray;
}

 A:hover
{
 font-size:80%; background:yellow; color:black; border:1px solid black;
 box-shadow:1px 1px 3px #222222;
}

 A:active
{
 font-size:80%; background:yellow; color:black;
}

 ::selection{background-color:yellow !important; color:black !important;}
 ::-moz-selection{background-color:yellow !important; color:black !important;}

</style>



</HEAD>

<BODY>

<FORM NAME="InputForm1" METHOD="post" ACTION="
$_ACTION_FILE_NAME_">

<TABLE align='center' WIDTH="782" style='border:1px solid black;' CELLPADDING="4" CELLSPACING="0">

<TR><TD style='color:white; background-color:#000066; text-align:center; border-radius:8px 8px 0px 0px; border:2px solid white;' ALIGN="center">
$_HEADER_</TD></TR>

<TR><TD style="background-color:LightCyan; text-align:center; font-size:11pt;">ENTER the Numerical Value Followed By the Length or Distance Units Symbol</TD></TR>

<TR><TD style='text-align:center; line-height:200%;'
title=" 
$UNITS_TABLE
 NOTE:
 The units symbols are NOT case-sensitive.
">

<INPUT NAME="LengthValue" TYPE="text" VALUE="
$LengthValue" SIZE="64" MAXLENGTH="256" style='text-align:right; padding:4px;'>
<INPUT NAME="LengthUnits" TYPE="text" VALUE="
$LengthUnits" SIZE="4"  MAXLENGTH="3">
<br>
<INPUT TYPE="submit" NAME="Submit" VALUE="Compute">
</TD></TR>


<!-- Yellow source code view link. --->
<tr>
<td colspan='1' style='background:transparent; color:black; font-size:10pt;
                       text-align:center;'>
<br>
<a href='View-Source-Code.php' target='_blank'
   style='font-family:Verdana; color:black; background:yellow;
         text-decoration:none; border:1px solid black; padding:4px;
         border-radius:4px;' title=' Tries to Display Source Code in a New Tab '>
         &nbsp;<span style='font-weight:normal;'>View/Copy PHP Source Code</span>&nbsp;</a>
</td>
</tr>


<tr><td>
<TABLE WIDTH="100%" BORDER="0" ALIGN="botom" BGCOLOR="black" CELLPADDING="8" CELLSPACING="1">

<TR><TD style='background:black; text-align:center;'>
<span style='color:lime; font-size:10pt;'>Double-Click Within Text Area to Select ALL Text</span><br>
<textarea name='TextArea1' cols="
$Text1Cols" rows="$Text1Rows" style='font-family:monospace; text-align:left; background:$BgColor; color:$TxColor; font-size:13pt; border:2px solid white; border-radius:8px;' ReadOnly OnDblClick='this.select();' OnMouseUp='return true;'>
$out
</textarea>

</TD></TR>

<TR><TD style='text-align:center;'>
<textarea name='TextArea2' cols="40" rows="32" style='text-align:left; background-color:LightYellow; font-size:11pt; border-radius:8px;' ReadOnly>
 There are 23 length units symbols that
 are recognized by this program. Listed
 in order of size, they are:

========    ===========================
$UNITS_TABLE
</textarea>
</TD></TR>

<tr><td style='color:gray; font-size:10pt; text-align:center;'>PHP Program by Jay Tanner - 
$cYear - v$_PROGRAM_VERSION_</td></tr>

</TABLE></td></tr>

</TABLE>
</FORM>

<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>


</body>
</html>

_HTML;


/* This function converts from one length unit to another
   with some special formatting.
*/

   
function From_Units_To_Units($FromValStr$FromUnits$ToUnits)
 {
   
$L1 Length_To_Meters ($FromValStr$FromUnits);
   
$w  Meters_To_Length ($L1$ToUnits);

   
$L2 $w;

   if (
abs($w) < 1)
      {
       
$w bcAdd('0'$w64);
       
$w BC_Round($w64);
       
$w RTrim(RTrim($w'0'), '.');
      }
   else
      {
       
$w BC_Round($w64);
       
$w RTrim(RTrim($w'0'), '.');
      }

   return 
$w;
 }





/*
   This utility function simply rounds off a BC number
   string to the specified number of decimals.
*/

   
function BC_Round ($xStrArg$NumDecimalsArg=0)

{
   
$SignStr = (substr($xStrArg,0,1) == '-' )? '-' '';

   
$x str_replace('-'''$xStrArg);

   
$decimals $NumDecimalsArg;

   
$Zeros5 '';

   for (
$i=0;   $i $decimals;   $i++)
       {
$Zeros5 .= '0';}
        
$Zeros5 .= '5';

   
$x bcAdd($x"0.$Zeros5"$decimals);

   return 
"$SignStr$x";

// End of  BC_Round()





/* ********************************************************
   This function converts any of several units of length or
   distance into the equivalent in meters.  It makes use of
   the metric length equivalents defined within this module.

   It is the opposite of the Meters_To_Length() function.

----
NOTE

These computations are able to accomodate arbitrary
precision out to 105 decimals which is sufficient
for any practical usage.

---------
ARGUMENTS

$LengthVal = Numerical value of the length to be converted
$FromUnits = The units symbol corresponding to the value

The returned output is simply the equivalent length in meters.

-------------------------------------------------------
There are 23 units symbols recognized by this function.

They are:

 SYMBOL         UNITS

   A            Angstroms
   nm           Nanometers
 um / u         Micrometers (or Microns)
   mm           Millimeters
   cm           Centimeters
   in           Inches
   ft           Feet
   yd           Yards
   m            Meters
   rd           Rods
   ch           Chains
   fur          Furlongs
   km           Kilometers
   mi           Miles (Statute)
   nmi          Nautical Miles
   AU           Astronomical Units
   LS           Light Seconds
   LM           Light Minutes
   LH           Light Hours
   LD           Light Days
   LW           Light Weeks
   LY           Light Years
   pc           Parsecs (Parallax Seconds)

IMPORTANT NOTE:
The units symbols used here ARE case sensitive.

ERRORS:
An error occurs if the argument cannot be resolved
into a valid numerical value and units symbol.  On
error, FALSE is returned.
*/

   
Function Length_To_Meters ($LengthVal$FromUnits)
{

// ------------------------------
// Set arbitrary precision limit.

   
$nDec 105;

// -----------------------------
// Get the numerical value part.
// Error if not a numerical value.

   
$x trim($LengthVal);

   if (
$x == "") {$x "0.0";}

   if (!
is_numeric($x)) {return FALSE;}

   if (
StrPos($x".") === FALSE) {$x "$x.0";}

// ----------------
// Get units symbol.

   
$UnitsSymbol trim($FromUnits);

// ---------------------------------------------------
// Initialize factor to empty string.   If it is still
// empty on exit from the switch block, below then it
// means that the units symbol was not recognized as
// valid.

   
$f '';

// --------------------------------------
// Determine the conversion factor to use
// from the units symbol argument.
//
// NOTE: These symbols ARE case sensitive.

   
switch ($UnitsSymbol)
  {
   case 
"A"   $f M_PER_A;     break;
   case 
"um"  $f M_PER_UM;    break;
   case 
"u"   $f M_PER_UM;    break;
   case 
"nm"  $f M_PER_NM;    break;
   case 
"mm"  $f M_PER_MM;    break;
   case 
"cm"  $f M_PER_CM;    break;
   case 
"in"  $f M_PER_IN;    break;
   case 
"ft"  $f M_PER_FT;    break;
   case 
"yd"  $f M_PER_YD;    break;
   case 
"m"   $f M_PER_M;     break;
   case 
"rd"  $f M_PER_RD;    break;
   case 
"ch"  $f M_PER_CH;    break;
   case 
"fur" $f M_PER_FUR;   break;
   case 
"km"  $f M_PER_KM;    break;
   case 
"mi"  $f M_PER_MI;    break;
   case 
"nmi" $f M_PER_NMI;   break;
   case 
"LS"  $f '299792458'; break;
   case 
"LM"  $f M_PER_LM;    break;
   case 
"LH"  $f M_PER_LH;    break;
   case 
"LD"  $f M_PER_LD;    break;
   case 
"LW"  $f M_PER_LW;    break;
   case 
"AU"  $f M_PER_AU;    break;
   case 
"LY"  $f M_PER_LY;    break;
   case 
"pc"  $f M_PER_PC;    break;
   default    : 
$f FALSE;       break;
  }


// ------------------------------------------
// Error if conversion factor is still empty,
// which means that the units symbol is not
// found in the table of valid symbols.
   
if ($f === '') {return FALSE;}

// ----------------------------------------------
// Otherwise, return the equivalent meters value
// by multiplying the value of the argument by
// the conversion factor ($f).
   
$w bcMul("$x""$f"$nDec);

// -----
// Done.
   
return RTrim(RTrim($w"0"), ".");

}  
// End of Length_To_Meters()




/*

**********************************************************
This function converts a length or distance value given in
meters into its equivalent in any of the 23 length units
recognized by this module.

It is the opposite of the Length_To_Meters() function and
recognizes the same length units symbols.

NOTE:
The computations are able to accomodate arbitrary
precision out to 105 decimals which is sufficient
for any practical usage.

ARGUMENTS
$metersArg =  Value in meters that will be converted
              to the specified output units.

$toUnits   =  Units symbol for the output value.  This
              symbol will NOT be attached to the output.
              It will simply be a numeric value that is
              understood to be in the specified units.

There are 23 units symbols recognized by this function.
They are:

 SYMBOL         UNITS

   A            Angstroms
   nm           Nanometers
 um or u        Micrometers (or Microns)
   mm           Millimeters
   cm           Centimeters
   in           Inches
   ft           Feet
   yd           Yards
   m            Meters
   rd           Rods
   ch           Chains
   fur          Furlongs
   km           Kilometers
   mi           Miles (Statute)
   nmi          Nautical Miles
   AU           Astronomical Units
   LS           Light Seconds
   LM           Light Minutes
   LH           Light Hours
   LD           Light Days
   LW           Light Weeks
   LY           Light Years
   pc           Parsecs

IMPORTANT NOTE:
The units symbols as used here internally ARE case-sensitive.
To the client, it doesn&#39;t matter and the interface value
input is NOT-case sensitive.

ERRORS
FALSE is returned if the argument cannot be resolved into a
valid numerical value and units symbol.

*/

   
Function Meters_To_Length ($MetersVal$ToUnits)

{

// ------------------------------
// Set arbitrary precision limit.

   
$nDec 105;

// ------------------------------
// Read value of meters argument.

   
$m Trim("$MetersVal");

// -------------------------------------
// Error if meters value is non-numeric.

   
If (!Is_Numeric($m)) {Return FALSE;}

   if (
StrPos($m".") === FALSE) {$m "$m.0";}

// --------------------------------------
// Read the output units symbol argument.

   
$UnitsSymbol Trim($ToUnits);

// ---------------------------------------------------
// Initialize factor to empty string.   If it is still
// empty on exit from the switch block below, then it
// means that the units symbol was not found in the
// table of valid units.

   
$f '';

// -----------------------------------------------
// Determine the conversion factor to use from the
// units symbol argument.
// INTERNALLY, THESE SYMBOLS ARE CASE SENSITIVE.

   
switch ($UnitsSymbol)
  {
   case 
"A"   $f M_PER_A;    break;
   case 
"um"  $f M_PER_UM;   break;
   case 
"u"   $f M_PER_UM;   break;
   case 
"nm"  $f M_PER_NM;   break;
   case 
"mm"  $f M_PER_MM;   break;
   case 
"cm"  $f M_PER_CM;   break;
   case 
"in"  $f M_PER_IN;   break;
   case 
"ft"  $f M_PER_FT;   break;
   case 
"yd"  $f M_PER_YD;   break;
   case 
"m"   $f M_PER_M;    break;

   case 
"rd"   $f M_PER_RD;  break;
   case 
"ch"   $f M_PER_CH;  break;

   case 
"fur" $f M_PER_FUR;  break;
   case 
"km"  $f M_PER_KM;   break;
   case 
"mi"  $f M_PER_MI;   break;
   case 
"nmi" $f M_PER_NMI;  break;
   case 
"LS"  $f M_PER_LS;   break;
   case 
"LM"  $f M_PER_LM;   break;
   case 
"LH"  $f M_PER_LH;   break;
   case 
"LD"  $f M_PER_LD;   break;
   case 
"LW"  $f M_PER_LW;   break;
   case 
"AU"  $f M_PER_AU;   break;
   case 
"LY"  $f M_PER_LY;   break;
   case 
"pc"  $f M_PER_PC;   break;
   default    : 
$f '';         break;
  }

// ------------------------------------------
// Error if conversion factor is still empty.

   
If ($f === '') {return FALSE;}

// ----------------------------------------------
// Otherwise, return the equivalent of the given
// meters value by dividing the value of the
// argument by the conversion factor $f.

   
$w bcDiv ($m$f$nDec);

   return 
RTrim(RTrim($w"0"), ".");

}  
// End of Meters_To_Length()



/* ***********************************************************************
   This is a utility function used to generate the formal names of giant
   integers up to 99 digits long.
*/

   
function BC_Big_Int_Name ($BigIntStr$LableString='')
{
// Read numeric string and cut off any decimal
// digits from X without rounding.
   
$X trim($BigIntStr);
   
$X bcAdd('0'$X);

// Read optional lable string argument
// to be appended to returned result.
   
$label trim($LableString);
   if (
$label <> '') {$label $label";}

// Return empty string if X < 1 million.
//   $LenX = StrLen($X);  if (strlen($X) < 7) {return '';}
   
$LenX StrLen($X);  if ($X 1000000) {return '';}

   
$NumDigits StrLen($X);

   
$i[0]  = "";
   
$i[1]  = "thousand";
   
$i[2]  = "million";
   
$i[3]  = "billion";
   
$i[4]  = "trillion";
   
$i[5]  = "quadrillion";
   
$i[6]  = "quintillion";
   
$i[7]  = "sextillion";
   
$i[8]  = "septillion";
   
$i[9]  = "octillion";
   
$i[10] = "nonillion";
   
$i[11] = "decillion";
   
$i[12] = "undecillion";
   
$i[13] = "duodecillion";
   
$i[14] = "tredecillion";
   
$i[15] = "quattuordecillion";
   
$i[16] = "quindecillion";
   
$i[17] = "sexdecillion";
   
$i[18] = "septendecillion";
   
$i[19] = "octodecillion";
   
$i[20] = "novemdecillion";
   
$i[21] = "vigintillion";
   
$i[22] = "unvigintillion";
   
$i[23] = "duovigintillion";
   
$i[24] = "trevigintillion";
   
$i[25] = "quattuorvigintillion";
   
$i[26] = "quinvigintillion";
   
$i[27] = "sexvigintillion";
   
$i[28] = "septenvigintillion";
   
$i[29] = "octovigintillion";
   
$i[30] = "novemvigintillion";
   
$i[31] = "trigintillion";
   
$i[32] = "untrigintillion";
   
$i[33] = "duotrigintillion";

   
$j floor($NumDigits 3);

   
$k $NumDigits 3;

   if (
$k == 0)
      {
$j -= 1;  $xxx substr($X03);}
   else
      {
$xxx substr($X0$k);}

   
$w "$xxx";  $w LTrim($w'0');  if (IntVal($w) == 0) {$w '0';}

   if (
$w == '0') {return '';}

// Collect 3 digits for decimal part from X.
   
$u substr($XStrLen($w), 4) + 5;
   
$ddd SPrintF("%03d"substr($u0StrLen($u)-1));

// Determine engineering notation exponent for X.
   
$E $LenX StrLen($w);

   
$w "\n $w.$ddd $i[$j]$label (E+$E)\n";

   return 
Str_Replace('.000'''$w);

// End of  BC_Big_Int_Name (BigIntStr)





/*
  This utility allows for fractional arguments to be
  converted to decimal values to up to 100 decimals.

  For example, the argument '1/8' will be converted to
  the decimal value '0.125' for internal computations.
*/

   
function BC_Int_Frac_to_Dec_Val ($IntFrac$Decimals=64)
{
   
$X trim($IntFrac);

   if (
StrPos($X'/') === FALSE) {$X "$X/1";}

   
$q trim($Decimals);
   
$Q 100;

   list(
$numer$denom) = PReg_Split("[\/]"$X);
   
$numer trim($numer);
   
$denom trim($denom);

   
$DecVal bcDiv($numer$denom$Q);
   
$DecVal bcAdd($DecVal'0'$q);
   
$DecVal RTrim(RTrim($DecVal'0'), '.');

   return 
$DecVal;
}






?>