MikeMcl / decimal.js

An arbitrary-precision Decimal type for JavaScript
http://mikemcl.github.io/decimal.js
MIT License
6.45k stars 475 forks source link

Bigint support #181

Open protango opened 3 years ago

protango commented 3 years ago

With bigint now a part of JavaScript, it would be nice for Decimal.JS to support it within its constructor and operations.

As a workaround we can just convert bigint's to strings before using them in Decimal.JS, however this becomes very repetitive with lots of numbers.

mahnunchik commented 2 years ago

Any news?

MikeMcl commented 2 years ago

@mahnunchik

No news. I'll try and have a look at this soon.

sterlu commented 1 year ago

Would you accept a PR which treats BigInt as a string in the constructor? Should be pretty simple to do around here:

if (t === 'bigint') {
  v = v.toString();
  t = 'string';
}
MikeMcl commented 1 year ago

@sterlu

Yes, but if the argument is a BigInt then there would be no need for the minus and plus sign checks, or for the isDecimal.test(v), so it would just be a matter of setting x.s to 1 or -1 depending on whether the argument is positive or negative, and then returning parseDecimal(x, v.toString()). Ça va?

SynthLuvr commented 2 months ago

This would be good to add to make our codebase a little bit more concise. I think @sterlu is on the right track, there wouldn't be too much effort required to add bigint support.