Skip to content

Integers not correctly handled in num::rational #16386

@tbu-

Description

@tbu-
  • Possible-machine integers are treated as mathematical integers: Ratio::reduce, where the unary minus operator on a negative number is assumed to yield a positive number.
  • self.denom is compared to Zero::zero instead of calling is_zero().
  • Ratio::recip might return a fractions with a denominator of 0.

There are also some issues regarding overflows, it seems the module just hopes that they won't happen at all – except for wrong results, this could also raise a fail!()ure, when e.g. 1/sqrt(max_int) is multiplied with itself, yielding 1/0.

This might mean that Rust needs some general guideline on how to treat integer overflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions