Skip to content

proposal: math/big: add functions for floor and ceil of a rational number #76821

@arminguenther

Description

@arminguenther

Proposal Details

Some computations require floor and ceiling of a rational number.
I propose adding Floor and Ceil methods to big.Rat, which return
the floor and ceiling as a *big.Int respectively.

Pull request #76820

An example use case is computing the Engel expansion:

func toEngel(u *big.Rat) (seq []*big.Int) {
        for {
                a := new(big.Rat).Inv(u).Ceil()
                seq = append(seq, a)
                u.Mul(u, new(big.Rat).SetInt(a))
                u.Sub(u, big.NewRat(1, 1))
                if u.Num().Cmp(big.NewInt(0)) == 0 {
                        break
                }
        }
        return seq
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions