Java Utililty Methods Number Sign

List of utility methods to do Number Sign

Description

The list of methods to do Number Sign are organized into topic(s).

Method

intsignum(float val)
signum
return (int) Math.signum(val);
intsignum(int a)
signum
if (a == 0)
    return 0;
return a < 0 ? -1 : 1;
intsignum(int v)
Returns the sign of a number: either -1, 0 or 1.
return v < 0 ? -1 : v > 0 ? 1 : 0;
intsignum(long diff)
Collapse number down to +1 0 or -1 depending on sign.
if (diff > 0)
    return 1;
if (diff < 0)
    return -1;
else
    return 0;
intsignum(long l)
signum
if (l > 0) {
    return 1;
} else if (l < 0) {
    return -1;
} else {
    return 0;
intsignum(long number)
signum
if (number < 0)
    return -1;
else if (number == 0)
    return 0;
else
    return 1;
doublesignumEps(double val, double eps)
Signum functions with epsilon for floating point imprecision
if (val < eps && val > -eps)
    return 0;
else
    return Math.signum(val);