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

Arbitrary precision integers (bignum) #1376

Open
sanjayjain159 opened this issue Jan 28, 2024 · 3 comments
Open

Arbitrary precision integers (bignum) #1376

sanjayjain159 opened this issue Jan 28, 2024 · 3 comments

Comments

@sanjayjain159
Copy link

Is there a convenient way to introduce arbitrary precision integers (bignum) in Janet? Perhaps through long strings?

@sogaiu
Copy link
Contributor

sogaiu commented Jan 28, 2024

For some use-cases, may be this is suitable?

An interest was expressed in a wrapper for GMP here, not sure if there was work on that.

I think at one point there was some comment about it NOT being likely for there to eventually be something built into Janet but I'm fuzzy on that (^^;

@amano-kenji
Copy link
Contributor

Scheme has full-numeric tower which includes big integer and big rational numbers.

@tttuuu888
Copy link

Related to this topic, I think one of Janet's current bignum-related problems is that it appears to support bignum but behaves strangely.

Below are some examples. (tested on Janet 1.33.0-f91e5994 linux/x64/gcc)

repl:24:> 11111111111111111
1.11111111111111e+16
repl:25:> 11111111111111110
1.11111111111111e+16
repl:27:> (- 11111111111111111 11111111111111110)
2
repl:28:> 1111111111111111111111111111111111
1.11111111111111e+33
repl:29:> 1111111111111111111111111111111110
1.11111111111111e+33
repl:31:> (= 1111111111111111111111111111111111 1111111111111111111111111111111110)
true
repl:34:> (- 1111111111111111111111111111111111 1111111111111111111111111111111110)
0

Wouldn't it be better to generate an error rather than allowing abnormal behavior like above?

In the long term, I hope that Janet will support bignum natively.
Janet-big mentioned above looks great. But unfortunately I found same abnormal behavior like below.

repl:5:> (=  (big/int 11111111111111111111)  (big/int 11111111111111111112))
true
repl:6:> (=  (big/int "11111111111111111111")  (big/int "11111111111111111112"))
false
repl:7:> (-  (big/int 11111111111111111111)  (big/int 11111111111111111110))
<big/int 0>
repl:8:> (-  (big/int "11111111111111111111")  (big/int "11111111111111111110"))
<big/int 1>

As above, Janet-big works normally only when bignum is provided as a string.
I'm not sure if this is due to a limitation of current Janet or Janet-big is missing something.
But if bignum is added to Janet, It would be nice if bignum could be freely used as a number rather than a string.

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

4 participants