All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.unit16.z.math.Rounding Maven / Gradle / Ivy

package com.unit16.z.math;

public final class Rounding {
	
	private Rounding() {}
	
	/**
	 * Symmetric rounding around zero. I.e. rounding towards/away from zero rather than rounding
	 * towards floor(v) / ceil(v).
	 * 
	 * For all v:
	 * -symmetric(v) == symmetric(-v)
	 * 
	 * @param v input value
	 * @return rounded value
	 */
	public static long symmetric(double v)
	{
		final long rva = Math.round(Math.abs(v));
		
		return v >= 0 ? rva : -rva;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy