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

BigInt support #249

Open
01mf02 opened this issue Dec 20, 2024 · 0 comments
Open

BigInt support #249

01mf02 opened this issue Dec 20, 2024 · 0 comments
Labels
good first issue Good for newcomers

Comments

@01mf02
Copy link
Owner

01mf02 commented Dec 20, 2024

In #243, @tranzystorekk made the following comment:

I'm wondering if switching the int repr in jaq-json to i64 would be a viable option (I saw the comment that isize allows ints to easily index arrays, but it seems the trade-off isn't as good if int is also comprehensively tested against arithmetic operations)

I have thought for some time about this suggestion. I think that rather than changing Int(isize) to Int(i64) in jaq_json::Val, it would be a nicer solution to support BigInt as an additional type of values BigInt(BigInt) (next to Int(isize)). That way, we could handle integers of any size on any architecture, switching automatically from isize to BigInt when the result of an operation exceeds isize.

I was worried that rounding from f64 might be an issue, but I think that this works nicely: When we have a f: f64, we can convert it to an integer representation via format!("{:.0}", f), and from there, we can simply parse() it to a BigInt. We just have to be careful when f is NaN or infinity, in which case we should probably return f unchanged. (This is currently not handled correctly by jaq.)

This work would mostly involve modifying jaq-json (and slightly jaq-std), I believe, and does not touch jaq-core. Therefore, it would be a good first issue for someone who is motivated to implement this.

@01mf02 01mf02 added the good first issue Good for newcomers label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant