Java Number Max Value max(Number n0, Number n1)

Here you can find the source of max(Number n0, Number n1)

Description

Returns the maximum (double) of the given values.

If either value is null, then the other value will be returned.

License

Open Source License

Parameter

Parameter Description
n0 The first value
n1 The second value

Return

The maximum

Declaration

static Number max(Number n0, Number n1) 

Method Source Code

//package com.java2s;
/*/*w ww  .jav a2  s  .c om*/
 * www.javagl.de - Viewer - Functions
 *
 * Copyright (c) 2013-2015 Marco Hutter - http://www.javagl.de
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

public class Main {
    /**
     * Returns the maximum (double) of the given values.<br> 
     * <br>
     * If either value is <code>null</code>, then the other value will be 
     * returned. If both values are <code>null</code>, then <code>null</code>
     * will be returned. If neither value is <code>null</code>, and either 
     * value is NaN, then the other value will be returned. If both values 
     * are NaN, then NaN will be returned.
     * 
     * @param n0 The first value
     * @param n1 The second value 
     * @return The maximum
     */
    static Number max(Number n0, Number n1) {
        if (n0 == null) {
            return n1;
        }
        if (n1 == null) {
            return n0;
        }
        double d0 = n0.doubleValue();
        double d1 = n1.doubleValue();
        if (Double.isNaN(d0)) {
            return d1;
        }
        if (Double.isNaN(d1)) {
            return d0;
        }
        return Math.max(d0, d1);
    }
}

Related

  1. max(Integer a, Integer b)
  2. max(Integer i1, Integer i2)
  3. max(Iterable nums)
  4. max(long a, long b)
  5. max(Number a, Number b)
  6. max(Number num1, Number num2)
  7. Max(Object in)
  8. max(Object o1, Object o2)
  9. max(String a, String b)