code: public static BigRational bernoulli(int n) {
  		if (n < 0) {
  			throw new ArithmeticException("Illegal bernoulli(n) for n < 0: n = " + n);
  		}
      	if (n == 1) {
      		return valueOf(-1, 2);
      	} else if (n % 2 == 1) {
      		return ZERO;
      	}
      	
      	synchronized (bernoulliCache) {
      		int index = n / 2;
      		
      		if (bernoulliCache.size() <= index) {
      			for (int i = bernoulliCache.size(); i <= index; i++) {
      				BigRational b = calculateBernoulli(i * 2);
  					bernoulliCache.add(b);
  				}
      		}
      		
      		return bernoulliCache.get(index);
  		}
      }
docs: Calculates the Bernoulli number for the specified index.
  
  <p>This function calculates the <strong>first Bernoulli numbers</strong> and therefore <code>bernoulli(1)</code> returns -0.5</p>
  <p>Note that <code>bernoulli(x)</code> for all odd x &gt; 1 returns 0</p>
  <p>See: <a href="https://en.wikipedia.org/wiki/Bernoulli_number">Wikipedia: Bernoulli number</a></p>
  
  @param n the index of the Bernoulli number to be calculated (starting at 0)
  @return the Bernoulli number for the specified index
  @throws ArithmeticException if x is lesser than 0