title: What size does of stack does java -xss16M allocate 16 MegaBytes or 16Megabits
body: <p>I am attempting to prove that I am using tail recursion properly by restricting the size allocated to the thread stack using the java -Xss160M command. I am writing a simple tail recursion algorithm for finding the factorial of a really big numbers:</p>
  
  <pre><code>/*
  *
  *my Program
  *
  */
  
  import java.math.BigInteger;
  
  public class TailFactorial {
  private BigInteger factorial(BigInteger n, BigInteger acc) {
      if (n.equals(BigInteger.ONE)) return acc;
      else return factorial(n.subtract(BigInteger.ONE), n.multiply(acc));
  }
  public static void main(String[] args) {
      // TODO Auto-generated method stub
      TailFactorial classs = new TailFactorial();
      int num;
      BigInteger bigNum = BigInteger.ONE;
      boolean gTG = false;
      String finalNumString = "";
      String msg = "";
      try {
          num = Integer.parseInt(args[0]);
          bigNum = BigInteger.valueOf(num);
          msg = "fact("+String.valueOf(num)+") = ";
          gTG = true;
  
      }catch(Exception e) {
          System.out.println("Could not get arguments, please make sure you are passing an integer");
          gTG = false;
      }
      try {
          if(gTG) {
              BigInteger finalNum = classs.factorial(bigNum ,BigInteger.ONE);
              System.out.println(String.valueOf(finalNum.bitCount()));
              finalNumString = finalNum.toString();
              //System.out.println( msg + finalNumString);
          }
          else {
              System.out.print("Exiting");
          }
  
      }catch(StackOverflowError e) {
          System.out.print("Not enough memory allocated to stack, try exicuting with java -Xss$bigger memory inserted here$ TrailFactorial");
      }
      catch(Exception e) {
          System.out.print("Unrecoginzed error in finding factorial");
      }
  
  
  
  }
  
  }
  </code></pre>
  
  <p>The code runs just fine, but I have to allocate 50M to the stack. When I run the current program, it displays the bit count of the result. When I find the factorial of one-hundred-thousand the bit count is 708,218, and I still have to use 50M. Can someone explain to me the meaning of the M? is it megabytes or bits? Am I not implementing tail-recursion properly?</p>