Repository navigation
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
Conversation
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`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of dimforge/rapier#1054 (companion to dimforge/rapier#1074).
Problem
With the
stdfeature on, a method call such asx.log2()on aRealresolves to the inherent float method, which calls the platform's math library even whenenhanced-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(...)incuboid.rs,segment.rs,aabb.rs, ...). Withoutenhanced-determinismthey still resolve to the standard library.partitioning/bvh/bvh_optimize.rs,optimization_configlog2×2math/vector_ext.rs,VectorExt::angleacostransformationhelpers (2D, 3D)shape/convex_polyhedron.rs,support_feature_id_toward_epssin_costransformation/mesh_intersection/mesh_intersection.rs,smallest_angleacosspade)Test
math::vector_ext::tests::angle_is_bit_exact_with_enhanced_determinismpinsVectorExt::angleto a bit pattern. Onmasterit fails on macOS arm64 (0x3fa066abfrom Apple'sacosf,0x3fa066aafrom libm). CI gains one step that runs it, since no job ran tests withenhanced-determinismbefore:Checked locally: the test passes on macOS arm64 and Linux arm64 with the fix.
cargo fmt -- --check(my files;query_dispatcher.rsalready differs onmaster),cargo clippy,cargo test --features wavefront,cargo check --features enhanced-determinism,cargo check --features bytemuck-serialize,serde-serialize,rkyv.Not covered:
spadehas platform math calls of its own in its mesh-refinement code.