Java Double Number Clamp clampToPercentageOrNAN(double input)

Here you can find the source of clampToPercentageOrNAN(double input)

Description

clamp To Percentage Or NAN

License

Open Source License

Parameter

Parameter Description
input a percentage value

Return

NaN if the value was NaN, 0% if <0%, 100% if >100%, otherwise the original value

Declaration

public static double clampToPercentageOrNAN(double input) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w  w  w .  j  a v  a2s.c om*/
     * One hundred percent, as represented internally.
     */
    public static final double ONE_HUNDRED_PERCENT_CPU_VALUE = 1.0;

    /**
     * @param input a percentage value
     * @return NaN if the value was NaN, 0% if <0%, 100% if >100%, otherwise the original value
     */
    public static double clampToPercentageOrNAN(double input) {
        // apply fallbacks in case the input is invalid or "unusual"
        if (Double.isNaN(input)) {
            return Double.NaN;
        } else if (input < 0.0) {
            return 0.0;
        } else if (input > ONE_HUNDRED_PERCENT_CPU_VALUE) {
            return ONE_HUNDRED_PERCENT_CPU_VALUE;
        } else {
            return input;
        }
    }
}

Related

  1. clampFloat(double in)
  2. clampMax(double val, double max)
  3. clampMax(final double MAX, final double VALUE)
  4. clampMin(double input, double min)
  5. clampRoundShort(double in)
  6. clampVector(double d)