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

Support for decimal.Decimal and other numerical types as an alternative to float #20

Closed
ezekielnewren opened this issue Sep 29, 2021 · 3 comments
Assignees

Comments

@ezekielnewren
Copy link

I'd like there be an option like parser = BaseArithmeticParser(numerical_types=[int, Decimal, complex]) where if numerical_types=None it would default to the value numerical_types=[int, float, complex] so that when I'm dealing with monetary values I can be confident that the answer IS EXACT, not really super close.

@ptmcg
Copy link
Member

ptmcg commented Sep 29, 2021

Interesting idea, I'll look into it.

@ptmcg ptmcg self-assigned this Sep 29, 2021
@ptmcg
Copy link
Member

ptmcg commented Aug 1, 2024

Well it took me a while to get around to this, but I did put some time into it, and I think I have a working version now. Rather than have you poke around with the internal numerical_types variable, I've added an optional use_decimal Boolean argument to the BaseArithmeticParser class initializer - when set to True, the internal math and resulting values will be Decimal objects, not floats. Works for common math operations, but complex results and trig functions are not supported in this mode.

@ptmcg
Copy link
Member

ptmcg commented Aug 2, 2024

Included in 0.8.0 release

@ptmcg ptmcg closed this as completed Aug 2, 2024
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

2 participants