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

Math with builtin types not as expected #94

Open
avylove opened this issue Aug 7, 2020 · 1 comment
Open

Math with builtin types not as expected #94

avylove opened this issue Aug 7, 2020 · 1 comment

Comments

@avylove
Copy link

avylove commented Aug 7, 2020

While I can see reasons for it, it's counterintuitive that adding 1 to a Byte would make it a float rather than a Byte one increment higher. This limits the use cases the library can be utilized. My expectation is if the other value for math operations is not a bitmath type, it should be converted to the bitmath type it is being combined with before the math operation is performed.

How to REPRODUCE the issue:

>>> bitmath.Byte(1) + 1
2.0

How REPRODUCIBLE (every time? intermittently? only in certain environments?):
Always

What you EXPECTED to happen:

>>> bitmath.Byte(1) + 1
Byte(2.0)

VERSION of bitmath effected (git hashes are OK). Did you install from RPM, PyPi, source?

  • Version:1.3.1.x
  • Install Source: python3-bitmath-1.3.1-1.fc32.14.noarch

Your OPERATING SYSTEM and the affected PYTHON VERSION:
Fedora 32
Python 3.8.5

@tbielawa
Copy link
Owner

tbielawa commented Feb 6, 2023

Hi, I've reviewed the docs and what you described is the defined behavior, num + BmType -> num

https://bitmath.readthedocs.io/en/latest/appendices.html#mixed-types-addition-and-subtraction

The result coming back as a float type is curious and I'll have to look at that closer.

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