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

RFE when using best prefix keep as bits? #82

Open
ajwillo opened this issue Aug 30, 2018 · 2 comments
Open

RFE when using best prefix keep as bits? #82

ajwillo opened this issue Aug 30, 2018 · 2 comments
Assignees

Comments

@ajwillo
Copy link

ajwillo commented Aug 30, 2018

Using the latest version of bitmath, im trying to convert a bit value into the best bit prefix. as seen below the output is always converted to bytes, I would like to keep the value in bits so best for this would be mebibits not mebibytes

>>> b = 130130.75
>>> m = Kib(b)
>>> m
Kib(130130.75)
>>> m.best_prefix()
MiB(15.885101318359375)

edited by tbielawa to use correct prefix units in the written form, replaced 'mega' with 'mebi' at end of description

@tbielawa tbielawa changed the title when using best prefix keep as bits? RFE when using best prefix keep as bits? Sep 29, 2018
@tbielawa
Copy link
Owner

@ajwillo Thanks for posting your question. You gave me something interesting to think about.

I have to admit, when I first saw this issue roll in I wasn't quite sure what to make of it, that's not your fault, that's mine. I thought to myself, "well, best_prefix is technically working as advertised".

But then I thought about this issue again today and I realized that you've identified a very legitimate use-case that absolutely has value. I completely missed this in the initial design of best_prefix. Thank you for filing this RFE.

To maintain current expected functionality I can't change the default behavior of best_prefix, but what I think I can do instead is add an optional keyword argument to the method and function such that the user can specify that they would like to preserve the original base unit. That way you could ensure you get back a bit or byte based unit back, depending on the input.

@tbielawa tbielawa self-assigned this Sep 29, 2018
@tbielawa
Copy link
Owner

tbielawa commented Sep 29, 2018

Proof of concept, must implement following behavior:

>>> a = bitmath.Kib(130130.75)
>>> print(a)
130130.75 Kib
>>> b = a.best_prefix(preserve_base=True)
>>> print(b)
1127.080810547 Mib

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

2 participants