Here you can find the source of roundToNearestEven(int mantissa, int numOfBitsToRoundOff)
Parameter | Description |
---|---|
mantissa | mantissa |
numOfBitsToRoundOff | number of bits to be rounded off |
public static int roundToNearestEven(int mantissa, int numOfBitsToRoundOff)
//package com.java2s; public class Main { /**/*from ww w .ja v a 2 s.com*/ * Rounds the mantissa with bitsRoundOff * * @param mantissa mantissa * @param numOfBitsToRoundOff number of bits to be rounded off * @return the result * * */ public static int roundToNearestEven(int mantissa, int numOfBitsToRoundOff) { assert (numOfBitsToRoundOff < 32); int a = 1 << (numOfBitsToRoundOff - 1) - 1; int b = (mantissa >> numOfBitsToRoundOff) & 1; return (mantissa + a + b) >> numOfBitsToRoundOff; } }