Skip to content

Exploit mpq functions for Rational{BigInt}? #9826

@stevengj

Description

@stevengj

As discussed on julia-dev, there is some performance advantage to using the GMP mpq functions for Rational{BigInt} operations.

The easiest way to do this would be:

  • Make BigInt an immutable type. (It currently has immutable semantics anyway.) This way, Rational{BigInt} would be binary compatible with GMP's mpq_t (a pointer to an __mpq_struct consisting of the numerator __mpz_struct followed by the denominator), since our BigInt type is already a mirror of __mpz_struct.
  • Define specialized + etc. methods for Rational{BigInt} that call GMP mpq functions.

I get the impression that the main reason that BigInt is a type and not immutable is that this makes it easier to pass by reference to GMP functions. So changing this to immutable would benefit greatly from a better way to pass ccall "out" arguments by reference, as discussed in #2322.

Alternatively, if you want to leave BigInt as-is, then one needs an easy way to convert BigInt to/from an immutable version thereof, and this requires us to add an additional "internal" constructor function BigInt(alloc::Cint, size::Cint, d::Ptr{Limb}).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bignumsBigInt and BigFloatperformanceMust go fasterrationalsThe Rational type and values thereof

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions