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

JsBigInt support? #376

Open
coolaj86 opened this issue Dec 14, 2018 · 4 comments
Open

JsBigInt support? #376

coolaj86 opened this issue Dec 14, 2018 · 4 comments

Comments

@coolaj86
Copy link

Total newbie to neon, just kicking the tires.

I'm just curious if there's a way to return a JS BigInt. I just guessed at JsResult<JsBigInt>, but that was wrong.

I believe there are three distinct BigInt types:

  • Signed BigInts (BigInt)
  • Signed BigInt64 (BigInt64Array.from([-123n]))
  • Unsigned BigInt64 (BigInt64Array.from([123n]))

The later two are i64 and u64 and the first is true arbitrary precision.

@amilajack
Copy link
Member

There isn't a way to do this just yet. For the time being you can return a string like we are doing in the fibonacci example. There is a way to do this in neon. You can construct those objects in neon. I can't provide any examples just yet because I haven't done this myself yet. I will look into this soon

@coolaj86
Copy link
Author

Thanks. I figured I could just return a string and then handle it in JS if needed.

I was just curious because I've been doing stuff with BigInts lately, but having it in neon isn't a need I have yet, though I imagine if I get into neon seriously I'll end up use them one way or another.

@amilajack
Copy link
Member

amilajack commented Dec 14, 2018

What you can do is access the object from the global property with cx.global and then get the BigInt property.

https://neon-bindings.com/api/neon/context/trait.context#method.global

@kjvalencik
Copy link
Member

This could also be done with a buffer. I agree that this would be a great addition to neon.

https://nodejs.org/api/buffer.html#buffer_buf_writebigint64be_value_offset

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

No branches or pull requests

3 participants