Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/big: print and parse in different bases #9141

Open
robpike opened this issue Nov 20, 2014 · 2 comments
Open

math/big: print and parse in different bases #9141

robpike opened this issue Nov 20, 2014 · 2 comments
Milestone

Comments

@robpike
Copy link
Contributor

robpike commented Nov 20, 2014

Feature request.

The math/big types Int and Rat do not provide facilities analogous to strconv that allow
printing and parsing numbers in arbitrary bases. This would be nice to have.
@griesemer
Copy link
Contributor

Comment 1:

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.

@robpike
Copy link
Contributor Author

robpike commented Nov 20, 2014

Comment 2:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants