1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/sysdata/libraries/stn/src/math.hb

15 lines
270 B
Plaintext
Raw Normal View History

2024-09-13 16:41:31 -05:00
shift := 31
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 {
c := a - b
2024-09-13 16:41:31 -05:00
return b + (c & c >> shift)
}
2024-09-13 16:41:31 -05:00
max := fn(a: int, b: uint): int {
c := a - b
2024-09-13 16:41:31 -05:00
return a - (c & c >> shift)
2024-08-20 07:03:39 -05:00
}