goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.49k stars 171 forks source link

Support arbitrarily big numbers (`Big...`) #451

Closed 64kramsystem closed 6 years ago

64kramsystem commented 7 years ago

Goby currently does support strictly integer representations (up to 64 bit), but not arbitrarily big numbers (typically called BigNum/BigInt...).

@st0012 if you don't have any very specific ideas about the implementation, I can implement Big numbers with a transparent Goby Integer interface - like Ruby 2.4 does, where an Integer is always exposed to the user, and transparently changed behind the scenes when required.

hachi8833 commented 7 years ago

I agree with it. Well I just wonder if we need Numeric class that is inherited to Integer and Float after that. Numeric can be almost empty.

64kramsystem commented 7 years ago

I think in the long term, the Goby Numeric class will be very likely added/needed, but I don't think that right now it would have any functionality - unless somebody introduces it with a specific purpose.

(for reference, Goby does have a Numeric interface, but in Go, and it's hidden from the user; it's currently used to abstract floating point conversions)

64kramsystem commented 7 years ago

With that in mind, of course, I don't think that adding it straight away would hurt, but it would need to be carefully designed to make sure it would change as little as possible in the future (if it would be chosen not to wait for it to be needed and to have clearer requirements).

st0012 commented 7 years ago

@saveriomiroddi @hachi8833 I think this is worth working, but it's priority should be low until we've reached certain version (like v0.4.0). Because we or test users will use this feature only if other fundamental features are provided.

hachi8833 commented 6 years ago

Just a memorandum.

I remember Decimal class can potentially treat arbitrary big num:

» a = "9999999999999999999999999999999999999999999999000000000000000000000000".to_d
#» 9999999999999999999999999999999999999999999999000000000000000000000000
» a.fraction
#» 9999999999999999999999999999999999999999999999000000000000000000000000/1

I wonder how to convert Integer and Decimal smoothly. Currently Decimal's toString() is truncated on 60th digits.

ear7h commented 6 years ago

Closing this issue because Big numbers are supported by the Decimal class, thank you @hachi8833 . I'll open up a separate issue for those concerns...