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

Add bignum feature #29

Open
ghost opened this issue Aug 13, 2019 · 6 comments
Open

Add bignum feature #29

ghost opened this issue Aug 13, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Aug 13, 2019

I've experimented with enabling Bignum extension (seems to be working just fine, can be enabled just by changing static lib name in Rust flags from quickjs to quickjs.bn). However I'm not sure what would be the correct types to map.

My idea is to have num-bigint feature that would use num-bigint crate to store values from JavaScript BigInt, which is currently stage3 and implemented by major browsers. At the same time I think maybeQuickJS's BigFloat can be ignored for now, as it is something non-standard, and also I haven't found a crate that would be a good fit to store BigFloat values in Rust.

@theduke theduke added the enhancement New feature or request label Aug 13, 2019
@theduke
Copy link
Owner

theduke commented Aug 13, 2019

I'm all for it.
For decimal, this might be a good fit: https://github.com/paupino/rust-decimal
It's used by diesel for postgres I think.

Are you interested in implementing this?

@ghost
Copy link
Author

ghost commented Aug 13, 2019

For decimal, this might be a good fit: https://github.com/paupino/rust-decimal

It is big decimal (fixed-point), which might not be practical to store QuickJS BigFloat (floating point), as numbers like 1e2000 would take enormous space when stored as fixed point.

@ghost
Copy link
Author

ghost commented Aug 13, 2019

Are you interested in implementing this?

Yes, want to try to add BigInt.

@theduke
Copy link
Owner

theduke commented Aug 13, 2019

Happy to help if you run into any questions.

@theduke
Copy link
Owner

theduke commented Aug 13, 2019

Ah yeah,

The binary representation consists of a 96 bit integer number, a scaling factor used to specify the decimal fraction and a 1 bit sign

I thought decimal was arbitrary precision.

@theduke theduke assigned ghost Aug 13, 2019
@ghost
Copy link
Author

ghost commented Aug 13, 2019

@theduke It turns out that only functions for converting BigInt to i64 and back are exposed publicly in QuickJS:

The structure JSBigFloat that is needed for extracting QuickJS big float type bf_t from JSValue is defined in quickjs.c and thus private.

@ghost ghost mentioned this issue Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant