mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-24 03:05:17 +02:00
ddb17f61cb
Cadence is working while speed still requires the wheel size.
31 lines
615 B
Java
31 lines
615 B
Java
package de.dennisguse.opentracks.util;
|
|
|
|
public class UintUtils {
|
|
|
|
public static int UINT16_MAX = 0xFFFF;
|
|
public static long UINT32_MAX = 0xFFFFFFFFL;
|
|
|
|
private UintUtils() {
|
|
}
|
|
|
|
/**
|
|
* Computes a - b for UINT with overflow (b < a).
|
|
*
|
|
* @return diff or -1 (invalid)
|
|
*/
|
|
public static long diff(long a, long b, final long UINT_MAX) {
|
|
if (a < 0 || b < 0) {
|
|
return -1;
|
|
}
|
|
if (a > UINT_MAX && b > UINT_MAX) {
|
|
return -1;
|
|
}
|
|
|
|
if (a >= b) {
|
|
return a - b;
|
|
}
|
|
|
|
return (UINT_MAX - b) + a;
|
|
}
|
|
}
|