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

Bitwise operations on BigDecimal #20

Open
littledan opened this issue Nov 13, 2019 · 3 comments
Open

Bitwise operations on BigDecimal #20

littledan opened this issue Nov 13, 2019 · 3 comments

Comments

@littledan
Copy link
Member

I can't figure out what sense bitwise operations like |, & and ^ would make on BigDecimal. My intuition is that we should just throw TypeErrors if they are used. Any concerns with this plan?

@MaxGraey
Copy link

What about use 1.5m | 0n or 1.5m >> 0n for converting to BigInt? Not sure is it good idea but some JavaScript users could expect this behaviour. 1.5m | 0 and 1.5m >>> 0 should of course restrict.

@littledan
Copy link
Member Author

I'm wondering, what would the downside be of requiring that people explicitly cast to BigInt in those cases?

@Rudxain
Copy link
Contributor

Rudxain commented Apr 10, 2022

@littledan We would expect code that looks like this: BigInt(BigDecimal.trunc(x)) & 0xffn (where x is a BigDecimal), which looks very verbose even if
this proposal got to Stage 3, which would instead look like BigInt(Math.trunc(x)) & 0xffn, which is shorter, but still has the same number of tokens. This was just an example, the expression can be simplified to BigDecimal.trunc(x % 256m), but the issue gets worse with operators such as XOR ^ which would require loops to emulate mathematically look like this BigInt(BigDecimal.trunc(x)) ^ y) , although I don't know of any use case for XORing a BigDecimal as if it were an int

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

3 participants