Java Float Number Clamp clampRoundByte(float in)

Here you can find the source of clampRoundByte(float in)

Description

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

License

Open Source License

Declaration

public static final byte clampRoundByte(float in) 

Method Source Code

//package com.java2s;
/*//from  www .java  2 s . 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
     * byte data type. The input number is float.
     */
    public static final byte clampRoundByte(float in) {
        return (in > 0xFF ? (byte) 0xFF : (in >= 0 ? (byte) (in + 0.5F) : (byte) 0));
    }

    /**
     * Clamps and rounds a number to the range supported by
     * byte data type. The input number is double.
     */
    public static final byte clampRoundByte(double in) {
        return (in > 0xFF ? (byte) 0xFF : (in >= 0 ? (byte) (in + 0.5) : (byte) 0));
    }
}

Related

  1. clampFloat(float value, float minimum, float maximum)
  2. clampLevel(float level)
  3. clampLevel(float level)
  4. clampNumberFromTime(long ms, float seconds)
  5. clampPercentage(float value)
  6. clampToMinusOneToOne(float value)
  7. clampToPositiveNonZero(float value)
  8. clampTrigo(float value, float min, float max)
  9. clampWithMod(float parFloat, float parMax)