bitmath icon indicating copy to clipboard operation
bitmath copied to clipboard

Math with builtin types not as expected

Open avylove opened this issue 4 years ago • 1 comments

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

avylove avatar Aug 07 '20 13:08 avylove

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.

tbielawa avatar Feb 06 '23 00:02 tbielawa