When I was reading System.nanoTime() API in Java. I found this line:
one should use t1 - t0 < 0, not t1 < t0, because of the possibility of numerical overflow.
http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#nanoTime()
To compare two nanoTime values
long t0 = System.nanoTime(); ... long t1 = System.nanoTime();
one should use t1 - t0 < 0, not t1 < t0, because of the possibility of numerical overflow.
I want to know why t1 - t0 < 0
is preferable way to prevent overflow.
Because I read from some other thread that A < B
is more preferable than A - B < 0
.
Java Integer compareTo() - why use comparison vs. subtraction?
These two things make contradiction.
See Question&Answers more detail:os