Skip to content
2 changes: 1 addition & 1 deletion packages/typegpu-color/src/oklab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const findGamutIntersection = tgpu.fn(
[f32, f32, f32, f32, f32, LC],
f32,
)((a, b, L1, C1, L0, cusp) => {
const FLT_MAX = f32(3.40282346e38);
const FLT_MAX = 3.40282346e38;

// Find the intersection for upper and lower half separately
let t = f32(0);
Expand Down
3 changes: 3 additions & 0 deletions packages/typegpu/src/tgsl/generationHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ export function getTypeForIndexAccess(
}

export function numericLiteralToSnippet(value: number): Snippet {
if (Math.abs(value) > 2 ** 63) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure about $2^{63}$ imo limit should be $2^{53}$.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my bad $2^{63}$ is correct, but we should check for $\geq$

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about value >= 2 ** 63 || value < -(2 ** 63)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yea, forgot that we take Math.abs

return snip(value, abstractFloat);
}
// WGSL AbstractInt uses 64-bit precision, but JS numbers are only safe up to 2^53 - 1.
// Warn when values exceed this range to prevent precision loss.
if (Number.isInteger(value)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/tests/examples/individual/oklab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('oklab example', () => {
}

fn findGamutIntersection_13(a: f32, b: f32, L1: f32, C1: f32, L0: f32, cusp: LC_12) -> f32 {
var FLT_MAX = 3.4028234663852886e+38f;
var FLT_MAX = 3.40282346e+38;
var t = 0f;
if (((((L1 - L0) * cusp.C) - ((cusp.L - L0) * C1)) <= 0)) {
t = ((cusp.C * L0) / ((C1 * cusp.L) + (cusp.C * (L0 - L1))));
Expand Down