-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add support for bytes? #31
Comments
Do you mean bytes as a underlying storage type ( For the later it can be done right now using #[macro_use]
mod information {
quantity! {
quantity: Information; "information";
dimension: Q<P1>;
units {
@byte: 1; "B", "byte", "bytes";
@kilobyte: 1024; "kB", "kilobyte", "kilobytes";
...
}
}
}
system! {
quantities: Q {
information: byte, B;
}
units: U {
Information,
}
}
// Requires #29.
mod u64 {
mod s { pub use ::*; }
Q!(u64::s, u64);
}
// Works today.
mod f64 {
mod s { pub use ::*; }
Q!(f64::s, f64);
} If you looking to plug in arbitrary external types as the underlying storage type the library implicitly requires the type to implement all the necessary operations ( |
Would be nice to see this |
I added a couple very rough implementations of I'm leaning towards the second implementation and welcome feedback. |
Yes of course the second one is better! |
Just wanna bump this as it's pretty useful functionality to have. |
Like others I would really like to see this, what's blocking this from being included? |
Mostly the time to implement is blocking this from being completed (PRs welcome!). Resolving this issue also isn't as simple as just merging the information branch linked above. Since |
Could |
If |
I can see the crate supports Or |
|
The SI brochure specifically and repeatedly states that “counts” (which I would classify “number of bits” as in the context users are asking for) are of unit one. Obviously, we don’t want other dimensionless quantities to coerce as information quantities. To my mind, this is exactly the use case for kinds. If we think a little abstractly for a moment, the difference between the “regular” kind and the angle kind is that they work in two different spaces: the basis of an angular quantity is fundamentally different from a linear quantity. By the same token, “amount of encoded information” or “rate of change in encoded information” are fundamentally different bases than “count” or “oscillation rate.” I understand and appreciate the wariness of just slapping another kind down and what I assume is a concern about precedent), but I think this is a useful functionality to expose and also don’t know that it makes sense to develop a new, orthogonal system for separating quantities of the same dimension when we already have such a system. I also think that “information” extends a lot more beyond “people want to describe a computer’s address space”: there are some fundamental discussions about information and information density in math and physics, and I think we also ought to expose units used in areas like these if the requested functionality is added. With all that said (sorry for the wall of text!), I would be happy to send an implementation PR, as I know you’ve said you’re short on time and I’ve got some to spare. (I’m also planning to send a PR finishing the |
Considering information a "count" definitely simplifies implementation. My original intuition was that there should be a dimension, but after doing a bit more reading today a dimensionless quantity seems to be the correct way to go. A PR would be very welcome. See the information branch for some of the work I did. |
@iliekturtles I have been working on implementing this, I just have a question, is there any way in a quantity definition for one unit to refer to the conversion of another unit either for less duplication or for unit aliases? For unit aliases it would be cool if the following were possible:
And for conversions:
|
Great to hear you're working on a PR! Using another unit isn't supported currently. It should be possible to implement and I'll add an issue to investigate. |
@Lukazoid, thanks for taking up this issue and submitting a PR! Exciting to see it finally closed. |
Would support for 'bytes' be within scope for this library? Would that work out well with using f32 / f64 storage? It seems like perhaps using
u64
for bytes, but floating point for all larger units might be useful?The text was updated successfully, but these errors were encountered: