Java Double Number Round roundDown(int val, int shift)

Here you can find the source of roundDown(int val, int shift)

Description

Rounds an integer down to the nearest multiple of 2^shift .

License

Open Source License

Parameter

Parameter Description
val the integer to round down.
shift the power of two to round down to.

Return

the rounded integer.

Declaration

public static int roundDown(int val, int shift) 

Method Source Code

//package com.java2s;
/*/*from  ww w .  j  a v  a  2  s  . com*/
 * Copyright (c) 2009.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

public class Main {
    /**
     * Rounds an integer down to the nearest multiple of {@code 2^shift}.
     * Works with both positive and negative integers.
     * @param val the integer to round down.
     * @param shift the power of two to round down to.
     * @return the rounded integer.
     */
    public static int roundDown(int val, int shift) {
        return val >>> shift << shift;
    }
}

Related

  1. roundDown(double value, int gridSize)
  2. roundDown(final float realNumber)
  3. RoundDown(final T number)
  4. roundDown(int n, int m)
  5. roundDown(int number, int mod)
  6. roundDown(int val, int to)
  7. roundDown(long n, long m)
  8. roundDown(long size, long roundBoundary)
  9. roundDown(long val, long delta)