/*
   ========================================================================
   This function will convert an arbitrary precision positive base 10
   X value into its equivalent in any base from 2 to 36.  The X value
   is NOT restricted to integers and also allows fractional values.

   ARGUMENTS:
   $XBase10 = Base 10 numeric string to be to converted
              into its BaseB equivalent.

   $BaseB = Base (2 to 36) in which to interpret input digit string.

   ERRORS:
   On error FALSE is returned.  An error occurs if either
   of the arguments is non-numeric or out of valid range.

   DEPENDENCY:
   BC_Base_10_Int_To_Base_B()

   ========================================================================
*/

   function BC_X_Base_10_To_Base_B ($xBase10, $BaseB, $TruncationLimit=0)
{
// Radix precision limit.
   $p = 1000;

// Decimal truncation limit.
   $q = $TruncationLimit;

// Remember numerical sign to be restored to output.
   $x = trim($xBase10);  $sign = (substr($x,0,1) != "-")? "" : "-";
   $x = str_replace("-","", $x);

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

   list($i, $f) = preg_split("[\.]", $x);  $f = "0.$f";

// Convert integer part.
   $IntPartOut = BC_Base_10_Int_To_Base_B ($i, $BaseB);

   $w = bcMul(bcPow($BaseB, $p), $f);

   $fp = BC_Base_10_Int_To_Base_B ($w, $BaseB);

   $zeros = Str_Repeat("0", $p - strlen($fp));

   if ($q > 0) {$fp = substr($fp, 0, $q-0);}

   $FracPartOut = ".$zeros$fp";

   $FracPartOut = RTrim(rtrim($FracPartOut,'0'), '.');

   return "$sign$IntPartOut$FracPartOut";

}// End of  BC_X_Base_10_To_Base_B ()