Skip to content

fix: make enhanced-determinism cover the math calls that go to the platform's libm under std - #468

Open
iancarscadden wants to merge 1 commit into
dimforge:masterfrom
iancarscadden:enhanced-determinism-libm-under-std
Open

iancarscadden wants to merge 1 commit into
dimforge:masterfrom
iancarscadden:enhanced-determinism-libm-under-std

Conversation

@iancarscadden

@iancarscadden iancarscadden commented Nov 13, 2026 •

Copy link
Copy Markdown

Part of dimforge/rapier#1054 (companion to dimforge/rapier#1074).

Problem

With the std feature on, a method call such as x.log2() on a Real resolves to the inherent float method, which calls the platform's math library even when enhanced-determinism (simba/libm_force) is enabled. Platform libms round these functions differently, so results can differ across platforms.

Fix

Call the four remaining sites through ComplexField, as the rest of the crate already does (<Real as ComplexField>::cos(...) in cuboid.rs, segment.rs, aabb.rs, ...). Without enhanced-determinism they still resolve to the standard library.

Site Function Runs when
partitioning/bvh/bvh_optimize.rs, optimization_config log2 ×2 every incremental BVH optimization (2D, 3D)
math/vector_ext.rs, VectorExt::angle acos trimesh pseudo-normals, transformation helpers (2D, 3D)
shape/convex_polyhedron.rs, support_feature_id_toward_eps sin_cos convex polyhedron support features (3D)
transformation/mesh_intersection/mesh_intersection.rs, smallest_angle acos mesh intersection (3D, spade)

Test

math::vector_ext::tests::angle_is_bit_exact_with_enhanced_determinism pins VectorExt::angle to a bit pattern. On master it fails on macOS arm64 (0x3fa066ab from Apple's acosf, 0x3fa066aa from libm). CI gains one step that runs it, since no job ran tests with enhanced-determinism before:

cargo test -p parry3d --features enhanced-determinism --lib enhanced_determinism

Checked locally: the test passes on macOS arm64 and Linux arm64 with the fix. cargo fmt -- --check (my files; query_dispatcher.rs already differs on master), cargo clippy, cargo test --features wavefront, cargo check --features enhanced-determinism, cargo check --features bytemuck-serialize,serde-serialize,rkyv.

Not covered: spade has platform math calls of its own in its mesh-refinement code.

With the `std` feature on, `x.log2()`, `x.acos()` and `x.sin_cos()` on a `Real`
resolve to the inherent float methods, which call the platform's math library
even when `enhanced-determinism` (`simba/libm_force`) is enabled. The results
then differ across platforms. Call them through `ComplexField`, like the rest
of the crate does:

- `Bvh::optimization_config` (`log2`), every incremental BVH optimization
- `VectorExt::angle` (`acos`)
- `ConvexPolyhedron::support_feature_id_toward_eps` (`sin_cos`)
- `smallest_angle` in the mesh intersection (`acos`)
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.

1 participant