Skip to content

Feature: more comparison operations with BigInts #430

Description

@Seltyk

Right now, the only comparison operation between BigInt types is PartialOrd<Rhs = Self>. There are times, however, that other comparisons are helpful, especially comparisons against primitive integer types. Most of these comparisons could be Ord in the case of BigInt, BigUint, and BigRational, though comparisons involving complex numbers could not be Ord. Even comparisons across differently-signed bigint types are trivial, simply adding an O(1) sign check before the vector-based comparing.

Admittedly, the primitive type comparison can be done already (e.g. x >= BigUint::from(8u64) or x < 16u64.into()), but this is inefficient in terms of time and memory.

Naturally, the reverse (primitive cmp bigint) would also be helpful, though thankfully implementing that will be trivial when the above implementation is made; it's the same source code with some text swapped around. I don't know much about macros, but this sounds like a job for macros.

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