Add a feature to enforce libm in std environment#375
Open
ElouanPetereau wants to merge 3 commits intorust-num:masterfrom
Open
Add a feature to enforce libm in std environment#375ElouanPetereau wants to merge 3 commits intorust-num:masterfrom
libm in std environment#375ElouanPetereau wants to merge 3 commits intorust-num:masterfrom
Conversation
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.
This pull request adds a feature named
force-libmto num-traits.Why
Currently, when both
stdandlibmfeatures are enabled,stdalways wins due to thenot(feature = "std")guard on the libm code paths. There is no way to uselibmimplementations in anstdenvironment afaik.This is something I need for reproducible cross-platform float math and, since I saw not open issue regarding this,I chose to propose my solution if you are interested.
How
I added a new cumulative
force-libmCargo feature which implies thatlibmis also enabled. It can be combined withstd(for everything else std provides) while routing float math throughlibm.When enabled, it overrides
stdfor float math operations by changing the conditional compilation gates:#[cfg(feature = "std")]on math impls becomes#[cfg(all(feature = "std", not(feature = "force-libm")))]#[cfg(all(not(feature = "std"), feature = "libm"))]becomes#[cfg(any(feature = "force-libm", all(not(feature = "std"), feature = "libm")))]I also updated
test_full.shto verifies that the feature works. It checks that the linked test binary containslibm::mathsymbols whenforce-libmis enabled and does not when usingstdalone.This is the only reliable solution I found but feel free to propose other solution.
Thank you for your work in maintaining this project 😄