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

Big Decimal Support #73

Open
danieagle opened this issue May 19, 2021 · 6 comments
Open

Big Decimal Support #73

danieagle opened this issue May 19, 2021 · 6 comments

Comments

@danieagle
Copy link

Hi! Thanks for this excelent serializer!

Please add suport for big.Int and decimal.Big !

My main need is the following golang types
(biginteger,native) math/big.Int and (bigdecimal) github.com/ericlagergren/decimal.Big

for others langs I don't care, but I would suggest:
java => (biginteger, native) https://docs.oracle.com/javase/10/docs/api/java/math/BigInteger.html
(bigdecimal, native) https://docs.oracle.com/javase/10/docs/api/java/math/BigDecimal.html
JavaScrip => (biginteger, native) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
(or, biginteger) https://github.com/MikeMcl/decimal.js
(bigdecimal) https://github.com/MikeMcl/decimal.js
C => (biginteger) https://github.com/libtom/libtommath
(bigdecimal) https://github.com/libtom/libtomfloat

Thanks Very Very Very Much!

Best Whishes,
Dani.

@pascaldekloe pascaldekloe changed the title (Wishlist) add suport for big.Int and decimal.Big. Big Decimal Support May 25, 2021
@pascaldekloe
Copy link
Owner

Big decimals allocate memory on instantiation, which goes against the spirit of a fast serialization system. The worst part is that almost none of the implementations allow you to specify the backing array.

Big decimals have their use of course. I am simply not sure what to do here.

@danieagle
Copy link
Author

Hi! and thanks!

Big decimals colfer encoding is just a length and a []byte in golang.

To get the binary from decimal.Big to []byte there is a high performance:
Big.MarshalText
and the reverse op []byte to decimal.Big there is a high performance:
Big.UnmarshalText

I'll try mirror the code used in "colf_binary" type for bigdecimal.

in this time I'll create a branch 'bigdecimal" in the my forks area.

ps.1: I Liked very very very much the code you made, it is a pleasant surprise to see a practical use of go / {ast, parser, etc.}
ps.2: what types of bigdecimal do you prefer for C, Java, Javascript?

[]'s Gratitude,
Dani.

@pascaldekloe
Copy link
Owner

Thanks Dany. It is nice to hear you like you like the code. 😊

MarshalText allocates a new byte array. That's a big no-go in terms of performance.

The generated code does not have any dependencies as a rule. That means we must either use whatever is in the core library, or expose the value in some sort of raw format.

@danieagle
Copy link
Author

Hi!
Thanks!
I completed the go lang support. https://github.com/danieagle/colfer bigdecimal branch :-)

Mostly arbitrary precision libs already use a text or a array of bytes as mantissa, because this, mostly change or conversion (type to []byte and []byte to type) is high performance.

i finished golang, so what next language do you want?
Thanks,
Dani.

@pascaldekloe
Copy link
Owner

A good start would be to add a big decimal entry in ./testdata/test.colf O and run the unit tests to see if your code compiles. Next we need a unit test (in ./go/gen_test.go).

@pascaldekloe
Copy link
Owner

You are still allocating a new buffer with MarshalText. At least use Append with hex then for somewhat reasonable performance. Better would be to store the decimal point as a varint, and the integer representation as a big-endian byte array + sign bit.

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

2 participants