Java Double Number Clamp clamp(double value, double min, double max)

Here you can find the source of clamp(double value, double min, double max)

Description

clamp

License

Open Source License

Parameter

Parameter Description
value a parameter
min a parameter
max a parameter

Declaration

public static double clamp(double value, double min, double max) 

Method Source Code

//package com.java2s;
/*//from   www.  jav a  2s.  c  o m
 * Copyright (c) 2015 Westwood Robotics <code.westwoodrobotics@gmail.com>.
 * 
 * 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.
 */

public class Main {
    /**
     * 
     * @param value
     * @param min
     * @param max
     * @return
     */
    public static double clamp(double value, double min, double max) {
        return Math.max(Math.min(value, max), min);
    }

    /**
     * 
     * @param value
     * @param min
     * @param max
     * @return
     */
    public static float clamp(float value, float min, float max) {
        return Math.max(Math.min(value, max), min);
    }

    /**
     * 
     * @param value
     * @param min
     * @param max
     * @return
     */
    public static int clamp(int value, int min, int max) {
        return Math.max(Math.min(value, max), min);
    }
}

Related

  1. clamp(double value, double low, double high)
  2. clamp(double value, double low, double high)
  3. clamp(double value, double min, double max)
  4. clamp(double value, double min, double max)
  5. clamp(double value, double min, double max)
  6. clamp(double value, final double min, final double max)
  7. clamp(double var1, double var2, double var3)
  8. clamp(double weight, double lowerBound, double upperBound)
  9. clamp(double x, double low, double high)