Java Double to Long doubleToLong(final double d)

Here you can find the source of doubleToLong(final double d)

Description

double To Long

License

Open Source License

Declaration

public static long doubleToLong(final double d) 

Method Source Code

//package com.java2s;
/*/*from ww w .jav  a  2  s . c  om*/
 * #%L
 * Cytoscape Equations API (equations-api)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2010 - 2013 The Cytoscape Consortium
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 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 Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */

public class Main {

    public static long doubleToLong(final double d) {
        if (d > Long.MAX_VALUE || d < Long.MIN_VALUE)
            throw new IllegalArgumentException(
                    "floating point value is too large to be converted to a Long.");

        double x = ((Double) d).longValue();
        if (x != d && d < 0.0)
            --x;

        return (long) x;
    }
}

Related

  1. doubleToLong(Double aVal)
  2. doubleToLong(double d)
  3. doubleToLong(double[] values)
  4. DoubleToLong_With_Little_Endian(double dd)
  5. doubleToLongArray(final double value)
  6. doubleToLongBits(double val)
  7. doubleToLongBits(double value)