Java Double Number Clamp clamp(double value, double low, double high)

Here you can find the source of clamp(double value, double low, double high)

Description

Clamp a value to be within the provided range.

License

Open Source License

Parameter

Parameter Description
value the value to clamp
low the low end of the range
high the high end of the range

Return

the clamped value

Declaration

public static double clamp(double value, double low, double high) 

Method Source Code

//package com.java2s;
/*/*  ww w .j a  va2 s.  c  o m*/
 *  Copyright (c) 2013, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */

public class Main {
    /**
     * Clamp a value to be within the provided range.
     * @param value the value to clamp
     * @param low the low end of the range
     * @param high the high end of the range
     * @return the clamped value
     */
    public static double clamp(double value, double low, double high) {
        return Math.min(Math.max(value, low), high);
    }

    public static int clamp(int value, int low, int high) {
        return Math.min(Math.max(value, low), high);
    }
}

Related

  1. clamp(double val, double min, double max)
  2. clamp(double val, double min, double max)
  3. clamp(double value)
  4. clamp(double value)
  5. clamp(double value, double low, double high)
  6. clamp(double value, double low, double high)
  7. clamp(double value, double min, double max)
  8. clamp(double value, double min, double max)
  9. clamp(double value, double min, double max)