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

String formatting with eV? #121

Closed
SimonHeybrock opened this issue Feb 8, 2021 · 3 comments
Closed

String formatting with eV? #121

SimonHeybrock opened this issue Feb 8, 2021 · 3 comments

Comments

@SimonHeybrock
Copy link
Contributor

SimonHeybrock commented Feb 8, 2021

#112 fixed some string formatting for units containing meV (milli electron volt). In our field (time-of-flight neutron scattering) we also encounter some odd combinations with this, the main example comes to mind is counts/meV. Currently this gets formatted badly:

// parsing ok
unit_from_string("counts/meV")
// to_string not ok
6.2415090744607627e+21counts/J

Is there a generic way to fix this, that doesn't require adding more exceptions?

@phlptp
Copy link
Collaborator

phlptp commented Feb 8, 2021

I will take a look, I am looking at some issues like this

@SimonHeybrock
Copy link
Contributor Author

Fixed by #130 (thanks!), but I have a related question: In fields where eV is used for energy, there is a set of related units than contain additional odd factors, in particular c (speed of light). See for example table on top right here: https://en.wikipedia.org/wiki/Electronvolt.

The most relevant ones are eV/c**2 for mass and eV/c for momentum.

Would you consider adding support for this? If so, I could give it a try myself (maybe you have some pointers on what is the best way?).

@phlptp
Copy link
Collaborator

phlptp commented Feb 10, 2021

My guess is adding c, c^2 and eV and possibly h and hbar to the test_units structure on line 319 of units.cpp might deal with a number of cases like that pretty easily.

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

No branches or pull requests

2 participants