Skip to content

Commit 653d78e

Browse files
fix: Big int handling (#1758)
1 parent eea2b13 commit 653d78e

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

packages/typegpu-color/src/oklab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const findGamutIntersection = tgpu.fn(
170170
[f32, f32, f32, f32, f32, LC],
171171
f32,
172172
)((a, b, L1, C1, L0, cusp) => {
173-
const FLT_MAX = f32(3.40282346e38);
173+
const FLT_MAX = 3.40282346e38;
174174

175175
// Find the intersection for upper and lower half separately
176176
let t = f32(0);

packages/typegpu/src/tgsl/generationHelpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ export function getTypeForIndexAccess(
168168
}
169169

170170
export function numericLiteralToSnippet(value: number): Snippet {
171+
if (value >= 2 ** 63 || value < -(2 ** 63)) {
172+
return snip(value, abstractFloat);
173+
}
171174
// WGSL AbstractInt uses 64-bit precision, but JS numbers are only safe up to 2^53 - 1.
172175
// Warn when values exceed this range to prevent precision loss.
173176
if (Number.isInteger(value)) {

packages/typegpu/tests/examples/individual/oklab.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('oklab example', () => {
136136
}
137137
138138
fn findGamutIntersection_13(a: f32, b: f32, L1: f32, C1: f32, L0: f32, cusp: LC_12) -> f32 {
139-
var FLT_MAX = 3.4028234663852886e+38f;
139+
var FLT_MAX = 3.40282346e+38;
140140
var t = 0f;
141141
if (((((L1 - L0) * cusp.C) - ((cusp.L - L0) * C1)) <= 0)) {
142142
t = ((cusp.C * L0) / ((C1 * cusp.L) + (cusp.C * (L0 - L1))));

0 commit comments

Comments
 (0)