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

Value was either too large or too small for a UInt16. #41

Open
Dunge opened this issue Mar 18, 2022 · 6 comments
Open

Value was either too large or too small for a UInt16. #41

Dunge opened this issue Mar 18, 2022 · 6 comments

Comments

@Dunge
Copy link

Dunge commented Mar 18, 2022

I'm trying to do binary operators ^ | on integer values representing flags to only keep the desired values. My values are actually 64bits (ulong), but NCalc seems to do all its internal numeric computation on 16bits. Any way around that?

@PsykomantaBrain
Copy link

Adding my +1 to this. Needed it to perform operations on 32-bit layermask values... not sure why the decision to limit the bitwise operands to 16 bits

@yallie
Copy link
Member

yallie commented Jul 14, 2023

Hello, sorry for my late reply.

Not sure why binary operators use 16-bit numbers, most likely due to historical reasons.
I believe that part of the code hasn't modified since the last ncalc version from Codeplex times.

If you adapt the code to support 64-bit integers (or 128-bit decimals), please submit a PR.
It will be much appreciated!

Thanks.

@gmcchessney
Copy link

gmcchessney commented Apr 23, 2024

@yallie I'm interested in adding support for this. I plan on supporting up to 64 bit integers since dotnet doesn't support binary operators on decimal type. If there is a use case for decimal binary operators let me know.

Would it be best to add an option to EvaluationOptions to enable/disable bitwise on larger size integers so that backwards compatibility can be maintained, or should I change the code to always work with integers of any size?

@yallie
Copy link
Member

yallie commented Apr 23, 2024

@gmcchessney, great, please go ahead :)

Would it be best to add an option to EvaluationOptions

I'd say it's better to implement support for integers of any size.

@marcblank
Copy link

Excited to see this!

@marcblank
Copy link

The perfect being the enemy of the good, why not do the extremely simple change of UInt16 to UInt32 for the bitwise operations? 2 minute change to the code, and solves a longstanding problem. Handling larger integers isn't something anyone has requested, after all. And if there are any backward compatibility issues, I can't see them (I guess if you were counting on an Exception, that could be a problem). An option for Allow32BitIntegersInBitwiseOperations doesn't strike me as necessary, but if that's the way to get this implemented, I'm all for it! :)

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

6 participants