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

SetHex or SetString equivalent #108

Closed
t-anyu opened this issue Jan 31, 2022 · 1 comment
Closed

SetHex or SetString equivalent #108

t-anyu opened this issue Jan 31, 2022 · 1 comment

Comments

@t-anyu
Copy link

t-anyu commented Jan 31, 2022

Hey,

it would be nice to have a math/big.Int SetString equivalent so that we can re-use Int objects without releasing to GC. Maybe just expose (z *Int) fromHex(hex string)?

Thanks

@holiman
Copy link
Owner

holiman commented May 10, 2022

Well, there's always

// UnmarshalText implements encoding.TextUnmarshaler
func (z *Int) UnmarshalText(input []byte) error {
	return z.fromHex(string(input))
}

But perhaps you want the ability to do SetString("500", 10) and choose the base?

I don't really se any problem with changing fromHex into FromHex, tbh. Although, I guess it cannot be exposed in it's current form -- as we have it now, the FromHex guarantees that the z is clear, and thus it doesn't have to set all components (only the ones that are used). If we expose it, we need to ensure to clear any prior bits.

Edit, should be fine

holiman added a commit that referenced this issue Feb 8, 2023
This change adds various string-conversion methods, mainly from decimal. 
It also aligns some setters, into the following: 

Public "convenience" constructors
    FromBig(*big.Int)
    FromHex(string)
    FromBase10(string)
Instance setters:
    (z *Int) SetFromBase10(string) (possibly)
    (z *Int) SetFromBig(*big.Int)
    (z *Int) SetBytes([]byte)
    (z *Int) SetString(string, int)


Co-authored-by: a <[email protected]>
Co-authored-by: Tjudice <[email protected]>
Co-authored-by: Martin Holst Swende <[email protected]>
@holiman holiman closed this as completed Mar 21, 2023
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
@holiman @t-anyu and others