Here you can find the source of max(double a, double b)
Parameter | Description |
---|---|
a | First value |
b | Second value |
public static double max(double a, double b)
//package com.java2s; /*//from www .j a va 2 s . co 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 max, <i>without</i> handling of special values. * * Because of the lack of special case handling, this is faster than * {@link Math#max}. 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.max(Double.NaN, 1.)} is 1, but <br /> * {@code MathUtil.max(1., Double.NaN)} is {@code Double.NaN}. * * @param a First value * @param b Second value * @return Maximum */ public static double max(double a, double b) { return a >= b ? a : b; } /** * Ternary max, <i>without</i> handling of special values. * * Because of the lack of special case handling, this is faster than * {@link Math#max}. But usually, it should be written inline. * * @param a First value * @param b Second value * @param c Third value * @return Maximum */ public static double max(double a, double b, double c) { return a >= b ? (a >= c ? a : c) : (b >= c ? b : c); } /** * Quadrary max, <i>without</i> handling of special values. * * Because of the lack of special case handling, this is faster than * {@link Math#max}. But usually, it should be written inline. * * @param a First value * @param b Second value * @param c Third value * @param d Fourth value * @return Maximum */ public static double max(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 max. If possible, inline. * * @param a First value * @param b Second value * @return Maximum */ public static int max(int a, int b) { return a >= b ? a : b; } /** * Ternary max. If possible, inline. * * @param a First value * @param b Second value * @param c Third value * @return Maximum */ public static int max(int a, int b, int c) { return a >= b ? (a >= c ? a : c) : (b >= c ? b : c); } /** * Quadrary max, <i>without</i> handling of special values. * * Because of the lack of special case handling, this is faster than * {@link Math#max}. But usually, it should be written inline. * * @param a First value * @param b Second value * @param c Third value * @param d Fourth value * @return Maximum */ public static int max(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); } }