ableos/sysdata/libraries/stn/src/math.hb

16 lines
406 B
Plaintext
Raw Normal View History

2024-10-12 15:39:09 -05:00
abs := fn($Expr: type, x: Expr): Expr {
mask := x >> @intcast(@sizeof(Expr) - 1)
2024-08-20 07:03:39 -05:00
return (x ^ mask) - mask
}
2024-10-12 15:39:09 -05:00
min := fn($Expr: type, a: Expr, b: Expr): Expr {
c := a - b
2024-10-12 15:39:09 -05:00
return b + (c & c >> @intcast(@sizeof(Expr) - 1))
}
2024-10-12 15:39:09 -05:00
max := fn($Expr: type, a: Expr, b: Expr): Expr {
c := a - b
2024-10-12 15:39:09 -05:00
return a - (c & c >> @intcast(@sizeof(Expr) - 1))
}
Vec2 := fn($Expr: type): type {
return struct {x: Expr, y: Expr}
2024-08-20 07:03:39 -05:00
}