doubleCompare function
Compare two double-precision values.
Returns an integer that indicates whether value
is less than, equal to, or greater than other
.
value
less than other
will return -1
value
equal to other
will return 0
value
greater than other
will return 1
If value
or other
is not finite (NaN
or infinity), throws an UnsupportedError.
Implementation
int doubleCompare(double value, double other,
{double precision = precisionErrorTolerance}) {
if (value.isNaN || other.isNaN) {
throw UnsupportedError('Compared with Infinity or NaN');
}
final double n = value - other;
if (n.abs() < precision) {
return 0;
}
return n < 0 ? -1 : 1;
}