From 695aaa9f16b8aba1baa332c790c91f85ba0b5204 Mon Sep 17 00:00:00 2001 From: oxura Date: Sat, 29 Aug 2026 17:04:38 +0600 Subject: [PATCH 1/2] fix: preserve signed float intdiv operands --- packages/typegpu/src/std/numeric.ts | 2 +- packages/typegpu/tests/std/numeric/intdiv.test.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/typegpu/src/std/numeric.ts b/packages/typegpu/src/std/numeric.ts index 4471af4449..961f18eb94 100644 --- a/packages/typegpu/src/std/numeric.ts +++ b/packages/typegpu/src/std/numeric.ts @@ -1227,7 +1227,7 @@ function cpuIntdiv(lhs: number, rhs: number): number { export const intdiv = dualImpl({ name: 'intdiv', signature: (lhs, rhs) => { - const unified = unify([lhs, rhs], [u32, i32]); + const unified = unify([lhs, rhs], [i32, u32]); if (!unified) { throw new SignatureNotSupportedError([lhs, rhs], [u32, i32, abstractInt]); } diff --git a/packages/typegpu/tests/std/numeric/intdiv.test.ts b/packages/typegpu/tests/std/numeric/intdiv.test.ts index 21d38d61e8..da3349b474 100644 --- a/packages/typegpu/tests/std/numeric/intdiv.test.ts +++ b/packages/typegpu/tests/std/numeric/intdiv.test.ts @@ -95,6 +95,20 @@ test('intdiv with u32 mixed with i32', () => { `); }); +test('intdiv preserves signed runtime float operands', () => { + using warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); + + const foo = tgpu.fn([d.f32, d.f32], d.i32)((lhs, rhs) => std.intdiv(lhs, rhs)); + + expect(foo(-5.9, 2.1)).toBe(-2); + expect(tgpu.resolve([foo])).toMatchInlineSnapshot(` + "fn foo(lhs: f32, rhs: f32) -> i32 { + return (i32(lhs) / i32(rhs)); + }" + `); + expect(warnSpy.mock.calls).toHaveLength(2); +}); + test('intdiv coerces float arguments to integers', () => { using warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); From 5ea3145c5b455dc530d5f08dc08d43cd4e1830c2 Mon Sep 17 00:00:00 2001 From: oxura Date: Sat, 29 Aug 2026 17:19:21 +0600 Subject: [PATCH 2/2] fix: align intdiv error type ordering --- packages/typegpu/src/std/numeric.ts | 2 +- packages/typegpu/tests/std/numeric/intdiv.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/typegpu/src/std/numeric.ts b/packages/typegpu/src/std/numeric.ts index 961f18eb94..b839d67f90 100644 --- a/packages/typegpu/src/std/numeric.ts +++ b/packages/typegpu/src/std/numeric.ts @@ -1229,7 +1229,7 @@ export const intdiv = dualImpl({ signature: (lhs, rhs) => { const unified = unify([lhs, rhs], [i32, u32]); if (!unified) { - throw new SignatureNotSupportedError([lhs, rhs], [u32, i32, abstractInt]); + throw new SignatureNotSupportedError([lhs, rhs], [i32, u32, abstractInt]); } return { argTypes: unified, returnType: unified[0] }; }, diff --git a/packages/typegpu/tests/std/numeric/intdiv.test.ts b/packages/typegpu/tests/std/numeric/intdiv.test.ts index da3349b474..0c8385c792 100644 --- a/packages/typegpu/tests/std/numeric/intdiv.test.ts +++ b/packages/typegpu/tests/std/numeric/intdiv.test.ts @@ -150,7 +150,7 @@ test('intdiv throws with vector arguments', () => { - - fn*:undefined - fn*:() - - fn:intdiv: Unsupported data types: vec3u, abstractInt. Supported types are: u32, i32, abstractInt.] + - fn:intdiv: Unsupported data types: vec3u, abstractInt. Supported types are: i32, u32, abstractInt.] `); expect(() => @@ -166,6 +166,6 @@ test('intdiv throws with vector arguments', () => { - - fn*:undefined - fn*:() - - fn:intdiv: Unsupported data types: abstractInt, vec3i. Supported types are: u32, i32, abstractInt.] + - fn:intdiv: Unsupported data types: abstractInt, vec3i. Supported types are: i32, u32, abstractInt.] `); });