Calling the argument toNearest is misleading because when a non-default rounding rule is used, the result will not in general be the "nearest" value. It's also important to note that this implementation is only guaranteed to produce a correct result when nearest is a power of two (and even then it can overflow or underflow spuriously).