approxEqAbs comparison type changed to f64#19
Merged
Conversation
Member
|
We had a similar problem with this line on Tides recently and simply removed it. Might be worth checking if this works better. What is the reason for it in the first place @michal-z ? |
hazeycode
approved these changes
Jun 24, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves the determinant near-zero check in the matrix inversion function by using double-precision tolerance to avoid falsely detecting non-singular matrices as singular.
- Switched
math.approxEqAbsfromf32tof64when comparing the determinant against epsilon - Updated epsilon argument to
math.floatEps(f64)for higher precision
Comments suppressed due to low confidence (2)
src/root.zig:2620
- [nitpick] Add a comment above this check explaining why
f64precision is needed for the determinant comparison to help future maintainers understand the rationale.
}
src/root.zig:2622
- Add a unit test for
inverseDetusing a near-singular matrix (like the orthographic example) to verify that the newf64comparison correctly avoids returning a zero matrix.
if (math.approxEqAbs(f64, det[0], 0.0, math.floatEps(f64))) {
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.
Ortographics matrix is:
Determinant result is:
0.00000000190641773273548f32 epsilon is
math.floatEps(f32) = 0.0000001192092900f64 epsilon is
math.floatEps(f64) = 0.0000000000000002Inverse matrix result give all column 0 because of this lines:
zmath/src/root.zig
Lines 2622 to 2629 in 634ffd6
Increasing approxEqAbs type to f64 solve the problem.