Skip to content

mutating APIs for BigInts and BigFloats? #31342

@StefanKarpinski

Description

@StefanKarpinski

We have Base.GMP.MPZ.add! and other very internal mutating arithmetic operations for BigInts which are used internally within the BigInt implementation to implement faster versions of some operations. #31310 introduces Base.MPFR.nextfloat! and Base.MPFR.prevfloat! as some of the first internal mutating functions for BigFloats. This PR also raises the question of what the API for copying a bignum should be—this is fundamentally part of the same API design question since without mutation there's never any point in copying a bignum.

Should we have a more coherent mutating API for both BigInts and BigFloats? The general guidance for using such a mutating API should probably be that you should only using the mutating operations on bignums when you "own" the bignum in the sense that you're sure that only your code can observe the mutation.

Is this a good idea? Should we avoid this and instead focus on better compiler tech to allow writing non-mutating bignum code and having the compiler reuse bignum objects as necessary? One of the concerns about introducing a mutating API is that needing to support it could potentially prevent such optimizations or make them harder. Perhaps the mutating API could be an experimental API that we might remove in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bignumsBigInt and BigFloatmathsMathematical functionsspeculativeWhether the change will be implemented is speculative

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions