Skip to content

math/big: Rat.Denom has side effects #33792

@ericlagergren

Description

@ericlagergren

From here: ericlagergren/decimal#138

My package divides (*Rat).Num by (*Rat).Denom to produce a decimal number. It turns out that (*Rat).Denom lazily sets its denominator, meaning it cannot be used concurrently.

Since the receiver is x not z, I assumed that the method simply read the denominator.

The receiver name should be updated to indicate side effects and/or the documentation for big.Rat should mention this side effect. I assume that the 7 years this has spent in the tree is too long to be reverted 😄. And, at any rate, not materializing the denominator can save allocations for whole numbers, which is a good thing.

I can send a CL if you want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions