Fix incorrect docs for Bernoulli::from_ratio and add a doc-test#1807
Merged
dhardy merged 1 commit intoJul 10, 2026
Merged
Conversation
dhardy
requested changes
Jul 10, 2026
dhardy
left a comment
Member
There was a problem hiding this comment.
- The error condition was described as "For
numerator > denominatoranddenominator == 0", but the implementation isif numerator > denominator || denominator == 0— two independent conditions joined by OR, not AND.
This is a case of ambiguous language ("for the cases where ..."), not technically an error.
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.
What
Corrects the doc comment on
Bernoulli::from_ratioand adds a runnable example.The previous docs had three inaccuracies:
new_ratio(2, 3), but the method is namedfrom_ratio;new_rationo longer exists, so following the example gives a compile error.true. Ifnumerator == 0it will always returnfalse."numerator > denominatoranddenominator == 0", but the implementation isif numerator > denominator || denominator == 0— two independent conditions joined by OR, not AND.from_ratioalso lacked a runnable example, unlike its siblings (new, etc.).Why
The rendered documentation was misleading: it named a nonexistent method, contained a garbled sentence, and mis-stated when an error is returned. A reader following the old example would hit a compile error, and the AND wording contradicts the actual OR behavior.
Testing
cargo test --doc from_ratio— the new doc-test compiles and passes. It checksd.p()is within1e-9of2/3, thatfrom_ratio(3, 3).p() == 1.0andfrom_ratio(0, 3).p() == 0.0, and thatfrom_ratio(4, 3)andfrom_ratio(1, 0)both returnErr.cargo fmt --check— clean.cargo clippy --lib— clean.Doc-only change; the function body is untouched.