2024-09-13 16:41:31 -05:00
|
|
|
shift := 31
|
2024-08-30 10:22:13 -05:00
|
|
|
|
2024-09-13 16:41:31 -05:00
|
|
|
// following only work for: int
|
2024-08-20 07:03:39 -05:00
|
|
|
abs := fn(x: int): int {
|
2024-09-13 16:41:31 -05:00
|
|
|
mask := x >> shift
|
2024-08-20 07:03:39 -05:00
|
|
|
return (x ^ mask) - mask
|
|
|
|
}
|
|
|
|
min := fn(a: int, b: int): int {
|
2024-08-30 10:22:13 -05:00
|
|
|
c := a - b
|
2024-09-13 16:41:31 -05:00
|
|
|
return b + (c & c >> shift)
|
2024-08-30 10:22:13 -05:00
|
|
|
}
|
2024-09-13 16:41:31 -05:00
|
|
|
max := fn(a: int, b: uint): int {
|
2024-08-30 10:22:13 -05:00
|
|
|
c := a - b
|
2024-09-13 16:41:31 -05:00
|
|
|
return a - (c & c >> shift)
|
2024-08-20 07:03:39 -05:00
|
|
|
}
|