Java Number Max Value max(double d1, double d2)

Here you can find the source of max(double d1, double d2)

Description

Returns the maximum value of d1 and d2.

License

Open Source License

Declaration

public static double max(double d1, double d2) 

Method Source Code

//package com.java2s;
/*//  ww w  . j a va 2 s.c  o m
Copyright ? 2008 Brent Boyer
    
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 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 Lesser GNU General Public License for more details.
    
You should have received a copy of the Lesser GNU General Public License along with this program (see the license directory in this project).  If not, see <http://www.gnu.org/licenses/>.
*/

public class Main {
    /**
    * Returns the maximum value of d1 and d2.
    * This method differs from {@link Math#max Math.max} solely in how it handles NaN inputs:
    * it only returns NaN if both args are NaN;
    * if exactly one arg is NaN, the other arg is always returned regardless of its value;
    * and if neither arg is NaN then the result of Math.max(d1, d2) is returned.
    * In contrast, Math.max always returns NaN if either arg is NaN.
    */
    public static double max(double d1, double d2) {
        if (Double.isNaN(d1))
            return d2;
        else if (Double.isNaN(d2))
            return d1;
        else
            return Math.max(d1, d2);
    }
}

Related

  1. max(double a, double b)
  2. max(double a, double b)
  3. max(double a, double b)
  4. max(double a, double b, double c, double d)
  5. max(double a, double b, double c, double d)
  6. max(double first, double second, double third, double fourth)
  7. max(double n1, double n2, double n3)
  8. max(double no1, double no2, double no3)
  9. max(double num1, double num2, double num3)