Skip to content

Make some kind of sum work, it doesn't now #103

Description

@timlnx

DESCRIPTION of the request - Make something like sum() but it must actually work for bitmath objects


Passing an array of bitmath objects into the built-in sum() function has unpredictable results.

In [78]: to_count = [Byte(1), MiB(1), GiB(1)]

In [79]: sum(to_count)
Out[79]: 3.0

In [80]: bitmath.best_prefix(sum(to_count))
Out[80]: Byte(3.0)

Which is incorrect:


In [76]: counted
Out[76]: Byte(1074790401.0)

In [77]: counted.best_prefix()
Out[77]: GiB(1.0009765634313226)

What you EXPECTED to happen:
Expected sum to let bitmath objects use their built in rich comparison and numeric data model emulation methods.

What ACTUALLY happened:
sum() seems to be using the instance.value attribute

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

  • all versions from all sources

To Do

Add something to bitmath, like bitmath.sum to emulate the standard library function which is misbehaving.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions