Java Number Min Value min(Number n0, Number n1)

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

Description

Returns the minimum (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 minimum

Declaration

static Number min(Number n0, Number n1) 

Method Source Code

//package com.java2s;
/*//from  ww  w.  ja v  a2  s  .co m
 * 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 minimum (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 minimum
     */
    static Number min(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.min(d0, d1);
    }
}

Related

  1. min(Integer a, Integer b)
  2. min(Integer i1, Integer i2)
  3. min(long m, long n)
  4. min(long x, long y)
  5. min(Number a, Number b)
  6. min(Number num1, Number num2)
  7. Min(Object in)
  8. min(Object o1, Object o2)
  9. min(String a, String b)