Example usage for java.math BigInteger doubleValue

List of usage examples for java.math BigInteger doubleValue

Introduction

In this page you can find the example usage for java.math BigInteger doubleValue.

Prototype

public double doubleValue() 

Source Link

Document

Converts this BigInteger to a double .

Usage

From source file:MainClass.java

public static void main(String[] args) {
    System.out.println("Here's Long.MAX_VALUE: " + Long.MAX_VALUE);
    BigInteger bInt = new BigInteger("3419229223372036854775807");
    System.out.println("Here's a bigger number: " + bInt);
    System.out.println("Here it is as a double: " + bInt.doubleValue());
}

From source file:BigNums.java

public static void main(String[] argv) {
    //+/*from  w w  w. j  a v  a2s.co  m*/
    System.out.println("Here's Long.MAX_VALUE: " + Long.MAX_VALUE);
    BigInteger bInt = new BigInteger("3419229223372036854775807");
    System.out.println("Here's a bigger number: " + bInt);
    System.out.println("Here it is as a double: " + bInt.doubleValue());
    //-
}

From source file:Main.java

public static void main(String[] args) {

    // assign value to bi1
    BigInteger bi1 = new BigInteger("123");

    // assign a larger value to bi2
    BigInteger bi2 = new BigInteger("12345678");

    // assign double value of bi1, bi2 to d1, d2
    Double d1 = bi1.doubleValue();
    Double d2 = bi2.doubleValue();

    System.out.println(d1);//w ww  . ja v a  2 s.  co  m
    System.out.println(d2);
}

From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java

/**
 * Converts a list of BigIntegers to a list of Doubles.
 * @param    List<BigInteger>    list of BigIntegers
 * @return                       list of doubles
 *///  w ww. j  a  v a  2  s  . c  o m
public static List<Double> toDoubleList(List<BigInteger> list) {

    List<Double> doubleList = new ArrayList<Double>();

    for (BigInteger val : list) {
        if (!OverFlowUtil.doubleOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
        doubleList.add(val.doubleValue());
    }

    return doubleList;
}

From source file:cc.redberry.core.number.Exponentiation.java

public static Complex findIntegerRoot(Complex base, BigInteger power) {
    BigInteger rDenominator = ((Rational) base.getReal()).getDenominator();
    BigInteger iDenominator = ((Rational) base.getImaginary()).getDenominator();

    BigInteger lcm = rDenominator.gcd(iDenominator);
    lcm = rDenominator.divide(lcm);/*w ww. j ava  2  s. c  o  m*/
    lcm = lcm.multiply(iDenominator);

    BigInteger lcmRoot = findIntegerRoot(lcm, power);

    if (lcm == null)
        return null;

    base = base.multiply(lcm);

    Complex numericValue = base.pow(1.0 / power.doubleValue());
    double real = numericValue.getReal().doubleValue();
    double imaginary = numericValue.getImaginary().doubleValue();

    int ceilReal = (int) Math.ceil(real), floorReal = (int) Math.floor(real),
            ceilImaginary = (int) Math.ceil(imaginary), floorImaginary = (int) Math.floor(imaginary);

    Complex candidate;
    if ((candidate = new Complex(ceilReal, ceilImaginary)).pow(power).equals(base))
        return candidate.divide(lcmRoot);
    if ((candidate = new Complex(floorReal, ceilImaginary)).pow(power).equals(base))
        return candidate.divide(lcmRoot);
    if ((candidate = new Complex(ceilReal, floorImaginary)).pow(power).equals(base))
        return candidate.divide(lcmRoot);
    if ((candidate = new Complex(floorReal, floorImaginary)).pow(power).equals(base))
        return candidate.divide(lcmRoot);
    return null;
}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Safely converts an object to a double. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Object    object to parse//from ww w. j  a v  a  2  s  .  c  om
 * @return             parsed object
 * @throws   ArithmeticException    on overflow
 */
public static double toDouble(Object obj) {

    /* Switch on class and convert to double */

    String type = obj.getClass().getSimpleName();
    double parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) obj;
        parsed = by.doubleValue();
        break;

    case "Short":
        Short sh = (Short) obj;
        parsed = sh.doubleValue();
        break;

    case "Integer":
        Integer in = (Integer) obj;
        parsed = in.doubleValue();
        break;

    case "Long":
        Long lo = (Long) obj;
        parsed = lo.doubleValue();
        break;

    case "Float":
        Float fl = (Float) obj;
        parsed = fl.doubleValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) obj;
        if (!OverFlowUtil.doubleOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + obj + " to a double.");
        }
        parsed = bi.doubleValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) obj;
        if (!OverFlowUtil.doubleOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + obj + " to a double.");
        }
        parsed = bd.doubleValue();
        break;

    case "Double":
        Double db = (Double) obj;
        parsed = db.doubleValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Safely converts a number to a double. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Number    number to parse//from   w w w. ja va  2s.com
 * @return             parsed number
 * @throws   ArithmeticException    on overflow
 */
public static double toDouble(Number number) {

    /* Switch on class and convert to double */

    String type = number.getClass().getSimpleName();
    double parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) number;
        parsed = by.doubleValue();
        break;

    case "Short":
        Short sh = (Short) number;
        parsed = sh.doubleValue();
        break;

    case "Integer":
        Integer in = (Integer) number;
        parsed = in.doubleValue();
        break;

    case "Long":
        Long lo = (Long) number;
        parsed = lo.doubleValue();
        break;

    case "Float":
        Float fl = (Float) number;
        parsed = fl.doubleValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) number;
        if (!OverFlowUtil.doubleOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bi.doubleValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) number;
        if (!OverFlowUtil.doubleOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bd.doubleValue();
        break;

    case "Double":
        Double db = (Double) number;
        parsed = db.doubleValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.ranking.FrequencyBased.java

/**
 * Calculates the weight for a split/*w  ww  .  jav  a2  s  .  c  o  m*/
 * @param split
 * @return
 */
private float calcRank(Split split) {
    BigInteger result = new BigInteger("1");

    for (SplitElement elem : split.getSplits()) {
        result = result.multiply(this.freq(elem));
    }

    return (float) Math.pow(result.doubleValue(), 1f / (double) split.getSplits().size());
}

From source file:cc.redberry.core.number.Numeric.java

@Override
public Numeric multiply(BigInteger bg) {
    checkNotNull(bg);// w  ww.j ava  2  s  .co  m
    //FUTURE bg.doubleValue() is very unefficient operation
    return multiply(bg.doubleValue());
}

From source file:cc.redberry.core.number.Numeric.java

@Override
public Numeric add(BigInteger bg) {
    checkNotNull(bg);//from   ww  w  .  j av a2 s.com
    //FUTURE fraction.doubleValue() is very unefficient operation
    return add(bg.doubleValue());
}