Here you can find the source of roundToWord(long value)
Parameter | Description |
---|---|
value | the value to be rounded up to the nearest multiple of four |
private static long roundToWord(long value)
//package com.java2s; /*/*from w w w . j a v a 2s . c o m*/ * Copyright (c) 2013, the Dart project authors. * * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.eclipse.org/legal/epl-v10.html * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ public class Main { /** * An array containing the amount by which a value must be incremented in order to round it up to * the nearest multiple of four when the index into the array is the remainder after dividing the * value by four. */ private static final long[] ROUND_UP_AMOUNT = { 0L, 3L, 2L, 1L }; /** * Return the smallest multiple of four (4) that is greater than or equal to the given value. * * @param value the value to be rounded up to the nearest multiple of four * @return the smallest multiple of four that is greater than or equal to the value */ private static long roundToWord(long value) { return value + ROUND_UP_AMOUNT[(int) (value % 4)]; } }