Java Double Number Clamp clampRoundShort(double in)

Here you can find the source of clampRoundShort(double in)

Description

Clamps and rounds a number to the range supported by short data type.

License

Open Source License

Declaration

public static final short clampRoundShort(double in) 

Method Source Code

//package com.java2s;
/*//from  w  w w .  j  a  va  2s . c  o  m
 * $RCSfile: ImageUtil.java,v $
 *
 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
 *
 * Use is subject to license terms.
 *
 * $Revision: 1.2 $
 * $Date: 2006/07/21 20:53:28 $
 * $State: Exp $
 */

public class Main {
    /**
     * Clamps and rounds a number to the range supported by
     * short data type. The input number is float.
     */
    public static final short clampRoundShort(float in) {
        return (in > Short.MAX_VALUE ? Short.MAX_VALUE
                : (in >= Short.MIN_VALUE ? (short) Math.floor(in + 0.5F) : Short.MIN_VALUE));
    }

    /**
     * Clamps and rounds a number to the range supported by
     * short data type. The input number is double.
     */
    public static final short clampRoundShort(double in) {
        return (in > Short.MAX_VALUE ? Short.MAX_VALUE
                : (in >= Short.MIN_VALUE ? (short) Math.floor(in + 0.5) : Short.MIN_VALUE));
    }
}

Related

  1. clampedLerp(double lowerBnd, double upperBnd, double slide)
  2. clampFloat(double in)
  3. clampMax(double val, double max)
  4. clampMax(final double MAX, final double VALUE)
  5. clampMin(double input, double min)
  6. clampToPercentageOrNAN(double input)
  7. clampVector(double d)