Skip to content

Fix incorrect docs for Bernoulli::from_ratio and add a doc-test#1807

Merged
dhardy merged 1 commit into
rust-random:masterfrom
teddytennant:docs/fix-bernoulli-from-ratio
Jul 10, 2026
Merged

Fix incorrect docs for Bernoulli::from_ratio and add a doc-test#1807
dhardy merged 1 commit into
rust-random:masterfrom
teddytennant:docs/fix-bernoulli-from-ratio

Conversation

@teddytennant

Copy link
Copy Markdown
Contributor

What

Corrects the doc comment on Bernoulli::from_ratio and adds a runnable example.

The previous docs had three inaccuracies:

  • The example referenced new_ratio(2, 3), but the method is named from_ratio; new_ratio no longer exists, so following the example gives a compile error.
  • A prior edit left an orphaned, subjectless fragment: "return true. If numerator == 0 it will always return false."
  • The error condition was described as "For numerator > denominator and denominator == 0", but the implementation is if numerator > denominator || denominator == 0 — two independent conditions joined by OR, not AND.

from_ratio also 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 checks d.p() is within 1e-9 of 2/3, that from_ratio(3, 3).p() == 1.0 and from_ratio(0, 3).p() == 0.0, and that from_ratio(4, 3) and from_ratio(1, 0) both return Err.
  • cargo fmt --check — clean.
  • cargo clippy --lib — clean.

Doc-only change; the function body is untouched.

Copilot AI review requested due to automatic review settings July 8, 2026 15:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dhardy dhardy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The error condition was described as "For numerator > denominator and denominator == 0", but the implementation is if 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.

@dhardy dhardy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Sorry, mis-click.)

@dhardy dhardy merged commit 8272d49 into rust-random:master Jul 10, 2026
18 checks passed
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.

3 participants