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

Format arbitrary unit nicely #268

Closed
jl-wynen opened this issue Jan 6, 2023 · 4 comments · Fixed by #272
Closed

Format arbitrary unit nicely #268

jl-wynen opened this issue Jan 6, 2023 · 4 comments · Fixed by #272

Comments

@jl-wynen
Copy link
Contributor

jl-wynen commented Jan 6, 2023

Currently, the following

auto u = units::unit_from_string("arbitraryunit");
std::cout << to_string(u) << '\n';

prints CXCUN[1]. It would be nice if it printed arbitraryunit or something along those lines.

@phlptp
Copy link
Collaborator

phlptp commented Jan 6, 2023

There are a lot of units that can be converted from a string but aren't displayed in an equivalent fashion.

addUserDefinedUnit("arbitraryunit", units::unit_from_string("arbitraryunit"));

should work, or whatever string you do, though that particular piece of code would only work once.

I am also thinking to add an addUserDefinedOutputUnit for cases like this as well in the near future.

@jl-wynen
Copy link
Contributor Author

jl-wynen commented Jan 9, 2023

Ok. Maybe I'm biased because arbitrary unit is relatively important for us.
We have our own mechanism for handling user defined units as mentioned in #271. I opened this issue because we would prefer to avoid adding special handling to always enforce a certain formatting of CXCUN[1]. But I see your point

@phlptp
Copy link
Collaborator

phlptp commented Jan 9, 2023

Fair enough, easy enough to add output units like this in the tables for units that don't interfere with existing ones. Feel free to make a PR adding it, or just let me know what string you want and I will add it next I am tinkering with that part of the code. It would go in defined_unit_names_si then you just have to adjust the array size.

@SimonHeybrock
Copy link
Contributor

Looking at https://en.wikipedia.org/wiki/Arbitrary_unit#Abbreviations_and_nomenclature, I would suggest to use "arb. unit", as it is the least ambiguous?

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 a pull request may close this issue.

3 participants