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

Problem with large number precision #446

Closed
ahungry opened this issue Jul 1, 2020 · 1 comment
Closed

Problem with large number precision #446

ahungry opened this issue Jul 1, 2020 · 1 comment

Comments

@ahungry
Copy link
Contributor

ahungry commented Jul 1, 2020

First off, I noticed on the Janet samples for Rosetta Code factorial, any of them with a factorial of 1e3 would give a return value of "inf" (not correct).

As I began to play with large numbers (I assume these are all floats and not actually ints at all) I observe some logical incorrectness:

 (let [bignum 1000000000000000000000000000000000] (= bignum (+ 1 bignum)))                                                        

   true

a large number that isn't actually "inf" can't be equal to itself + 1
@bakpakin ^ any idea?

   (let [bignum 1000000000000000000000000000000000] (= bignum (+ 1e17 bignum)))                                                     

   false
   (let [bignum 1000000000000000000000000000000000] (= bignum (+ 1e16 bignum)))                                                     

   true

it would appear after some precision point anything afterwards is disregarded, resulting in false comparison results.

I think bignum should be handled in a separate module or package, or baked in for non-float based numbers (no decimal points), or else numbers exceeding the precision that can be properly handled should trigger errors.

What do you think?

@bakpakin
Copy link
Member

bakpakin commented Jul 1, 2020

Janet numbers are IEEE754 double precision floating point numbers, and as such follow al of the semantics these numbers obey. Which includes limited precision. This will not change.

Edit: This includes on parsing - there is no plan to parse large numbers or extremely precise numbers into a different number type.

@bakpakin bakpakin closed this as completed Jul 1, 2020
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

2 participants