Skip to content

Take reference for Real::min/Real::max#10

Merged
timschmidt merged 1 commit into
timschmidt:mainfrom
TimTheBig:ref-min-max
May 27, 2026
Merged

Take reference for Real::min/Real::max#10
timschmidt merged 1 commit into
timschmidt:mainfrom
TimTheBig:ref-min-max

Conversation

@TimTheBig
Copy link
Copy Markdown

This may save a clone in many cases

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the min and max methods of the Real struct in src/real/arithmetic.rs to accept and return references with a lifetime parameter instead of taking ownership of the values. There are no review comments, so I have no feedback to provide.

@timschmidt
Copy link
Copy Markdown
Owner

  1. High: Rational parsing now accepts zero denominators and leaves fractions unreduced.
    In hyperreal/src/rational/arithmetic.rs:1611, the fraction parser constructs Self directly instead of checking denominator.is_zero() and
    calling from_fraction_parts(...).reduce(). Confirmed failure: "1/0".parse::() returns Ok(Rational { denominator: 0 }), and "9/18"
    no longer canonicalizes to 1/2.
  2. High: Derived Deserialize bypasses Rational invariants.
    hyperreal/src/rational/arithmetic.rs:52 replaces the custom deserializer with Deserialize, so JSON can create invalid or noncanonical
    rationals, including denominator zero. Confirmed with {"sign":1,"numerator":[1],"denominator":[]} deserializing successfully instead of
    erroring.
  3. High: CBOR rational pairs with denominator zero now panic instead of returning Problem::DivideByZero.
    In hyperreal/src/serde.rs:73, the code divides Rational::from_bigint(numerator) / Rational::from_bigint(denominator). When denominator is
    zero, this reaches an internal assertion in rational division. The previous implementation used from_bigint_fraction, which returned a
    proper error.
  4. Medium: Simple::from_str accepts trailing input.
    hyperreal/src/simple.rs:682 now returns after parsing the first expression without checking remaining characters. Confirmed: (+ 1 2) junk is
    accepted and evaluates to 3.

timschmidt added a commit that referenced this pull request May 27, 2026
@timschmidt timschmidt merged commit 55429b3 into timschmidt:main May 27, 2026
1 check passed
@timschmidt
Copy link
Copy Markdown
Owner

I fixed up the issues, at least well enough that tests pass, and there was a performance improvement, so I pulled it in.

@TimTheBig
Copy link
Copy Markdown
Author

thanks

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.

2 participants