Yaffle / BigDecimal

a polyfill for decimal propocal
MIT License
51 stars 7 forks source link

Is there any reason why this library build on top of BigInt? #2

Closed nanlei2000 closed 1 year ago

nanlei2000 commented 3 years ago

I saw that you implement two version of the decimal proposal , one is on top of BIgInt, and another use the decimal.js, what is the advantage and disadvantage between this two way?

Yaffle commented 3 years ago

The second is a ready to use decimal library, i am using it to test against my implementation, test.js has some random tests. While this library is a my try to implement floating point arithmetic on top of bigint. Would be nice to know why decimal.js is not using bigint...

nanlei2000 commented 3 years ago

I don't konw how the decimal.js being implemented, i think the way that build on top of BigInt will benifit the native performance, am i correct?

nanlei2000 commented 3 years ago

And i found there is no way transform this library to jsbi, cause that babel plugin can only transform jsbi to native BigInt(not reverse).

Yaffle commented 3 years ago

I don't konw how the decimal.js being implemented, i think the way that build on top of BigInt will benifit the native performance, am i correct?

Yes, perhaps, and this is also some separation of code...

Yaffle commented 3 years ago

And i found there is no way transform this library to jsbi, cause that babel plugin can only transform jsbi to native BigInt(not reverse).

The plugin in readme transforms code to use JSBI

nanlei2000 commented 3 years ago

In fact, i want to implement a

And i found there is no way transform this library to jsbi, cause that babel plugin can only transform jsbi to native BigInt(not reverse).

The plugin in readme transforms code to use JSBI

Sorry, i am wrong, you made a reverse transformer, that's awesome! In fact, i want made a similar library too, to deal with both decimal and bigint, is anything i can help with the code?

Yaffle commented 3 years ago

The babel plugin is a little buggy right now and needs to be fixed (see https://github.com/Yaffle/babel-plugin-transform-bigint/issues/5 ). You could try to implement some fast decimal library or update the code of this library :-) Some benchmark is needed to compare libs. In this library many things are not perfect like binary to decimal conversion or math functions, not sure as well how to efficiently implement rounding. Someone also mentions another library - https://github.com/tc39/proposal-decimal/issues/27#issuecomment-743455396 - with a benchmark results... Btw, I prefer to use BigFloat, as in this case it is possible to use bitwise shifts, which are faster.