Java Number Min Value min(double a, double b)

Here you can find the source of min(double a, double b)

Description

Binary min, without handling of special values.

License

Open Source License

Parameter

Parameter Description
a First value
b Second value

Return

minimum

Declaration

public static double min(double a, double b) 

Method Source Code

//package com.java2s;
/*/*from  ww  w .  j a  v  a2 s. c o  m*/
 This file is part of ELKI:
 Environment for Developing KDD-Applications Supported by Index-Structures
    
 Copyright (C) 2015
 Ludwig-Maximilians-Universit?t M?nchen
 Lehr- und Forschungseinheit f?r Datenbanksysteme
 ELKI Development Team
    
 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/>.
 */

public class Main {
    /**
     * Binary min, <i>without</i> handling of special values.
     *
     * Because of the lack of special case handling, this is faster than
     * {@link Math#min}. But usually, it should be written inline as
     * {@code (a <= b) ? a : b}
     *
     * The result is asymmetric in case of {@code Double.NaN}:<br />
     * {@code MathUtil.min(Double.NaN, 1.)} is 1, but <br />
     * {@code MathUtil.min(1., Double.NaN)} is {@code Double.NaN}.
     *
     * @param a First value
     * @param b Second value
     * @return minimum
     */
    public static double min(double a, double b) {
        return a <= b ? a : b;
    }

    /**
     * Ternary min, <i>without</i> handling of special values.
     *
     * Because of the lack of special case handling, this is faster than
     * {@link Math#min}. But usually, it should be written inline.
     *
     * @param a First value
     * @param b Second value
     * @param c Third value
     * @return minimum
     */
    public static double min(double a, double b, double c) {
        return a <= b ? (a <= c ? a : c) : (b <= c ? b : c);
    }

    /**
     * Quadrary min, <i>without</i> handling of special values.
     *
     * Because of the lack of special case handling, this is faster than
     * {@link Math#min}. But usually, it should be written inline.
     *
     * @param a First value
     * @param b Second value
     * @param c Third value
     * @param d Fourth value
     * @return minimum
     */
    public static double min(double a, double b, double c, double d) {
        return a <= b ? //
                a <= c ? (a <= d ? a : d) : (c <= d ? c : d) //
                : //
                b <= c ? (b <= d ? b : d) : (c <= d ? c : d);
    }

    /**
     * Binary min, <i>without</i> handling of special values.
     *
     * Because of the lack of special case handling, this is faster than
     * {@link Math#min}. But usually, it should be written inline.
     *
     * @param a First value
     * @param b Second value
     * @return minimum
     */
    public static int min(int a, int b) {
        return a <= b ? a : b;
    }

    /**
     * Ternary min, <i>without</i> handling of special values.
     *
     * Because of the lack of special case handling, this is faster than
     * {@link Math#min}. But usually, it should be written inline.
     *
     * @param a First value
     * @param b Second value
     * @param c Third value
     * @return minimum
     */
    public static int min(int a, int b, int c) {
        return a <= b ? (a <= c ? a : c) : (b <= c ? b : c);
    }

    /**
     * Quadrary min, <i>without</i> handling of special values.
     *
     * Because of the lack of special case handling, this is faster than
     * {@link Math#min}. But usually, it should be written inline.
     *
     * @param a First value
     * @param b Second value
     * @param c Third value
     * @param d Fourth value
     * @return minimum
     */
    public static int min(int a, int b, int c, int d) {
        return a <= b ? //
                a <= c ? (a <= d ? a : d) : (c <= d ? c : d) //
                : //
                b <= c ? (b <= d ? b : d) : (c <= d ? c : d);
    }
}

Related

  1. findMinAngularDistance(double angle1, double angle2)
  2. min( final double p_first, final double p_second, final double p_third )
  3. min(Comparable c1, Comparable c2)
  4. min(Comparable c1, Comparable c2)
  5. min(Double a, Double b)
  6. min(double a, double b)
  7. min(double a, double b)
  8. min(double a, double b)
  9. min(double a, double b, boolean backward)