Java Factorial factorialAsDoubleIncludeDivisor(int n, double divisor)

Here you can find the source of factorialAsDoubleIncludeDivisor(int n, double divisor)

Description

Computes n!

License

Open Source License

Parameter

Parameter Description
n a parameter
divisor a parameter

Declaration

public static double factorialAsDoubleIncludeDivisor(int n, double divisor) 

Method Source Code

//package com.java2s;
/*//from   www .j  a va  2  s  .  c  o m
 *  Java Information Dynamics Toolkit (JIDT)
 *  Copyright (C) 2012, Joseph T. Lizier
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Computes n! as a double (to provide extended range over a long).
     * 
     * We include the divisor here since n! hits with n at about 340.
     * So if there is anything the result would have been divided by, we include it here,
     *  thus extending the range of n the function is suitable for. 
     * 
     * @param n
     * @param divisor
     * @return
     */
    public static double factorialAsDoubleIncludeDivisor(int n, double divisor) {
        double result = 1.0 / divisor;
        for (int i = 1; i <= n; i++) {
            result *= (double) i;
        }
        return result;
    }
}

Related

  1. factorial(int x)
  2. factorial(long l)
  3. factorial(long n)
  4. factorial(long num)
  5. factorialAsDouble(int n)
  6. factorialCheckBounds(int n)
  7. factorialDouble(final int n)
  8. factorialLog(final int n)
  9. factorialLog(final int n)