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

Added logarithmic units #229

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

Atmelfan
Copy link
Contributor

@Atmelfan Atmelfan commented Dec 12, 2020

Poor attempt at implementing #201.

No tests, doesn't compile under no_std, missing documentation, fails CI, etc. Breaks every rule regarding macros and generic programming.

@iliekturtles
Copy link
Owner

Thanks for the PR! My plan right now is to finish up the two other open PRs thenpush out a new version. After that I'll dig into this PR in more detail.

@iliekturtles
Copy link
Owner

I finally released v0.31.0 earlier today and will start reviewing this now. Took me a bit longer than expected!

@iliekturtles
Copy link
Owner

Could you possibly rebase this on top of master? The recent change to extract some of the code from quantity.rs into unit.rs is causing conflicts with this PR. I started looking to do this but never ended up finishing with the limited time I've had recently.

@Atmelfan
Copy link
Contributor Author

I'll take a look over the weekend.

@iliekturtles
Copy link
Owner

Finally got a chance to rebase. https://github.com/iliekturtles/uom/compare/Atmelfan-master Will start reviewing for real now!

@iliekturtles
Copy link
Owner

I finally finished my library book, which I'm going to blame any delays on. I have been reading about power and root-power quantities and digging in to this more and wanted to provide an update. The trait changes mostly need minor fixes like documentation and formating. I believe the to/from_linear functions should be merged into to/from/change_base. I'm reviewing rustc/llvm optimizations next to ensure that doing so will keep these functions zero-cost.

@iliekturtles
Copy link
Owner

@Atmelfan, I'm starting to look at integrating these changes again after finally merging #260 and was wondering why the Ratio's decibel is defined as a root-power ratio (10^(1/10)) but Power's decibel-watt derivatives use power ratios (10^(1/20)).

@Atmelfan
Copy link
Contributor Author

It seems right to me, but I might be reading it wrong?

Ratio, base 10, scale 20:

        @part_per_billion: 1.0_E-9; "ppb", "part per billion", "parts per billion";
        @part_per_trillion: 1.0_E-12; "ppt", "part per trillion", "parts per trillion";
        @part_per_quadrillion: 1.0_E-15; "ppq", "part per quadrillion", "parts per quadrillion";
+
+        @decibel: 1.0, 10.0, 20.0; "dB", "decibel", "decibels";
    }
}

Power, base 10, scale 10

+        @decibel_watt: prefix!(none), 10.0, 10.0; "dBW", "decibel-watt", "decibel-watts";
+        @decibel_milliwatt: prefix!(milli), 10.0, 10.0; "dBm", "decibel-milliwatt", "decibel-milliwatts";// dBm is more common than dBmW
+        @decibel_microwatt: prefix!(micro), 10.0, 10.0; "dBµW", "decibel-microwatt", "decibel-microwatts";

@iliekturtles
Copy link
Owner

Logarithmic units require pow/root functions which are not available
in no-std/no-libm builds. Excluding logarthmic units has proven
difficult (in-place filter foiled by macros unable to be used inside an
enum definition). Using a tt-muncher could possibly solve the issue, but
would likely hit the recursion limit very quickly and likely the
quadratic performance characteristics would make uom's slow
compilation even slower.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants