Java BigInteger Factorial factorial(BigInteger originValue)

Here you can find the source of factorial(BigInteger originValue)

Description

factorial

License

Open Source License

Declaration

public static BigInteger factorial(BigInteger originValue) 

Method Source Code

//package com.java2s;
/**/*from   ww w.  j a v a2s .  com*/
                                         * @(#)ArithmeticUtils.java 1.00 2011-9-5 <br>
                                         * Copyright 2009?2019 MarsorStudio , Inc. All rights reserved.<br>
                                         * fhvsbgmy the same as qxc permitted.<br>
                                         * Use is subject to license terms.<br>
                                         */

import java.math.BigInteger;

public class Main {

    public static long factorial(int originValue) {
        long result = 1;
        while (originValue > 1) {
            result = result * originValue;
            originValue--;
        }
        return result;
    }

    public static BigInteger factorial(BigInteger originValue) {
        BigInteger one = new BigInteger("1");
        BigInteger result = new BigInteger("1");
        while (originValue.compareTo(one) > 0) {
            result = result.multiply(originValue);
            originValue = originValue.subtract(one);
        }
        return result;
    }
}

Related

  1. factorial(BigInteger n)
  2. factorial(BigInteger n)
  3. factorial(BigInteger number)