hyunsik / bytesize

An utility that easily makes bytes size representation and helps its arithmetic operations.
Apache License 2.0
107 stars 31 forks source link

Dimensionality ignored #2

Closed mulkieran closed 6 years ago

mulkieran commented 7 years ago

1 KiB * 8 B = 8 KiB^2, not 8 KiB, and so forth. People seldom think in Bytes squared, unlike say meters squared, but the rules work the same.

This makes a bunch of the arithmetic operations numerically correct, but dimensionally incorrect.

ckauhaus commented 7 years ago

I think that ByteSize should support scalar arithmetics only with dimensionless integers. This means that the following operations should be supported:

Makes sense?

mulkieran commented 7 years ago

Those should certainly all be supported.

I devoted a lot of thought to this in my justbytes library (in Python). There are a few others that make sense, as well. The source code of that library includes justifications for all operations, with units.

ErichDonGubler commented 5 years ago

Is there a reason that the Sub implementation is not supported yet, as was discussed a few comments ago here? I'm trying to experiment with upgrading systemstat's dependency on this lib to 1.0, and they explicitly depended on that.

Obviously, one can work around this by coercing to u64 and back in the meantime, but that's annoying, especially considering that there was no explicit acknowledgement by @hyunsik about what set of operations would actually be supported.