mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-05 19:13:07 +02:00
e9e48e4a79
Also forgot to fix tests. Fixes #810.
31 lines
725 B
Java
31 lines
725 B
Java
package de.dennisguse.opentracks.util;
|
|
|
|
public class UintUtils {
|
|
|
|
public static final int UINT16_MAX = 0xFFFF;
|
|
public static final long UINT32_MAX = 0xFFFFFFFFL;
|
|
|
|
private UintUtils() {
|
|
}
|
|
|
|
/**
|
|
* Computes a - b for UINT with overflow (b < a).
|
|
*
|
|
* @return diff
|
|
*/
|
|
public static long diff(long a, long b, final long UINT_MAX) {
|
|
if (a < 0 || b < 0) {
|
|
throw new RuntimeException("a or b cannot be less than zero.");
|
|
}
|
|
if (a > UINT_MAX || b > UINT_MAX) {
|
|
throw new RuntimeException("a or b are outside of the allowed range.");
|
|
}
|
|
|
|
if (a >= b) {
|
|
return a - b;
|
|
}
|
|
|
|
return (UINT_MAX - b) + a;
|
|
}
|
|
}
|