public final class Round extends Object
| Modifier and Type | Method and Description |
|---|---|
static BigDecimal |
ceiling(BigDecimal x) |
static BigDecimal |
ceiling(BigDecimal x,
BigDecimal baseStep) |
static double |
ceiling(double x)
Rounds the number to the least integer
n, such that x ≤ n. |
static double |
ceiling(double x,
double baseStep)
Rounds the number to the least integral multiple of the base step value, which is greater than or equal to the
input value.
|
static BigDecimal |
floor(BigDecimal x) |
static BigDecimal |
floor(BigDecimal x,
BigDecimal baseStep) |
static double |
floor(double x)
Rounds the number to the greatest integer
n, such that n ≤ x. |
static double |
floor(double x,
double baseStep)
Rounds the number to the greatest integral multiple of the base step value, which is less than or equal to the
input value.
|
static BigDecimal |
halfDown(BigDecimal x) |
static BigDecimal |
halfDown(BigDecimal x,
BigDecimal baseStep) |
static double |
halfDown(double x)
Rounds the number to a nearest integer.
|
static double |
halfDown(double x,
double baseStep)
Rounds the number to a nearest integral multiple of the base step value.
|
static BigDecimal |
halfFromZero(BigDecimal x) |
static BigDecimal |
halfFromZero(BigDecimal x,
BigDecimal baseStep) |
static double |
halfFromZero(double x)
Rounds the number to a nearest integer.
|
static double |
halfFromZero(double x,
double baseStep)
Rounds the number to a nearest integral multiple of the base step value.
|
static double |
halfFromZeroToEven(double x) |
static BigDecimal |
halfTowardsZero(BigDecimal x) |
static BigDecimal |
halfTowardsZero(BigDecimal x,
BigDecimal baseStep) |
static double |
halfTowardsZero(double x)
Rounds the number to a nearest integer.
|
static double |
halfTowardsZero(double x,
double baseStep)
Rounds the number to a nearest integral multiple of the base step value.
|
static BigDecimal |
halfUp(BigDecimal x) |
static BigDecimal |
halfUp(BigDecimal x,
BigDecimal baseStep) |
static double |
halfUp(double x)
Rounds the number to a nearest integer.
|
static double |
halfUp(double x,
double baseStep)
Rounds the number to a nearest integral multiple of the base step value.
|
static double |
partFromMidpoint(double x,
double baseStep,
double splitFraction,
double midpoint)
This function provides further generalization of rounding.
|
static double |
partFromZero(double x,
double baseStep,
double splitFraction)
This function generalizes
halfFromZero(double, double), where the "decision point" between two base step
multiples is not exactly in the middle between them, but is specified as an arbitrary fraction. |
static double |
partTowardsMidpoint(double x,
double baseStep,
double splitFraction,
double midpoint) |
static double |
partTowardsZero(double x,
double baseStep,
double splitFraction)
This function generalizes
halfTowardsZero(double, double), where the "decision point" between two base
step multiples is not exactly in the middle between them, but is specified as an arbitrary fraction. |
static BigDecimal |
truncFromZero(BigDecimal x) |
static BigDecimal |
truncFromZero(BigDecimal x,
BigDecimal baseStep) |
static double |
truncFromZero(double x)
Rounds the number to the nearest integer, absolute value of which is greater than or equal to absolute value of
the source number.
|
static double |
truncFromZero(double x,
double baseStep)
Rounds the number to the nearest integral multiple of the base step value, which is not closer to zero than the
source value.
|
static BigDecimal |
truncTowardsZero(BigDecimal x) |
static BigDecimal |
truncTowardsZero(BigDecimal x,
BigDecimal baseStep) |
static double |
truncTowardsZero(double x)
Rounds the number to the nearest integer, absolute value of which is less than or equal to absolute value of the
source number.
|
static double |
truncTowardsZero(double x,
double baseStep)
Rounds the number to the nearest integral multiple of the base step value, which is not further to zero than the
source value.
|
public static double floor(double x)
n, such that n ≤ x. Special cases are:
x = NaN: the result is NaN
x is positive or negative infinity: the result is unchanged
x - a numberxMath.floor(double)public static BigDecimal floor(BigDecimal x)
public static double floor(double x,
double baseStep)
floor(27.5, 10.0) will return value 20.0. Special
cases:
x = NaN: the result is NaN
x is positive or negative infinity: the result is unchanged
The base step value must be positive (greater than 0) and finite.
Formal mathematical description is floor(x, b) = N*b, where N is an integer and
N*b ≤ x < (N+1)*b.
x - a numberbaseStep - the "precision" of roundingbaseStep less than or equal to xIllegalArgumentException - when the baseStep is negative, zero or infinitepublic static BigDecimal floor(BigDecimal x, BigDecimal baseStep)
public static double ceiling(double x)
n, such that x ≤ n. Special cases are:
x = NaN: the result is NaN
x is positive or negative infinity: the result is unchanged
x - a numberxMath.ceil(double)public static BigDecimal ceiling(BigDecimal x)
public static double ceiling(double x,
double baseStep)
ceiling(27.5, 10.0) will return value 30.0. Special
cases:
x = NaN: the result is NaN
x is positive or negative infinity: the result is unchanged
The base step value must be positive (greater than 0) and finite.
Formal mathematical description is ceiling(x, b) = N*b, where N is an integer and
(N-1)*b < x ≤ (N)*b.
x - a numberbaseStep - the "precision" of roundingbaseStep greater than or equal to xIllegalArgumentException - when the baseStep is negative, zero or infinitepublic static BigDecimal ceiling(BigDecimal x, BigDecimal baseStep)
public static double truncFromZero(double x)
x, truncFromZero(x) = n such that
abs(n)-1 < abs(x) ≤ abs(n) and sgn(n) =
sgn(x).
Special cases are:
x is zero (positive or negative): the result is unchanged
x = NaN: the result is NaN
x is positive or negative infinity: the result is unchanged
x - a numberx or further from 0.0 than the value
xpublic static BigDecimal truncFromZero(BigDecimal x)
public static double truncFromZero(double x,
double baseStep)
x, truncFromZero(x, b) = N*b such that
sgn(x) = sgn(N) and (abs(N)-1)*b < abs(x) ≤
abs(N)*b.
Special cases:
x is zero (positive or negative): the result is unchanged
x = NaN: the result is NaN
x is positive or negative infinity: the result is unchanged
The base step value must be positive (greater than 0) and finite.
x - a numberbaseStep - the "precision" of roundingIllegalArgumentException - when the baseStep is negative, zero or infinitepublic static BigDecimal truncFromZero(BigDecimal x, BigDecimal baseStep)
public static double truncTowardsZero(double x)
x (where abs(x) ≥ 1),
truncTowardsZero(x) = n such that abs(n) ≤ abs(x) ≤
abs(n)+1 and sgn(n) = sgn(x).
Special cases are:
x is zero (positive or negative): the result is unchanged
x = NaN: the result is NaN
x is positive or negative infinity: the result is unchanged
x - a numberx or closer to 0.0 than the value
xpublic static BigDecimal truncTowardsZero(BigDecimal x)
public static double truncTowardsZero(double x,
double baseStep)
x such that abs(x) ≥ 1,
truncTowardsZero(x, b) = N*b, where sgn(x) = sgn(N) and
abs(N)*b ≤ abs(x) < (abs(N)+1)*b.
Special cases:
x < base step: the result is zero (+0)
x < 0: the result is negative zero (-0)
x is zero (positive or negative): the result is unchanged
x = NaN: the result is NaN
x is positive or negative infinity: the result is unchanged
The base step value must be positive (greater than 0) and finite.
x - a numberbaseStep - the "precision" of roundingIllegalArgumentException - when the baseStep is negative, zero or infinitepublic static BigDecimal truncTowardsZero(BigDecimal x, BigDecimal baseStep)
public static double halfFromZero(double x)
Examples:
halfFromZero(3.3) = 3.0
halfFromZero(3.81) = 4.0
halfFromZero(-5.2) = -5.0
halfFromZero(-5.64) = -6.0
halfFromZero(1.5) = 2.0
halfFromZero(-1.5) = -2.0
x - a numberpublic static BigDecimal halfFromZero(BigDecimal x)
public static double halfFromZero(double x,
double baseStep)
x - a numberbaseStep - the "precision" of roundingIllegalArgumentException - when the baseStep is negative, zero or infinitepublic static BigDecimal halfFromZero(BigDecimal x, BigDecimal baseStep)
public static double halfTowardsZero(double x)
Examples:
halfTowardsZero(3.3) = 3.0
halfTowardsZero(3.81) = 4.0
halfTowardsZero(-5.2) = -5.0
halfTowardsZero(-5.64) = -6.0
halfTowardsZero(1.5) = 1.0
halfTowardsZero(-1.5) = -1.0
x - a numberpublic static BigDecimal halfTowardsZero(BigDecimal x)
public static double halfTowardsZero(double x,
double baseStep)
x - a numberbaseStep - the "precision" of roundingIllegalArgumentException - when the baseStep is negative, zero or infinitepublic static BigDecimal halfTowardsZero(BigDecimal x, BigDecimal baseStep)
public static double halfUp(double x)
Examples:
halfUp(3.3) = 3.0
halfUp(3.81) = 4.0
halfUp(-5.2) = -5.0
halfUp(-5.64) = -6.0
halfUp(1.5) = 2.0
halfUp(-1.5) = -1.0
x - a numberpublic static BigDecimal halfUp(BigDecimal x)
public static double halfUp(double x,
double baseStep)
x - a numberbaseStep - the "precision" of roundingIllegalArgumentException - when the baseStep is negative, zero or infinitepublic static BigDecimal halfUp(BigDecimal x, BigDecimal baseStep)
public static double halfDown(double x)
Examples:
halfDown(3.3) = 3.0
halfDown(3.81) = 4.0
halfDown(-5.2) = -5.0
halfDown(-5.64) = -6.0
halfDown(1.5) = 1.0
halfDown(-1.5) = -2.0
x - a numberpublic static BigDecimal halfDown(BigDecimal x)
public static double halfDown(double x,
double baseStep)
x - a numberbaseStep - the "precision" of roundingIllegalArgumentException - when the baseStep is negative, zero or infinitepublic static BigDecimal halfDown(BigDecimal x, BigDecimal baseStep)
public static double partFromZero(double x,
double baseStep,
double splitFraction)
halfFromZero(double, double), where the "decision point" between two base step
multiples is not exactly in the middle between them, but is specified as an arbitrary fraction.
Examples:
partFromZero(14.1, 2.2, 0.3) = 15.4, because the surrounding multiples of 14.1 are 13.2 (2.2*6)
and 15.4 (2.2*7), and the "0.3 decision point" between these multiples is 13.86
partFromZero(-8.3, 0.75, 0.05) = -9 , because the surrounding multiples of -8.3 are -8.25
(-11*0.75) and -9 (-12*0.75), and the "0.05 decision point" between these multiples is -8.2875.
The following relation is valid: partFromZero(x, base, 0.5) = halfFromZero(x, base).
x - a numberbaseStep - the "precision" of roundingsplitFraction - the relative position of "decision point" between the two consecutive integral multiples of
baseStepIllegalArgumentException - when the baseStep is negative, zero or infinite; or when the splitFraction
is not within interval (0, 1).public static double partTowardsZero(double x,
double baseStep,
double splitFraction)
halfTowardsZero(double, double), where the "decision point" between two base
step multiples is not exactly in the middle between them, but is specified as an arbitrary fraction.
For detailed explanation, see partFromZero(double, double, double).
x - a numberbaseStep - the "precision" of roundingsplitFraction - the relative position of "decision point" between the two consecutive integral multiples of
baseStepIllegalArgumentException - when the baseStep is negative, zero or infinite; or when the splitFraction
is not within interval (0, 1).public static double partFromMidpoint(double x,
double baseStep,
double splitFraction,
double midpoint)
x - baseStep - splitFraction - midpoint - public static double partTowardsMidpoint(double x,
double baseStep,
double splitFraction,
double midpoint)
x - baseStep - splitFraction - midpoint - public static double halfFromZeroToEven(double x)
x - Copyright © 2014 Boleslav Bobcik - Auderis. All rights reserved.