mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Add math.divmod and math.floor_divmod
This commit is contained in:
@@ -614,6 +614,25 @@ floor_mod :: proc "contextless" (x, y: $T) -> T
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
divmod :: #force_inline proc "contextless" (x, y: $T) -> (div, mod: T)
|
||||||
|
where intrinsics.type_is_integer(T) {
|
||||||
|
div = x / y
|
||||||
|
mod = x % y
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
floor_divmod :: #force_inline proc "contextless" (x, y: $T) -> (div, mod: T)
|
||||||
|
where intrinsics.type_is_integer(T) {
|
||||||
|
div := x / y
|
||||||
|
mod := x % y
|
||||||
|
if (div > 0 && y < 0) || (mod < 0 && y > 0) {
|
||||||
|
div -= 1
|
||||||
|
mod += y
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
modf_f16 :: proc "contextless" (x: f16) -> (int: f16, frac: f16) {
|
modf_f16 :: proc "contextless" (x: f16) -> (int: f16, frac: f16) {
|
||||||
shift :: F16_SHIFT
|
shift :: F16_SHIFT
|
||||||
mask :: F16_MASK
|
mask :: F16_MASK
|
||||||
|
|||||||
Reference in New Issue
Block a user