Java Number Range Create range(double value1, double value2)

Here you can find the source of range(double value1, double value2)

Description

Calculates the range of any two real numbers.

License

Open Source License

Parameter

Parameter Description
value1 a parameter
value2 a parameter

Return

double

Declaration

public static double range(double value1, double value2) 

Method Source Code

//package com.java2s;
/**/*from w  w  w. j av a2s  . c om*/
* PlotUtilities.java
*
*
* Cytobank (TM) is server and client software for web-based management, analysis,
* and sharing of flow cytometry data.
*
* Copyright (C) 2009 Cytobank, Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Cytobank, Inc.
* 659 Oak Grove Avenue #205
* Menlo Park, CA 94025
*
* http://www.cytobank.org
*/

public class Main {
    /**
    * Calculates the range of any two real numbers.
    * Accepts input values in any order
    * @param value1
    * @param value2
    * @return double
    */
    public static double range(double value1, double value2) {

        if (value1 != value2) {

            double min = Math.min(value1, value2);
            double max = Math.max(value1, value2);

            if ((min < 0) && (max <= 0)) {
                return Math.abs(min) - Math.abs(max);
            } else if ((min >= 0) && (max > 0)) {
                return Math.abs(max) - Math.abs(min);
            } else {
                return Math.abs(min) + Math.abs(max);
            }

        }

        // If value1 == value2 range is zero
        return 0;
    }
}

Related

  1. range(double a, double b, double step)
  2. range(double[] data, int to, int stride, int numElementsEachStride)
  3. range(double[] min, double[] max, double[] min2, double[] max2)
  4. range(double[] vals)
  5. range(final int max)