From 737bccbd5eb454fb50552339940a5dc53dbf3c82 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 15 Aug 2022 16:31:43 +0100 Subject: [PATCH 1/2] Add `math.divmod` and `math.floor_divmod` --- core/math/math.odin | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/math/math.odin b/core/math/math.odin index 5a6115e55..380bad6e6 100644 --- a/core/math/math.odin +++ b/core/math/math.odin @@ -614,6 +614,25 @@ floor_mod :: proc "contextless" (x, y: $T) -> T 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) { shift :: F16_SHIFT mask :: F16_MASK From 208f168564c18b49deba1027ed5e2d96059e720d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 15 Aug 2022 16:31:59 +0100 Subject: [PATCH 2/2] Correct assignment --- core/math/math.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/math/math.odin b/core/math/math.odin index 380bad6e6..5f9c737ab 100644 --- a/core/math/math.odin +++ b/core/math/math.odin @@ -623,8 +623,8 @@ divmod :: #force_inline proc "contextless" (x, y: $T) -> (div, mod: T) floor_divmod :: #force_inline proc "contextless" (x, y: $T) -> (div, mod: T) where intrinsics.type_is_integer(T) { - div := x / y - mod := x % y + div = x / y + mod = x % y if (div > 0 && y < 0) || (mod < 0 && y > 0) { div -= 1 mod += y