Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
math/big: print and parse in different bases #9141
big.Int certainly permits arbitrary bases: http://golang.org/pkg/math/big/#Int.SetString : for SetString one can provide a base http://golang.org/pkg/math/big/#Int.Format : Format permits at least the common bases (all the code is present internally: if you have a good API suggestion, please let me know). For Rat we have SetFrac where one can set each part of the fraction which can be scanned via SetString. But what's more needed here would be a good API suggestion. What's the notation for a floating-point number or fraction represented in a different base.
Don't know how I missed the base in SetString. Thanks. It's not in Rat though, so I need to do a little dance for that, which is doable but clumsy. Use of Format requires changing the verb for the job and is limited to the standard bases. It works but not generally and somewhat clumsily in the context I have. The API I had in mind was suggested by my original report: strconv's Parse and Format, although obviously the name wouldn't work for Format as it's already taken.