Skip to content

MathUtils: Fix large isPowerOfTwo values - #34459

Merged
Mugen87 merged 2 commits into
mrdoob:devfrom
lprnmns:codex/fix-is-power-of-two-large-values
Sep 8, 2026
Merged

Mugen87 merged 2 commits into
mrdoob:devfrom
lprnmns:codex/fix-is-power-of-two-large-values

Conversation

@lprnmns

@lprnmns lprnmns commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Problem

MathUtils.isPowerOfTwo() uses bitwise operators, which coerce numbers to 32 bits. Large non-powers such as 3 * 2 ** 32 therefore return true, despite the public API documenting a general number input.

Fix

Check for a positive integer and compare it exactly with the nearest numeric power of two. This avoids 32-bit truncation while keeping existing behavior.

Tests

  • npm run test-unit - 1315 passed, 1 todo
  • npm run test-unit-addons - 385 passed
  • npm run lint-core - passed
  • npm run build - passed
  • git diff --check - passed

Compatibility

The signature is unchanged. Behavior changes only for values the previous 32-bit coercion classified incorrectly.

Related issue

Independently reproduced on current dev; no matching issue or pull request was found.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
Core 389.13
102.11
389.18
102.13
+43 B
+20 B
WebGL 372.46
87.93
372.46
87.93
+0 B
+0 B
WebGPU 709.03
195.26
709.03
195.26
+0 B
+0 B
WebGPU Nodes 707.01
194.94
707.01
194.94
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 515.88
124.89
515.88
124.89
+0 B
+0 B
WebGPU 762.69
204.82
762.73
204.84
+43 B
+20 B
WebGPU Nodes 711.35
192.09
711.39
192.11
+43 B
+21 B

@Mugen87 Mugen87 modified the milestones: r187, r186 Sep 4, 2026
@Mugen87
Mugen87 merged commit 796d331 into mrdoob:dev Sep 8, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants