2023-05-23 02:08:34 +02:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
pub fn max(a: anytype, b: anytype) @TypeOf(a, b) {
|
|
|
|
return @max(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn max_int(comptime int: std.builtin.Type.Int) comptime_int {
|
|
|
|
const bit_count = int.bits;
|
2023-04-19 01:25:35 +02:00
|
|
|
|
|
|
|
if (bit_count == 0) return 0;
|
|
|
|
|
2023-07-10 02:10:56 +02:00
|
|
|
return (1 << (bit_count - @intFromBool(int.signedness == .signed))) - 1;
|
2023-04-19 01:25:35 +02:00
|
|
|
}
|
|
|
|
|
2023-05-23 02:08:34 +02:00
|
|
|
pub fn min(a: anytype, b: anytype) @TypeOf(a, b) {
|
|
|
|
return @min(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn min_int(comptime int: std.builtin.Type.Int) comptime_int {
|
|
|
|
if (int.signedness == .unsigned) return 0;
|
|
|
|
|
|
|
|
const bit_count = int.bits;
|
|
|
|
|
|
|
|
if (bit_count == 0) return 0;
|
|
|
|
|
|
|
|
return -(1 << (bit_count - 1));
|
2023-04-19 01:25:35 +02:00
|
|
|
}
|
2023-05-24 01:22:12 +02:00
|
|
|
|
|
|
|
pub fn wrap(value: anytype, lower: anytype, upper: anytype) @TypeOf(value, lower, upper) {
|
|
|
|
const range = upper - lower;
|
|
|
|
|
|
|
|
return if (range == 0) lower else lower + @mod((@mod((value - lower), range) + range), range);
|
|
|
|
}
|